@supersdk/supercli 0.3.2 → 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 (107) hide show
  1. package/dist/build/artifactIntegrity.js +275 -0
  2. package/dist/build/artifactIntegrity.js.map +1 -0
  3. package/dist/build/projectBuild.js +335 -0
  4. package/dist/build/projectBuild.js.map +1 -0
  5. package/dist/cli.js +20 -11
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/add.js +111 -57
  8. package/dist/commands/add.js.map +1 -1
  9. package/dist/commands/analytics.js +15 -9
  10. package/dist/commands/analytics.js.map +1 -1
  11. package/dist/commands/build.js +533 -0
  12. package/dist/commands/build.js.map +1 -0
  13. package/dist/commands/db.js +24 -19
  14. package/dist/commands/db.js.map +1 -1
  15. package/dist/commands/deploy.js +434 -751
  16. package/dist/commands/deploy.js.map +1 -1
  17. package/dist/commands/env.js +8 -8
  18. package/dist/commands/env.js.map +1 -1
  19. package/dist/commands/image.js +31 -20
  20. package/dist/commands/image.js.map +1 -1
  21. package/dist/commands/init.js +81 -57
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/logs.js +16 -7
  24. package/dist/commands/logs.js.map +1 -1
  25. package/dist/commands/publishSite.js +28 -943
  26. package/dist/commands/publishSite.js.map +1 -1
  27. package/dist/commands/register.js +84 -218
  28. package/dist/commands/register.js.map +1 -1
  29. package/dist/commands/settings.js +10 -6
  30. package/dist/commands/settings.js.map +1 -1
  31. package/dist/config/appConfig.js +48 -171
  32. package/dist/config/appConfig.js.map +1 -1
  33. package/dist/config/superConfig.js +457 -0
  34. package/dist/config/superConfig.js.map +1 -0
  35. package/dist/deploy/adapterTypes.js +3 -0
  36. package/dist/deploy/adapterTypes.js.map +1 -0
  37. package/dist/deploy/manifest.js +403 -0
  38. package/dist/deploy/manifest.js.map +1 -0
  39. package/dist/deploy/preflight.js +201 -0
  40. package/dist/deploy/preflight.js.map +1 -0
  41. package/dist/deploy/resultWriter.js +178 -0
  42. package/dist/deploy/resultWriter.js.map +1 -0
  43. package/dist/deploy/runAdapter.js +302 -0
  44. package/dist/deploy/runAdapter.js.map +1 -0
  45. package/dist/deploy/siteAdapter.js +182 -0
  46. package/dist/deploy/siteAdapter.js.map +1 -0
  47. package/dist/docker/dockerCli.js +110 -53
  48. package/dist/docker/dockerCli.js.map +1 -1
  49. package/dist/output/envelope.js +5 -1
  50. package/dist/output/envelope.js.map +1 -1
  51. package/dist/output/resultPrinter.js +3 -0
  52. package/dist/output/resultPrinter.js.map +1 -1
  53. package/dist/publish/responseClassifier.js +4 -4
  54. package/dist/publish/responseClassifier.js.map +1 -1
  55. package/dist/publish/runClient.js +11 -11
  56. package/dist/publish/runClient.js.map +1 -1
  57. package/dist/publish/siteZip.js +4 -5
  58. package/dist/publish/siteZip.js.map +1 -1
  59. package/dist/template/README.md +26 -257
  60. package/dist/template/android/app/src/main/java/com/supersdk/simple/EnvironmentStore.java +1 -1
  61. package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +2 -2
  62. package/dist/template/android/gradle/supersdk-config-reader.gradle +13 -61
  63. package/dist/template/android/scripts/build.sh +11 -0
  64. package/dist/template/android/supersdk-default.config.json +3 -2
  65. package/dist/template/ios/Sources/App/AppDelegate.swift +1 -1
  66. package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +1 -1
  67. package/dist/template/ios/project.yml +1 -1
  68. package/dist/template/ios/scripts/build.sh +19 -0
  69. package/dist/template/ios/scripts/render_project.py +60 -0
  70. package/dist/template/ios/supersdk-default.config.json +6 -0
  71. package/dist/template/service/Dockerfile +2 -0
  72. package/dist/template/service/scripts/build.sh +11 -0
  73. package/dist/template/super.json +62 -0
  74. package/dist/template/template_manifest.json +6 -9
  75. package/dist/template/web/package.json +8 -0
  76. package/dist/template/web/scripts/build.sh +8 -0
  77. package/dist/template/web/scripts/web_package.py +490 -0
  78. package/dist/template/web/src/js/app.js +2 -2
  79. package/dist/util/shell.js +3 -3
  80. package/dist/workspace/config.js +69 -183
  81. package/dist/workspace/config.js.map +1 -1
  82. package/dist/workspace/identity.js +10 -18
  83. package/dist/workspace/identity.js.map +1 -1
  84. package/dist/workspace/projectContext.js +93 -0
  85. package/dist/workspace/projectContext.js.map +1 -0
  86. package/dist/workspace/projectIdentity.js +50 -98
  87. package/dist/workspace/projectIdentity.js.map +1 -1
  88. package/dist/workspace/template.js +208 -83
  89. package/dist/workspace/template.js.map +1 -1
  90. package/package.json +4 -2
  91. package/dist/publish/siteConfig.js +0 -649
  92. package/dist/publish/siteConfig.js.map +0 -1
  93. package/dist/template/scripts/android_snapshot_canary.py +0 -145
  94. package/dist/template/scripts/build_android.sh +0 -366
  95. package/dist/template/scripts/build_ios.sh +0 -299
  96. package/dist/template/scripts/build_site.sh +0 -43
  97. package/dist/template/scripts/lib/workspace.sh +0 -43
  98. package/dist/template/scripts/serve_web.py +0 -80
  99. package/dist/template/scripts/super_build_orchestrator.py +0 -421
  100. package/dist/template/scripts/supersdk_template.py +0 -1161
  101. package/dist/template/scripts/web_host_validator.py +0 -103
  102. package/dist/template/scripts/web_package.py +0 -295
  103. package/dist/template/scripts/ws03_shared_schema_merge_guard.py +0 -73
  104. package/dist/template/super_build.sh +0 -144
  105. package/dist/template/supersdk.json +0 -35
  106. package/dist/workspace/inspect.js +0 -274
  107. package/dist/workspace/inspect.js.map +0 -1
@@ -1,421 +0,0 @@
1
- #!/usr/bin/env python3
2
- import argparse
3
- import json
4
- import math
5
- import os
6
- import signal
7
- import subprocess
8
- import sys
9
- import threading
10
- from dataclasses import dataclass
11
- from pathlib import Path
12
-
13
- sys.path.insert(0, str(Path(__file__).resolve().parent))
14
- import supersdk_template
15
-
16
-
17
- PROJECT_TYPES = supersdk_template.PROJECT_TYPES
18
- # 🔴 站点没有 skip 模式:它是 success 或 failed。这条常量必须跟着类型改名走 ——
19
- # 留着旧的 "web" 会让每个 site 构建都被 SKIP 扫描,任何以 SKIP_ 开头的日志行都会
20
- # 把它判成 skipped,而退出码仍然是 0(静默的状态漂移,比直接失败危险得多)。
21
- NO_SKIP_MODE_TYPES = ("site",)
22
- SUMMARY_PREFIX = "SUPERSDK_BUILD_SUMMARY_JSON="
23
- SUMMARY_SCHEMA_VERSION = 2
24
- DEFAULT_TIMEOUT_SECONDS = 1800.0
25
- REASON_LIMIT = 500
26
- TRUNCATION_MARKER = "...(truncated)"
27
- OUTPUT_HEAD_LINES = 100
28
- OUTPUT_TAIL_LINES = 100
29
- OUTPUT_LOCK = threading.Lock()
30
- FORWARDED_LINE_SEPARATOR_TRANSLATION = {
31
- ord("\r"): "\\r",
32
- ord("\f"): "\\f",
33
- ord("\v"): "\\v",
34
- 0x1C: "\\x1c",
35
- 0x1D: "\\x1d",
36
- 0x1E: "\\x1e",
37
- 0x85: "\\x85",
38
- 0x2028: "\\u2028",
39
- 0x2029: "\\u2029",
40
- }
41
-
42
-
43
- @dataclass
44
- class HelperOutput:
45
- stdout_lines: list[str]
46
- stderr_lines: list[str]
47
- stdout_skip_line: str | None = None
48
- stderr_skip_line: str | None = None
49
-
50
-
51
- class BoundedLineBuffer:
52
- def __init__(self):
53
- self.head_lines = []
54
- self.tail_lines = []
55
- self.extra_line_count = 0
56
-
57
- def append(self, line):
58
- if len(self.head_lines) < OUTPUT_HEAD_LINES:
59
- self.head_lines.append(line)
60
- return
61
- self.extra_line_count += 1
62
- self.tail_lines.append(line)
63
- if len(self.tail_lines) > OUTPUT_TAIL_LINES:
64
- self.tail_lines.pop(0)
65
-
66
- def lines(self):
67
- if self.extra_line_count == 0:
68
- return list(self.head_lines)
69
- hidden_count = self.extra_line_count - len(self.tail_lines)
70
- if hidden_count <= 0:
71
- return [*self.head_lines, *self.tail_lines]
72
- return [*self.head_lines, f"...({hidden_count} lines omitted)...\n", *self.tail_lines]
73
-
74
-
75
- def selected_projects(config, platform, project):
76
- """把「构建哪些项目」这件事交还给引擎,编排器不自己解析 supersdk.json。"""
77
- normalized = supersdk_template.load_and_validate(config, platform, project)
78
- supersdk_template.require_selection(normalized, platform, project)
79
- return [{"type": item["type"], "dir": item["dir"]} for item in normalized["projects"]]
80
-
81
-
82
- def helper_command(root, project, config):
83
- script = Path(root) / "scripts" / f"build_{project['type']}.sh"
84
- command = [str(script), "--build", "--project", project["dir"]]
85
- # 只有 android 需要根配置:它的 snapshot canary 在 managed config 缺席时会回退去读根配置。
86
- if project["type"] == "android":
87
- command.extend(["--config", str(config)])
88
- return command
89
-
90
-
91
- def helper_timeout_seconds():
92
- raw = os.environ.get("SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS")
93
- if raw is None or raw == "":
94
- return DEFAULT_TIMEOUT_SECONDS
95
- try:
96
- value = float(raw)
97
- except ValueError:
98
- warn_invalid_timeout(raw)
99
- return DEFAULT_TIMEOUT_SECONDS
100
- if value > 0 and math.isfinite(value):
101
- return value
102
- warn_invalid_timeout(raw)
103
- return DEFAULT_TIMEOUT_SECONDS
104
-
105
-
106
- def warn_invalid_timeout(raw):
107
- with OUTPUT_LOCK:
108
- print(
109
- f"[orchestrator] warning: ignoring invalid SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS={raw!r}; using {DEFAULT_TIMEOUT_SECONDS:g}s",
110
- file=sys.stderr,
111
- )
112
-
113
-
114
- def decode_line(raw):
115
- return raw.decode("utf-8", errors="replace")
116
-
117
-
118
- def sanitize_forwarded_line(line):
119
- suffix = "\n" if line.endswith("\n") else ""
120
- body = line[:-1] if suffix else line
121
- return body.translate(FORWARDED_LINE_SEPARATOR_TRANSLATION) + suffix
122
-
123
-
124
- def forward_reader(pipe, platform, stream_name, sink, capture, skip_line_ref, capture_lock):
125
- try:
126
- while True:
127
- raw = pipe.readline()
128
- if raw == b"":
129
- break
130
- decoded = decode_line(raw)
131
- normalized = decoded.rstrip("\r\n")
132
- with capture_lock:
133
- capture.append(decoded)
134
- if skip_line_ref[stream_name] is None and is_skip_line(normalized):
135
- skip_line_ref[stream_name] = normalized
136
- with OUTPUT_LOCK:
137
- forwarded = sanitize_forwarded_line(decoded)
138
- sink.write(f"[{platform} {stream_name}] {forwarded}")
139
- if not forwarded.endswith("\n"):
140
- sink.write("\n")
141
- sink.flush()
142
- except (OSError, ValueError):
143
- pass
144
- finally:
145
- try:
146
- pipe.close()
147
- except Exception:
148
- pass
149
-
150
-
151
- def snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock):
152
- with capture_lock:
153
- return HelperOutput(
154
- stdout_capture.lines(),
155
- stderr_capture.lines(),
156
- skip_line_ref["stdout"],
157
- skip_line_ref["stderr"],
158
- )
159
-
160
-
161
- def run_helper(command, platform, timeout_seconds):
162
- stdout_capture = BoundedLineBuffer()
163
- stderr_capture = BoundedLineBuffer()
164
- skip_line_ref = {"stdout": None, "stderr": None}
165
- capture_lock = threading.Lock()
166
- try:
167
- process = subprocess.Popen(
168
- command,
169
- stdout=subprocess.PIPE,
170
- stderr=subprocess.PIPE,
171
- start_new_session=True,
172
- )
173
- except OSError as exc:
174
- return 127, HelperOutput(stdout_capture.lines(), stderr_capture.lines()), f"launch error: {exc}"
175
-
176
- threads = [
177
- threading.Thread(
178
- target=forward_reader,
179
- args=(process.stdout, platform, "stdout", sys.stdout, stdout_capture, skip_line_ref, capture_lock),
180
- daemon=True,
181
- ),
182
- threading.Thread(
183
- target=forward_reader,
184
- args=(process.stderr, platform, "stderr", sys.stderr, stderr_capture, skip_line_ref, capture_lock),
185
- daemon=True,
186
- ),
187
- ]
188
- for thread in threads:
189
- thread.start()
190
-
191
- timed_out = False
192
- try:
193
- exit_code = process.wait(timeout=timeout_seconds)
194
- except subprocess.TimeoutExpired:
195
- timed_out = True
196
- terminate_process_group(process, platform)
197
- exit_code = 124
198
-
199
- for thread in threads:
200
- thread.join(timeout=5)
201
- pipe_open = any(thread.is_alive() for thread in threads)
202
-
203
- output = snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock)
204
- if timed_out:
205
- return exit_code, output, f"timeout after {timeout_seconds:g}s"
206
- if pipe_open:
207
- with OUTPUT_LOCK:
208
- print(f"[{platform}] warning: helper output pipe remained open after process exit", file=sys.stderr)
209
- return exit_code, output, None
210
-
211
-
212
- def terminate_process_group(process, platform):
213
- try:
214
- os.killpg(process.pid, signal.SIGTERM)
215
- except Exception:
216
- with OUTPUT_LOCK:
217
- print(f"[{platform}] warning: could not terminate process group {process.pid}", file=sys.stderr)
218
- try:
219
- process.terminate()
220
- except Exception:
221
- with OUTPUT_LOCK:
222
- print(f"[{platform}] warning: could not terminate process {process.pid}", file=sys.stderr)
223
- pass
224
- try:
225
- process.wait(timeout=2)
226
- return
227
- except Exception:
228
- pass
229
- try:
230
- os.killpg(process.pid, signal.SIGKILL)
231
- except Exception:
232
- with OUTPUT_LOCK:
233
- print(f"[{platform}] warning: could not kill process group {process.pid}", file=sys.stderr)
234
- try:
235
- process.kill()
236
- except Exception:
237
- with OUTPUT_LOCK:
238
- print(f"[{platform}] warning: could not kill process {process.pid}", file=sys.stderr)
239
- pass
240
- try:
241
- process.wait(timeout=2)
242
- except Exception:
243
- pass
244
-
245
-
246
- def is_skip_line(line):
247
- return line.startswith("SKIP_") or line.startswith("BUILD SKIPPED")
248
-
249
-
250
- def first_skip_line(output):
251
- if output.stdout_skip_line is not None:
252
- return output.stdout_skip_line
253
- if output.stderr_skip_line is not None:
254
- return output.stderr_skip_line
255
- for lines in (output.stdout_lines, output.stderr_lines):
256
- for line in lines:
257
- normalized = line.rstrip("\r\n")
258
- if is_skip_line(normalized):
259
- return normalized
260
- return None
261
-
262
-
263
- def output_excerpt(output):
264
- for lines in (output.stderr_lines, output.stdout_lines):
265
- text = "".join(line for line in lines if not is_omission_marker(line)).strip()
266
- if text:
267
- return " ".join(text.split())
268
- return ""
269
-
270
-
271
- def is_omission_marker(line):
272
- return line.startswith("...(") and line.endswith(" lines omitted)...\n")
273
-
274
-
275
- def cap_reason(reason):
276
- if len(reason) <= REASON_LIMIT:
277
- return reason
278
- return reason[: REASON_LIMIT - len(TRUNCATION_MARKER)] + TRUNCATION_MARKER
279
-
280
-
281
- def classify_result(project, command, exit_code, output, launch_or_timeout_reason=None):
282
- command_payload = [str(item) for item in command]
283
- if launch_or_timeout_reason is not None:
284
- return platform_result(project, "failed", exit_code, cap_reason(launch_or_timeout_reason), command_payload)
285
-
286
- if exit_code != 0:
287
- excerpt = output_excerpt(output)
288
- reason = f"exit_code={exit_code}"
289
- if excerpt:
290
- reason = f"{reason}; {excerpt}"
291
- return platform_result(project, "failed", exit_code, cap_reason(reason), command_payload)
292
-
293
- if project["type"] not in NO_SKIP_MODE_TYPES:
294
- marker = first_skip_line(output)
295
- if marker is not None:
296
- return platform_result(project, "skipped", exit_code, cap_reason(marker), command_payload)
297
-
298
- return platform_result(project, "success", exit_code, "", command_payload)
299
-
300
-
301
- def platform_result(project, status, exit_code, reason, command):
302
- return {
303
- "platform": project["type"],
304
- # 一个工作空间可以有多个同类型项目(比如两个 site)。没有 dir,两条摘要记录
305
- # 长得一模一样,谁失败了根本读不出来。
306
- "dir": project["dir"],
307
- "status": status,
308
- "exit_code": int(exit_code),
309
- "reason": reason,
310
- "command": command,
311
- }
312
-
313
-
314
- def aggregate_summary(results):
315
- statuses = [item["status"] for item in results]
316
- if any(status == "failed" for status in statuses):
317
- overall_status = "failed"
318
- elif statuses and all(status == "skipped" for status in statuses):
319
- overall_status = "skipped"
320
- else:
321
- overall_status = "success"
322
- exit_code = 1 if overall_status == "failed" else 0
323
- return {
324
- "schema_version": SUMMARY_SCHEMA_VERSION,
325
- "overall_status": overall_status,
326
- "overall_exit_code": exit_code,
327
- "platforms": results,
328
- }
329
-
330
-
331
- def emit_summary(summary):
332
- payload = SUMMARY_PREFIX + json.dumps(summary, separators=(",", ":")) + "\n"
333
- with OUTPUT_LOCK:
334
- sys.stdout.write(payload)
335
- sys.stdout.flush()
336
-
337
-
338
- def command_payload(command):
339
- return [str(part) for part in command] if command else ["<command-unavailable>"]
340
-
341
-
342
- def run_all(root, projects, config):
343
- timeout = helper_timeout_seconds()
344
- results = []
345
- for index, item in enumerate(projects):
346
- command = []
347
- try:
348
- command = helper_command(root, item, config)
349
- exit_code, output, launch_or_timeout_reason = run_helper(command, item["type"], timeout)
350
- results.append(classify_result(item, command, exit_code, output, launch_or_timeout_reason))
351
- except Exception as exc:
352
- results.append(
353
- platform_result(
354
- item,
355
- "failed",
356
- 1,
357
- cap_reason(f"internal orchestrator error: {exc}"),
358
- command_payload(command),
359
- )
360
- )
361
- for remaining in projects[index + 1 :]:
362
- remaining_command = []
363
- try:
364
- remaining_command = helper_command(root, remaining, config)
365
- except Exception:
366
- pass
367
- results.append(
368
- platform_result(
369
- remaining,
370
- "failed",
371
- 1,
372
- cap_reason(f"not run after internal orchestrator error in {item['dir']}: {exc}"),
373
- command_payload(remaining_command),
374
- )
375
- )
376
- break
377
- return aggregate_summary(results)
378
-
379
-
380
- def fallback_internal_summary(projects, root, config, exc):
381
- results = []
382
- for index, item in enumerate(projects):
383
- try:
384
- command = helper_command(root, item, config)
385
- except Exception:
386
- command = []
387
- reason = f"internal orchestrator error: {exc}" if index == 0 else f"not run after internal orchestrator error: {exc}"
388
- results.append(platform_result(item, "failed", 1, cap_reason(reason), command_payload(command)))
389
- return aggregate_summary(results)
390
-
391
-
392
- def main(argv=None):
393
- parser = argparse.ArgumentParser(description="Run SuperSDK workspace project builds and emit one root summary")
394
- parser.add_argument("--root", required=True)
395
- parser.add_argument("--platform", choices=["all", *PROJECT_TYPES], default="all")
396
- parser.add_argument("--project", default=None)
397
- parser.add_argument("--config", required=True)
398
- args = parser.parse_args(argv)
399
-
400
- root = Path(args.root).resolve()
401
- config = Path(args.config).resolve()
402
- try:
403
- projects = selected_projects(config, args.platform, args.project)
404
- except supersdk_template.ConfigError as exc:
405
- # 配置错误发生在编排开始**之前**:按契约,这种情况不发摘要。
406
- print(str(exc), file=sys.stderr)
407
- return 1
408
- try:
409
- summary = run_all(root, projects, config)
410
- except Exception as exc:
411
- summary = fallback_internal_summary(projects, root, config, exc)
412
- try:
413
- emit_summary(summary)
414
- except Exception as exc:
415
- print(f"internal orchestrator error while emitting summary: {exc}", file=sys.stderr)
416
- return 1
417
- return summary["overall_exit_code"]
418
-
419
-
420
- if __name__ == "__main__":
421
- raise SystemExit(main())