@supersdk/supercli 0.3.3-staging.45 → 0.3.3-staging.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/build/artifactIntegrity.js +158 -2
  2. package/dist/build/artifactIntegrity.js.map +1 -1
  3. package/dist/build/projectBuild.js +335 -0
  4. package/dist/build/projectBuild.js.map +1 -0
  5. package/dist/cli.js +0 -2
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/add.js +35 -29
  8. package/dist/commands/add.js.map +1 -1
  9. package/dist/commands/build.js +407 -105
  10. package/dist/commands/build.js.map +1 -1
  11. package/dist/commands/init.js +22 -29
  12. package/dist/commands/init.js.map +1 -1
  13. package/dist/commands/register.js +62 -217
  14. package/dist/commands/register.js.map +1 -1
  15. package/dist/config/appConfig.js +36 -163
  16. package/dist/config/appConfig.js.map +1 -1
  17. package/dist/config/superConfig.js +213 -185
  18. package/dist/config/superConfig.js.map +1 -1
  19. package/dist/deploy/manifest.js +189 -167
  20. package/dist/deploy/manifest.js.map +1 -1
  21. package/dist/deploy/preflight.js +15 -16
  22. package/dist/deploy/preflight.js.map +1 -1
  23. package/dist/deploy/runAdapter.js +7 -4
  24. package/dist/deploy/runAdapter.js.map +1 -1
  25. package/dist/docker/dockerCli.js +72 -77
  26. package/dist/docker/dockerCli.js.map +1 -1
  27. package/dist/template/README.md +26 -94
  28. package/dist/template/android/gradle/supersdk-config-reader.gradle +13 -62
  29. package/dist/template/android/scripts/build.sh +11 -0
  30. package/dist/template/ios/project.yml +1 -1
  31. package/dist/template/ios/scripts/build.sh +19 -0
  32. package/dist/template/ios/scripts/render_project.py +60 -0
  33. package/dist/template/ios/supersdk-default.config.json +6 -0
  34. package/dist/template/service/scripts/build.sh +11 -0
  35. package/dist/template/super.json +22 -14
  36. package/dist/template/template_manifest.json +3 -7
  37. package/dist/template/web/package.json +8 -0
  38. package/dist/template/web/scripts/build.sh +8 -0
  39. package/dist/template/web/scripts/web_package.py +490 -0
  40. package/dist/template/web/src/js/app.js +2 -2
  41. package/dist/util/shell.js +3 -3
  42. package/dist/workspace/config.js +3 -79
  43. package/dist/workspace/config.js.map +1 -1
  44. package/dist/workspace/identity.js +6 -15
  45. package/dist/workspace/identity.js.map +1 -1
  46. package/dist/workspace/projectIdentity.js +2 -7
  47. package/dist/workspace/projectIdentity.js.map +1 -1
  48. package/dist/workspace/template.js +205 -77
  49. package/dist/workspace/template.js.map +1 -1
  50. package/package.json +3 -1
  51. package/dist/commands/config.js +0 -170
  52. package/dist/commands/config.js.map +0 -1
  53. package/dist/template/scripts/android_snapshot_canary.py +0 -145
  54. package/dist/template/scripts/build_android.sh +0 -382
  55. package/dist/template/scripts/build_ios.sh +0 -331
  56. package/dist/template/scripts/build_service.sh +0 -89
  57. package/dist/template/scripts/build_site.sh +0 -57
  58. package/dist/template/scripts/lib/workspace.sh +0 -43
  59. package/dist/template/scripts/serve_web.py +0 -78
  60. package/dist/template/scripts/super_build_orchestrator.py +0 -344
  61. package/dist/template/scripts/supersdk_template.py +0 -1394
  62. package/dist/template/scripts/web_host_validator.py +0 -103
  63. package/dist/template/scripts/web_package.py +0 -296
  64. package/dist/template/scripts/ws03_shared_schema_merge_guard.py +0 -73
  65. package/dist/template/super_build.sh +0 -70
  66. package/dist/workspace/inspect.js +0 -275
  67. package/dist/workspace/inspect.js.map +0 -1
@@ -1,331 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5
- # shellcheck source=lib/workspace.sh
6
- . "$SCRIPT_DIR/lib/workspace.sh"
7
- WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
8
- PYTHON_BIN="${PYTHON_BIN:-python3}"
9
- HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
10
- CONFIG="$WORKSPACE_ROOT/super.json"
11
- PROJECT_ID=""
12
- PROJECT_DIR=""
13
- OUTPUT_DIR=""
14
- EVIDENCE_PATH=""
15
-
16
- usage() {
17
- echo "Usage: scripts/build_ios.sh --build --config PATH --project-id ID --output-dir DIR --evidence FILE" >&2
18
- }
19
-
20
- build_seen=false
21
- while [ "$#" -gt 0 ]; do
22
- case "$1" in
23
- --build)
24
- if [ "$build_seen" = true ]; then
25
- usage
26
- exit 2
27
- fi
28
- build_seen=true
29
- shift
30
- ;;
31
- --project-id)
32
- if [ "$#" -lt 2 ]; then
33
- usage
34
- exit 2
35
- fi
36
- PROJECT_ID="$2"
37
- shift 2
38
- ;;
39
- --config)
40
- if [ "$#" -lt 2 ]; then usage; exit 2; fi
41
- CONFIG="$2"; shift 2 ;;
42
- --output-dir)
43
- if [ "$#" -lt 2 ]; then usage; exit 2; fi
44
- OUTPUT_DIR="$2"; shift 2 ;;
45
- --evidence)
46
- if [ "$#" -lt 2 ]; then usage; exit 2; fi
47
- EVIDENCE_PATH="$2"; shift 2 ;;
48
- *)
49
- echo "error: expected --build" >&2
50
- exit 2
51
- ;;
52
- esac
53
- done
54
-
55
- if [ -z "$PROJECT_ID" ]; then PROJECT_ID="ios"; fi
56
- PROJECT_DIR="$("$PYTHON_BIN" "$HELPER" resolve --config "$CONFIG" --platform ios --project "$PROJECT_ID")"
57
- if [ -z "$OUTPUT_DIR" ]; then OUTPUT_DIR="$WORKSPACE_ROOT/$PROJECT_DIR/.supersdk/artifacts"; fi
58
- if [ -z "$EVIDENCE_PATH" ]; then EVIDENCE_PATH="$WORKSPACE_ROOT/$PROJECT_DIR/.supersdk/evidence/ios-build-evidence.json"; fi
59
-
60
- "$PYTHON_BIN" "$HELPER" inject --root "$WORKSPACE_ROOT" --config "$CONFIG" --platform ios --project "$PROJECT_ID"
61
-
62
- IOS_DIR="$WORKSPACE_ROOT/$PROJECT_DIR"
63
- GENERATED_DIR="$IOS_DIR/.supersdk/generated"
64
- GENERATED_SPEC="$GENERATED_DIR/project.generated.yml"
65
-
66
- "$PYTHON_BIN" - "$WORKSPACE_ROOT" "$PROJECT_DIR" <<'PY'
67
- import json
68
- import importlib.util
69
- import re
70
- import sys
71
- from pathlib import Path
72
-
73
-
74
- def fail_invalid(reason):
75
- print(f"ios managed config invalid: {reason}", file=sys.stderr)
76
- sys.exit(1)
77
-
78
-
79
- def quote(value):
80
- return json.dumps(str(value))
81
-
82
-
83
- def swift_string(value):
84
- # spid 被下面的 ASCII 约束限死,所以 json.dumps 就是一个合法的 Swift 字符串字面量。
85
- return json.dumps(str(value))
86
-
87
-
88
- def load_template_contract(workspace_root):
89
- helper_path = workspace_root / "scripts" / "supersdk_template.py"
90
- spec = importlib.util.spec_from_file_location("supersdk_template_contract", helper_path)
91
- if spec is None or spec.loader is None:
92
- fail_invalid("supersdk_template.py contract cannot be loaded")
93
- module = importlib.util.module_from_spec(spec)
94
- spec.loader.exec_module(module)
95
- return module
96
-
97
-
98
- workspace_root = Path(sys.argv[1]).resolve()
99
- project_dir = sys.argv[2]
100
- template_contract = load_template_contract(workspace_root)
101
- ios_dir = workspace_root / project_dir
102
- managed_path = ios_dir / ".supersdk" / "managed" / "config.json"
103
- generated_dir = ios_dir / ".supersdk" / "generated"
104
- generated_spec = generated_dir / "project.generated.yml"
105
- simple_config = generated_dir / "SimpleConfig.swift"
106
-
107
- if not managed_path.is_file():
108
- print(
109
- f"ios managed config missing for directory {project_dir}; run ./super_build.sh --project <projectId> --build",
110
- file=sys.stderr,
111
- )
112
- sys.exit(1)
113
-
114
- try:
115
- managed_text = managed_path.read_text(encoding="utf-8")
116
- except (OSError, UnicodeDecodeError) as exc:
117
- fail_invalid(f"config.json is unreadable: {exc}")
118
-
119
- try:
120
- managed = json.loads(managed_text)
121
- except json.JSONDecodeError:
122
- fail_invalid("config.json is not valid JSON")
123
-
124
- if not isinstance(managed, dict):
125
- fail_invalid("root must be an object")
126
- if set(managed) != set(template_contract.MANAGED_CONFIG_KEYS):
127
- fail_invalid("top-level keys must match managed config schema")
128
- if managed.get("managed_by") != template_contract.MANAGED_BY:
129
- fail_invalid(f"managed_by must be {template_contract.MANAGED_BY}")
130
- if managed.get("schema_version") != template_contract.MANAGED_CONFIG_SCHEMA_VERSION:
131
- fail_invalid(f"schema_version must be {template_contract.MANAGED_CONFIG_SCHEMA_VERSION}")
132
- # 类型名就是 managed config 里的 platform 值;这个字面量必须跟着 PROJECT_TYPES 走。
133
- if managed.get("platform") != "ios":
134
- fail_invalid("platform must be ios")
135
-
136
- platform_config = managed.get("platform_config")
137
- if not isinstance(platform_config, dict):
138
- fail_invalid("platform_config must be an object")
139
- spm_mode = platform_config.get("spmMode", "mock")
140
-
141
- if spm_mode == "real":
142
- print("spmMode=real is not supported until SDK-F040 remote SPM is ready", file=sys.stderr)
143
- sys.exit(1)
144
- if spm_mode != "mock":
145
- fail_invalid("platform_config.spmMode must be mock")
146
-
147
- spid = managed.get("spid")
148
- if not isinstance(spid, str) or not re.fullmatch(template_contract.SPID_PATTERN, spid):
149
- fail_invalid(f"spid must match ^{template_contract.SPID_PATTERN}$")
150
- # 🔴 这里**没有** environment:它是运行时 init 参数,不进构建产物。
151
- # demo 在运行时切换环境(见 Sources/App/EnvironmentStore.swift)。
152
- name = managed.get("name")
153
- if not isinstance(name, str) or not name:
154
- fail_invalid("name must be a non-empty string")
155
- version = managed.get("version")
156
- if not isinstance(version, dict):
157
- fail_invalid("version must be an object")
158
- version_name = version.get("name")
159
- if not isinstance(version_name, str) or not version_name:
160
- fail_invalid("version.name must be a non-empty string")
161
- version_code = version.get("code")
162
- if not template_contract.is_positive_int(version_code):
163
- fail_invalid("version.code must be a positive integer")
164
-
165
- # 没有推导兜底:App 身份来自 projects[].bundleId,否则构建失败。
166
- bundle_id = platform_config.get("bundleId")
167
- if bundle_id is None:
168
- fail_invalid(
169
- f"platform_config.bundleId is required; set bundleId on the ios project in {template_contract.CONFIG_FILENAME}"
170
- )
171
- if not isinstance(bundle_id, str) or not re.fullmatch(template_contract.BUNDLE_ID_PATTERN, bundle_id):
172
- fail_invalid("platform_config.bundleId must be a bundle identifier")
173
- mock_package = (ios_dir / "MockSuperSDKPackage").resolve()
174
- source_spec = ios_dir / "project.yml"
175
-
176
- if not source_spec.is_file():
177
- print("ios project.yml missing", file=sys.stderr)
178
- sys.exit(1)
179
-
180
- generated_dir.mkdir(parents=True, exist_ok=True)
181
- simple_config.write_text(
182
- """import Foundation
183
-
184
- enum SimpleConfig {
185
- static let spid = %s
186
- }
187
- """ % swift_string(spid),
188
- encoding="utf-8",
189
- )
190
-
191
- template = source_spec.read_text(encoding="utf-8")
192
- replacements = {
193
- "__SUPERSDK_MOCK_PACKAGE_PATH__": quote(mock_package),
194
- "__SUPERSDK_APP_SOURCES_PATH__": quote(ios_dir / "Sources" / "App"),
195
- "__SUPERSDK_SIMPLE_CONFIG_PATH__": quote(simple_config),
196
- "__SUPERSDK_RESOURCES_PATH__": quote(ios_dir / "Resources"),
197
- "__SUPERSDK_BUNDLE_ID__": quote(bundle_id),
198
- "__SUPERSDK_VERSION_NAME__": quote(version_name),
199
- "__SUPERSDK_VERSION_CODE__": str(version_code),
200
- "__SUPERSDK_INFOPLIST_PATH__": quote(ios_dir / "Resources" / "Info.plist"),
201
- "__SUPERSDK_DISPLAY_NAME__": quote(name),
202
- "__SUPERSDK_TEST_SOURCES_PATH__": quote(ios_dir / "Tests" / "SimpleAppTests"),
203
- }
204
- template_tokens = set(re.findall(r"__SUPERSDK_[A-Z0-9_]+__", template))
205
- unknown_tokens = sorted(template_tokens - set(replacements))
206
- if unknown_tokens:
207
- print(f"ios project.yml has unresolved placeholder(s): {', '.join(unknown_tokens)}", file=sys.stderr)
208
- sys.exit(1)
209
- rendered = re.sub(r"__SUPERSDK_[A-Z0-9_]+__", lambda match: replacements[match.group(0)], template)
210
-
211
- generated_spec.write_text(rendered, encoding="utf-8")
212
- print(f"rendered {generated_spec}")
213
- PY
214
-
215
- # SDK 内部的 Teamwork 评审闸门。第三方模板用户不应设置 SUPERSDK_CI_GATE;
216
- # 本地正常构建走下面的模拟器自动选择。
217
- if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ] && [ "$(uname -s)" != "Darwin" ]; then
218
- echo "IOS_MACOS_EXECUTOR_MISSING: ws03-ios-xcodegen-generate requires a macOS/Xcode runner" >&2
219
- exit 1
220
- fi
221
-
222
- if ! command -v xcodegen >/dev/null 2>&1; then
223
- if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ]; then
224
- echo "xcodegen missing for non-skippable ws03-ios-xcodegen-generate gate" >&2
225
- exit 1
226
- fi
227
- echo "SKIP_XCODEGEN_MISSING: xcodegen not installed" >&2
228
- exit 0
229
- fi
230
-
231
- xcodegen generate --project "$IOS_DIR" --spec "$GENERATED_SPEC"
232
-
233
- if ! command -v xcodebuild >/dev/null 2>&1; then
234
- if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ]; then
235
- echo "xcodebuild missing for non-skippable ws03-ios-xcodegen-generate gate" >&2
236
- exit 1
237
- fi
238
- echo "SKIP_XCODEBUILD_MISSING: xcodebuild not installed" >&2
239
- exit 0
240
- fi
241
-
242
- if ! command -v xcrun >/dev/null 2>&1 || ! xcrun simctl list devices available >/dev/null 2>&1; then
243
- if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ]; then
244
- echo "SKIP_SIMULATOR_MISSING invalid for ws03-ios-xcodegen-generate gate" >&2
245
- exit 1
246
- fi
247
- echo "SKIP_SIMULATOR_MISSING: no available iOS simulator" >&2
248
- exit 0
249
- fi
250
-
251
- SIMULATOR_DESTINATION="$("$PYTHON_BIN" - <<'PY' || true
252
- import json
253
- import os
254
- import subprocess
255
- import sys
256
-
257
- GATE_NAME = "ws03-ios-xcodegen-generate"
258
- GATE_DESTINATION = "platform=iOS Simulator,name=iPhone 17,OS=26.5"
259
- GATE_DEVICE = "iPhone 17"
260
- GATE_RUNTIME_SUFFIX = "iOS-26-5"
261
-
262
- try:
263
- raw = subprocess.check_output(
264
- ["xcrun", "simctl", "list", "devices", "available", "-j"],
265
- stderr=subprocess.DEVNULL,
266
- text=True,
267
- )
268
- devices_by_runtime = json.loads(raw).get("devices", {})
269
- except Exception:
270
- sys.exit(1)
271
-
272
- gate = os.environ.get("SUPERSDK_CI_GATE") == GATE_NAME
273
- for runtime, devices in devices_by_runtime.items():
274
- runtime_key = runtime.replace(".", "-")
275
- if gate and not runtime_key.endswith(GATE_RUNTIME_SUFFIX):
276
- continue
277
- if not gate and "iOS-" not in runtime_key:
278
- continue
279
- for device in devices:
280
- if not device.get("isAvailable", True):
281
- continue
282
- name = device.get("name")
283
- if gate:
284
- if name == GATE_DEVICE:
285
- print(GATE_DESTINATION)
286
- sys.exit(0)
287
- continue
288
- udid = device.get("udid")
289
- if name and udid:
290
- print(f"platform=iOS Simulator,id={udid}")
291
- sys.exit(0)
292
- sys.exit(1)
293
- PY
294
- )"
295
- if [ -z "$SIMULATOR_DESTINATION" ]; then
296
- if [ "${SUPERSDK_CI_GATE:-}" = "ws03-ios-xcodegen-generate" ]; then
297
- echo "SKIP_SIMULATOR_MISSING invalid for ws03-ios-xcodegen-generate gate: missing iPhone 17 OS 26.5" >&2
298
- exit 1
299
- fi
300
- echo "SKIP_SIMULATOR_MISSING: no available iOS simulator destination" >&2
301
- exit 0
302
- fi
303
- if [ "${SUPERSDK_CI_GATE:-}" != "ws03-ios-xcodegen-generate" ]; then
304
- echo "Using iOS simulator destination: $SIMULATOR_DESTINATION" >&2
305
- fi
306
-
307
- xcodebuild \
308
- -project "$IOS_DIR/SimpleApp.xcodeproj" \
309
- -scheme SimpleApp \
310
- -configuration Debug \
311
- -destination "$SIMULATOR_DESTINATION" \
312
- CODE_SIGNING_ALLOWED=NO \
313
- test
314
-
315
- mkdir -p "$OUTPUT_DIR" "$(dirname "$EVIDENCE_PATH")"
316
- tar -cf "$OUTPUT_DIR/ios-simulator-build.tar" -C "$IOS_DIR" .supersdk/generated
317
- "$PYTHON_BIN" - "$EVIDENCE_PATH" "$PROJECT_ID" "$PROJECT_DIR" "$SIMULATOR_DESTINATION" <<'PY'
318
- import json
319
- import sys
320
- from pathlib import Path
321
-
322
- path, project_id, project_dir, destination = sys.argv[1:]
323
- Path(path).write_text(json.dumps({
324
- "schemaVersion": 1,
325
- "projectId": project_id,
326
- "type": "ios",
327
- "status": "success",
328
- "projectDir": project_dir,
329
- "destination": destination,
330
- }, indent=2, sort_keys=True) + "\n", encoding="utf-8")
331
- PY
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5
- # shellcheck source=lib/workspace.sh
6
- . "$SCRIPT_DIR/lib/workspace.sh"
7
- WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
8
- PYTHON_BIN="${PYTHON_BIN:-python3}"
9
- HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
10
- CONFIG="$WORKSPACE_ROOT/super.json"
11
- PROJECT_ID=""
12
- OUTPUT_DIR=""
13
- EVIDENCE_PATH=""
14
-
15
- usage() { echo "Usage: scripts/build_service.sh --build --config PATH --project-id ID --output-dir DIR --evidence FILE" >&2; }
16
- build_seen=false
17
- while [ "$#" -gt 0 ]; do
18
- case "$1" in
19
- --build) if [ "$build_seen" = true ]; then usage; exit 2; fi; build_seen=true; shift ;;
20
- --config) if [ "$#" -lt 2 ]; then usage; exit 2; fi; CONFIG="$2"; shift 2 ;;
21
- --project-id) if [ "$#" -lt 2 ]; then usage; exit 2; fi; PROJECT_ID="$2"; shift 2 ;;
22
- --output-dir) if [ "$#" -lt 2 ]; then usage; exit 2; fi; OUTPUT_DIR="$2"; shift 2 ;;
23
- --evidence) if [ "$#" -lt 2 ]; then usage; exit 2; fi; EVIDENCE_PATH="$2"; shift 2 ;;
24
- *) usage; exit 2 ;;
25
- esac
26
- done
27
- if [ "$build_seen" = false ] || [ -z "$PROJECT_ID" ] || [ -z "$OUTPUT_DIR" ] || [ -z "$EVIDENCE_PATH" ]; then usage; exit 2; fi
28
- if ! command -v docker >/dev/null 2>&1; then echo "Docker is required for service builds" >&2; exit 1; fi
29
-
30
- project_json="$("$PYTHON_BIN" "$HELPER" validate --config "$CONFIG" --platform service --project "$PROJECT_ID")"
31
- eval "$("$PYTHON_BIN" - "$project_json" <<'PY'
32
- import json
33
- import shlex
34
- import sys
35
-
36
- project = json.loads(sys.argv[1])["projects"][0]
37
- build = project["platformConfig"]
38
- for key, value in {
39
- "PROJECT_DIR": project["dir"],
40
- "BUILD_CONTEXT": build["context"],
41
- "DOCKERFILE": build["dockerfile"],
42
- "PLATFORM": build["platform"],
43
- }.items():
44
- print(f"{key}={shlex.quote(str(value))}")
45
- print("BUILD_ARG_NAMES=" + shlex.quote("\n".join(build["argsFromEnv"])))
46
- PY
47
- )"
48
-
49
- context_path="$WORKSPACE_ROOT/$PROJECT_DIR/$BUILD_CONTEXT"
50
- dockerfile_path="$context_path/$DOCKERFILE"
51
- if [ ! -f "$dockerfile_path" ] || [ -L "$dockerfile_path" ]; then echo "service Dockerfile must be a regular file inside build context" >&2; exit 1; fi
52
- project_real="$(cd "$WORKSPACE_ROOT/$PROJECT_DIR" && pwd -P)"
53
- context_real="$(cd "$context_path" && pwd -P)"
54
- dockerfile_real="$(cd "$(dirname "$dockerfile_path")" && pwd -P)/$(basename "$dockerfile_path")"
55
- case "$context_real/" in "$project_real/"*) ;; *) echo "service build context escapes project directory" >&2; exit 1 ;; esac
56
- case "$dockerfile_real" in "$context_real/"*) ;; *) echo "service Dockerfile escapes build context" >&2; exit 1 ;; esac
57
-
58
- tag="super-local/$PROJECT_ID:build-$(date +%s)-$$"
59
- set --
60
- while IFS= read -r name; do
61
- [ -n "$name" ] || continue
62
- eval "present=\${$name+x}"
63
- if [ "$present" != x ]; then echo "service build input missing: $name" >&2; exit 1; fi
64
- set -- "$@" --build-arg "$name"
65
- done <<EOF
66
- $BUILD_ARG_NAMES
67
- EOF
68
-
69
- docker build --platform "$PLATFORM" --file "$dockerfile_path" --tag "$tag" "$@" "$context_path"
70
- image_id="$(docker image inspect --format '{{.Id}}' "$tag")"
71
- mkdir -p "$OUTPUT_DIR" "$(dirname "$EVIDENCE_PATH")"
72
- archive="$OUTPUT_DIR/image.tar"
73
- docker save --output "$archive" "$tag"
74
- "$PYTHON_BIN" - "$EVIDENCE_PATH" "$PROJECT_ID" "$tag" "$image_id" "$PLATFORM" <<'PY'
75
- import json
76
- import sys
77
- from pathlib import Path
78
-
79
- path, project_id, tag, image_id, platform = sys.argv[1:]
80
- Path(path).write_text(json.dumps({
81
- "schemaVersion": 1,
82
- "projectId": project_id,
83
- "type": "service",
84
- "status": "success",
85
- "localImageTag": tag,
86
- "localImageId": image_id,
87
- "platform": platform,
88
- }, indent=2, sort_keys=True) + "\n", encoding="utf-8")
89
- PY
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5
- # shellcheck source=lib/workspace.sh
6
- . "$SCRIPT_DIR/lib/workspace.sh"
7
- WORKSPACE_ROOT="$(supersdk_require_workspace_root "$SCRIPT_DIR")"
8
- PYTHON_BIN="${PYTHON_BIN:-python3}"
9
- HELPER="$WORKSPACE_ROOT/scripts/supersdk_template.py"
10
- CONFIG="$WORKSPACE_ROOT/super.json"
11
- PROJECT_ID=""
12
- OUTPUT_DIR=""
13
- EVIDENCE_PATH=""
14
-
15
- usage() { echo "Usage: scripts/build_site.sh --build --config PATH --project-id ID --output-dir DIR --evidence FILE" >&2; }
16
- build_seen=false
17
- while [ "$#" -gt 0 ]; do
18
- case "$1" in
19
- --build) if [ "$build_seen" = true ]; then usage; exit 2; fi; build_seen=true; shift ;;
20
- --config) if [ "$#" -lt 2 ]; then usage; exit 2; fi; CONFIG="$2"; shift 2 ;;
21
- --project-id) if [ "$#" -lt 2 ]; then usage; exit 2; fi; PROJECT_ID="$2"; shift 2 ;;
22
- --output-dir) if [ "$#" -lt 2 ]; then usage; exit 2; fi; OUTPUT_DIR="$2"; shift 2 ;;
23
- --evidence) if [ "$#" -lt 2 ]; then usage; exit 2; fi; EVIDENCE_PATH="$2"; shift 2 ;;
24
- *) usage; exit 2 ;;
25
- esac
26
- done
27
- if [ "$build_seen" = false ]; then usage; exit 2; fi
28
- if [ -z "$PROJECT_ID" ]; then PROJECT_ID="web"; fi
29
-
30
- PROJECT_DIR="$("$PYTHON_BIN" "$HELPER" resolve --config "$CONFIG" --platform site --project "$PROJECT_ID")"
31
- if [ -z "$OUTPUT_DIR" ]; then OUTPUT_DIR="$WORKSPACE_ROOT/$PROJECT_DIR/.supersdk/artifacts"; fi
32
- if [ -z "$EVIDENCE_PATH" ]; then EVIDENCE_PATH="$WORKSPACE_ROOT/$PROJECT_DIR/.supersdk/evidence/site-build-evidence.json"; fi
33
- "$PYTHON_BIN" "$HELPER" inject --root "$WORKSPACE_ROOT" --config "$CONFIG" --platform site --project "$PROJECT_ID"
34
- package_json="$("$PYTHON_BIN" "$WORKSPACE_ROOT/scripts/web_package.py" package-managed --root "$WORKSPACE_ROOT" --project "$PROJECT_DIR")"
35
- printf '%s\n' "$package_json"
36
- mkdir -p "$OUTPUT_DIR" "$(dirname "$EVIDENCE_PATH")"
37
- "$PYTHON_BIN" - "$package_json" "$OUTPUT_DIR" "$EVIDENCE_PATH" "$PROJECT_ID" "$PROJECT_DIR" <<'PY'
38
- import json
39
- import shutil
40
- import sys
41
- from pathlib import Path
42
-
43
- result = json.loads(sys.argv[1])
44
- output, evidence, project_id, project_dir = Path(sys.argv[2]), Path(sys.argv[3]), sys.argv[4], sys.argv[5]
45
- shutil.copytree(Path(result["dist"]), output / "dist")
46
- zip_path = result.get("zip")
47
- if zip_path:
48
- shutil.copy2(zip_path, output / Path(zip_path).name)
49
- evidence.write_text(json.dumps({
50
- "schemaVersion": 1,
51
- "projectId": project_id,
52
- "type": "site",
53
- "status": "success",
54
- "projectDir": project_dir,
55
- "offline": {"host": result.get("host"), "skipped": bool(result.get("offline_skipped"))},
56
- }, indent=2, sort_keys=True) + "\n", encoding="utf-8")
57
- PY
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bash
2
- # 工作空间定位的单一实现,被 super_build.sh 与所有 build_<type>.sh 复用。
3
- #
4
- # 🔴 为什么不能再用 `APP_ROOT="$(dirname "$0")/.."`:项目目录由用户在 super.json 的
5
- # `projects[].dir` 里指定,深度不定(`android`、`apps/android`、`clients/mobile/android`…)。
6
- # 任何「固定层级」的反推都会在第一个非默认布局上算错根目录,而且是**静默**算错 ——
7
- # 注入会写到一个不存在的地方,构建照样退出 0。
8
- #
9
- # 定位语义与 CLI 侧一致:向上查找 `super.json`,它所在的目录就是工作空间根。
10
- # `scripts/` 与 `super_build.sh` 是工作空间级共享物,所以脚本自身位置永远在根之下。
11
-
12
- supersdk_find_workspace_root() {
13
- dir="$1"
14
- while :; do
15
- if [ -f "$dir/super.json" ]; then
16
- printf '%s\n' "$dir"
17
- return 0
18
- fi
19
- parent="$(dirname "$dir")"
20
- if [ "$parent" = "$dir" ]; then
21
- return 1
22
- fi
23
- dir="$parent"
24
- done
25
- }
26
-
27
- # 允许调用方(编排器/CI)显式钉住根目录;否则从给定起点向上查找。
28
- supersdk_workspace_root() {
29
- if [ -n "${SUPERSDK_WORKSPACE_ROOT:-}" ]; then
30
- printf '%s\n' "$SUPERSDK_WORKSPACE_ROOT"
31
- return 0
32
- fi
33
- supersdk_find_workspace_root "$1"
34
- }
35
-
36
- supersdk_require_workspace_root() {
37
- root="$(supersdk_workspace_root "$1" || true)"
38
- if [ -z "$root" ]; then
39
- echo "error: no super.json found at or above $1; run this script from inside a SuperSDK workspace" >&2
40
- exit 1
41
- fi
42
- printf '%s\n' "$root"
43
- }
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env python3
2
- import argparse
3
- import functools
4
- import http.server
5
- import sys
6
- from pathlib import Path
7
-
8
- sys.path.insert(0, str(Path(__file__).resolve().parent))
9
- import supersdk_template
10
-
11
-
12
- def resolve_site_dir(root, project):
13
- """站点目录来自配置,不是写死的 `web/`。"""
14
- return supersdk_template.resolve_single(Path(root) / supersdk_template.CONFIG_FILENAME, "site", project)
15
-
16
-
17
- def main(argv=None):
18
- parser = argparse.ArgumentParser(description="Serve a SuperSDK site project for local HTTP debugging")
19
- parser.add_argument("--root", default=Path(__file__).resolve().parents[1], type=Path)
20
- parser.add_argument("--project", default=None, help="Stable site projectId; the directory is resolved from super.json.")
21
- parser.add_argument(
22
- "--host",
23
- default="127.0.0.1",
24
- help="Bind host. The default is loopback-only; non-loopback binds expose the workspace root.",
25
- )
26
- parser.add_argument("--port", default=8000, type=int)
27
- parser.add_argument(
28
- "--allow-remote",
29
- action="store_true",
30
- help="Allow non-loopback binds for dev-only remote debugging.",
31
- )
32
- args = parser.parse_args(argv)
33
-
34
- root = args.root.resolve()
35
- try:
36
- site_dir = resolve_site_dir(root, args.project)
37
- except supersdk_template.ConfigError as exc:
38
- print(str(exc), file=sys.stderr)
39
- return 1
40
-
41
- # Prefer the built package root: only <project>/dist carries the generated
42
- # supersdk-config.json that the browser fallback path reads.
43
- entry = None
44
- for relative in (f"{site_dir}/dist/index.html", f"{site_dir}/src/index.html"):
45
- if (root / relative).is_file():
46
- entry = relative
47
- break
48
- if entry is None:
49
- print(f"{site_dir}/dist/index.html or {site_dir}/src/index.html not found under {root}", file=sys.stderr)
50
- return 1
51
- if entry.endswith("/src/index.html"):
52
- print(
53
- f"warning: serving unbuilt {site_dir}/src; run scripts/build_site.sh --build for the browser config fallback",
54
- file=sys.stderr,
55
- )
56
-
57
- remote_bind = args.host not in {"127.0.0.1", "localhost", "::1"}
58
- if remote_bind and not args.allow_remote:
59
- print("refusing non-loopback bind; pass --allow-remote to expose the full workspace root", file=sys.stderr)
60
- return 1
61
- if remote_bind:
62
- print("warning: serving the full workspace root on a non-loopback host", file=sys.stderr)
63
-
64
- handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(root))
65
- server = http.server.ThreadingHTTPServer((args.host, args.port), handler)
66
- host, port = server.server_address
67
- print(f"http://{host}:{port}/{entry}", flush=True)
68
- try:
69
- server.serve_forever()
70
- except KeyboardInterrupt:
71
- pass
72
- finally:
73
- server.server_close()
74
- return 0
75
-
76
-
77
- if __name__ == "__main__":
78
- raise SystemExit(main())