@supersdk/supercli 0.1.0-dev.1

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 (100) hide show
  1. package/dist/api/consoleClient.js +132 -0
  2. package/dist/api/consoleClient.js.map +1 -0
  3. package/dist/auth/browserAuth.js +163 -0
  4. package/dist/auth/browserAuth.js.map +1 -0
  5. package/dist/auth/refresh.js +32 -0
  6. package/dist/auth/refresh.js.map +1 -0
  7. package/dist/cli.js +46 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/commands/accounts.js +46 -0
  10. package/dist/commands/accounts.js.map +1 -0
  11. package/dist/commands/createApp.js +225 -0
  12. package/dist/commands/createApp.js.map +1 -0
  13. package/dist/commands/login.js +54 -0
  14. package/dist/commands/login.js.map +1 -0
  15. package/dist/commands/logout.js +99 -0
  16. package/dist/commands/logout.js.map +1 -0
  17. package/dist/commands/publishSite.js +361 -0
  18. package/dist/commands/publishSite.js.map +1 -0
  19. package/dist/commands/switchaccount.js +35 -0
  20. package/dist/commands/switchaccount.js.map +1 -0
  21. package/dist/commands/update.js +95 -0
  22. package/dist/commands/update.js.map +1 -0
  23. package/dist/config/environments.js +53 -0
  24. package/dist/config/environments.js.map +1 -0
  25. package/dist/createApp/copyTemplate.js +237 -0
  26. package/dist/createApp/copyTemplate.js.map +1 -0
  27. package/dist/publish/orgResolve.js +30 -0
  28. package/dist/publish/orgResolve.js.map +1 -0
  29. package/dist/publish/responseClassifier.js +111 -0
  30. package/dist/publish/responseClassifier.js.map +1 -0
  31. package/dist/publish/siteClient.js +113 -0
  32. package/dist/publish/siteClient.js.map +1 -0
  33. package/dist/publish/siteConfig.js +190 -0
  34. package/dist/publish/siteConfig.js.map +1 -0
  35. package/dist/publish/siteZip.js +172 -0
  36. package/dist/publish/siteZip.js.map +1 -0
  37. package/dist/store/accountStore.js +236 -0
  38. package/dist/store/accountStore.js.map +1 -0
  39. package/dist/store/backends/encryptedFile.js +162 -0
  40. package/dist/store/backends/encryptedFile.js.map +1 -0
  41. package/dist/store/backends/osKeyring.js +283 -0
  42. package/dist/store/backends/osKeyring.js.map +1 -0
  43. package/dist/store/credentialStore.js +65 -0
  44. package/dist/store/credentialStore.js.map +1 -0
  45. package/dist/template/README.md +144 -0
  46. package/dist/template/android/.gitkeep +1 -0
  47. package/dist/template/android/app/build.gradle.kts +122 -0
  48. package/dist/template/android/app/src/main/AndroidManifest.xml +19 -0
  49. package/dist/template/android/app/src/main/java/com/supersdk/simple/MainActivity.java +17 -0
  50. package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +22 -0
  51. package/dist/template/android/app/src/test/java/com/supersdk/simple/AppNameResourceTest.java +19 -0
  52. package/dist/template/android/build.gradle.kts +3 -0
  53. package/dist/template/android/gradle/supersdk-config-reader.gradle +61 -0
  54. package/dist/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  55. package/dist/template/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  56. package/dist/template/android/gradle.properties +3 -0
  57. package/dist/template/android/gradlew +251 -0
  58. package/dist/template/android/settings.gradle.kts +25 -0
  59. package/dist/template/android/supersdk-default.config.json +17 -0
  60. package/dist/template/ios/MockSuperSDKPackage/Package.swift +15 -0
  61. package/dist/template/ios/MockSuperSDKPackage/Sources/SuperSDK/SuperSDK.swift +25 -0
  62. package/dist/template/ios/Resources/Info.plist +43 -0
  63. package/dist/template/ios/Sources/App/AppDelegate.swift +20 -0
  64. package/dist/template/ios/Sources/App/SceneDelegate.swift +14 -0
  65. package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +7 -0
  66. package/dist/template/ios/Sources/App/SimpleSDKProbe.swift +26 -0
  67. package/dist/template/ios/Sources/App/SimpleSDKProvider.swift +4 -0
  68. package/dist/template/ios/Sources/App/SimpleViewController.swift +20 -0
  69. package/dist/template/ios/Tests/SimpleAppTests/SimpleSDKInitializationTests.swift +17 -0
  70. package/dist/template/ios/project.yml +67 -0
  71. package/dist/template/scripts/android_snapshot_canary.py +136 -0
  72. package/dist/template/scripts/build_android.sh +240 -0
  73. package/dist/template/scripts/build_ios.sh +261 -0
  74. package/dist/template/scripts/build_web.sh +12 -0
  75. package/dist/template/scripts/serve_web.py +51 -0
  76. package/dist/template/scripts/super_build_orchestrator.py +400 -0
  77. package/dist/template/scripts/supersdk_template.py +611 -0
  78. package/dist/template/scripts/web_host_validator.py +103 -0
  79. package/dist/template/scripts/web_package.py +202 -0
  80. package/dist/template/scripts/ws03_shared_schema_merge_guard.py +73 -0
  81. package/dist/template/super_build.sh +116 -0
  82. package/dist/template/supersdk.yaml +15 -0
  83. package/dist/template/web/src/css/style.css +83 -0
  84. package/dist/template/web/src/index.html +37 -0
  85. package/dist/template/web/src/js/app.js +99 -0
  86. package/dist/template/web/src/js/supersdk.js +1848 -0
  87. package/dist/template/web/src/js/supersdk.provenance.json +6 -0
  88. package/dist/update/channelResolver.js +183 -0
  89. package/dist/update/channelResolver.js.map +1 -0
  90. package/dist/update/installSafety.js +135 -0
  91. package/dist/update/installSafety.js.map +1 -0
  92. package/dist/util/fsAtomic.js +294 -0
  93. package/dist/util/fsAtomic.js.map +1 -0
  94. package/dist/util/log.js +55 -0
  95. package/dist/util/log.js.map +1 -0
  96. package/dist/util/origin.js +66 -0
  97. package/dist/util/origin.js.map +1 -0
  98. package/dist/util/prompt.js +113 -0
  99. package/dist/util/prompt.js.map +1 -0
  100. package/package.json +43 -0
@@ -0,0 +1,400 @@
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
+
14
+ PLATFORMS = ("android", "ios", "web")
15
+ SUMMARY_PREFIX = "SUPERSDK_BUILD_SUMMARY_JSON="
16
+ DEFAULT_TIMEOUT_SECONDS = 1800.0
17
+ REASON_LIMIT = 500
18
+ TRUNCATION_MARKER = "...(truncated)"
19
+ OUTPUT_HEAD_LINES = 100
20
+ OUTPUT_TAIL_LINES = 100
21
+ OUTPUT_LOCK = threading.Lock()
22
+ FORWARDED_LINE_SEPARATOR_TRANSLATION = {
23
+ ord("\r"): "\\r",
24
+ ord("\f"): "\\f",
25
+ ord("\v"): "\\v",
26
+ 0x1C: "\\x1c",
27
+ 0x1D: "\\x1d",
28
+ 0x1E: "\\x1e",
29
+ 0x85: "\\x85",
30
+ 0x2028: "\\u2028",
31
+ 0x2029: "\\u2029",
32
+ }
33
+
34
+
35
+ @dataclass
36
+ class HelperOutput:
37
+ stdout_lines: list[str]
38
+ stderr_lines: list[str]
39
+ stdout_skip_line: str | None = None
40
+ stderr_skip_line: str | None = None
41
+
42
+
43
+ class BoundedLineBuffer:
44
+ def __init__(self):
45
+ self.head_lines = []
46
+ self.tail_lines = []
47
+ self.extra_line_count = 0
48
+
49
+ def append(self, line):
50
+ if len(self.head_lines) < OUTPUT_HEAD_LINES:
51
+ self.head_lines.append(line)
52
+ return
53
+ self.extra_line_count += 1
54
+ self.tail_lines.append(line)
55
+ if len(self.tail_lines) > OUTPUT_TAIL_LINES:
56
+ self.tail_lines.pop(0)
57
+
58
+ def lines(self):
59
+ if self.extra_line_count == 0:
60
+ return list(self.head_lines)
61
+ hidden_count = self.extra_line_count - len(self.tail_lines)
62
+ if hidden_count <= 0:
63
+ return [*self.head_lines, *self.tail_lines]
64
+ return [*self.head_lines, f"...({hidden_count} lines omitted)...\n", *self.tail_lines]
65
+
66
+
67
+ def selected_platforms(platform):
68
+ return list(PLATFORMS) if platform == "all" else [platform]
69
+
70
+
71
+ def helper_command(root, platform, config):
72
+ script = Path(root) / "scripts" / f"build_{platform}.sh"
73
+ command = [str(script), "--build"]
74
+ if platform == "android":
75
+ command.extend(["--config", str(config)])
76
+ return command
77
+
78
+
79
+ def helper_timeout_seconds():
80
+ raw = os.environ.get("SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS")
81
+ if raw is None or raw == "":
82
+ return DEFAULT_TIMEOUT_SECONDS
83
+ try:
84
+ value = float(raw)
85
+ except ValueError:
86
+ warn_invalid_timeout(raw)
87
+ return DEFAULT_TIMEOUT_SECONDS
88
+ if value > 0 and math.isfinite(value):
89
+ return value
90
+ warn_invalid_timeout(raw)
91
+ return DEFAULT_TIMEOUT_SECONDS
92
+
93
+
94
+ def warn_invalid_timeout(raw):
95
+ with OUTPUT_LOCK:
96
+ print(
97
+ f"[orchestrator] warning: ignoring invalid SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS={raw!r}; using {DEFAULT_TIMEOUT_SECONDS:g}s",
98
+ file=sys.stderr,
99
+ )
100
+
101
+
102
+ def decode_line(raw):
103
+ return raw.decode("utf-8", errors="replace")
104
+
105
+
106
+ def sanitize_forwarded_line(line):
107
+ suffix = "\n" if line.endswith("\n") else ""
108
+ body = line[:-1] if suffix else line
109
+ return body.translate(FORWARDED_LINE_SEPARATOR_TRANSLATION) + suffix
110
+
111
+
112
+ def forward_reader(pipe, platform, stream_name, sink, capture, skip_line_ref, capture_lock):
113
+ try:
114
+ while True:
115
+ raw = pipe.readline()
116
+ if raw == b"":
117
+ break
118
+ decoded = decode_line(raw)
119
+ normalized = decoded.rstrip("\r\n")
120
+ with capture_lock:
121
+ capture.append(decoded)
122
+ if skip_line_ref[stream_name] is None and is_skip_line(normalized):
123
+ skip_line_ref[stream_name] = normalized
124
+ with OUTPUT_LOCK:
125
+ forwarded = sanitize_forwarded_line(decoded)
126
+ sink.write(f"[{platform} {stream_name}] {forwarded}")
127
+ if not forwarded.endswith("\n"):
128
+ sink.write("\n")
129
+ sink.flush()
130
+ except (OSError, ValueError):
131
+ pass
132
+ finally:
133
+ try:
134
+ pipe.close()
135
+ except Exception:
136
+ pass
137
+
138
+
139
+ def snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock):
140
+ with capture_lock:
141
+ return HelperOutput(
142
+ stdout_capture.lines(),
143
+ stderr_capture.lines(),
144
+ skip_line_ref["stdout"],
145
+ skip_line_ref["stderr"],
146
+ )
147
+
148
+
149
+ def run_helper(command, platform, timeout_seconds):
150
+ stdout_capture = BoundedLineBuffer()
151
+ stderr_capture = BoundedLineBuffer()
152
+ skip_line_ref = {"stdout": None, "stderr": None}
153
+ capture_lock = threading.Lock()
154
+ try:
155
+ process = subprocess.Popen(
156
+ command,
157
+ stdout=subprocess.PIPE,
158
+ stderr=subprocess.PIPE,
159
+ start_new_session=True,
160
+ )
161
+ except OSError as exc:
162
+ return 127, HelperOutput(stdout_capture.lines(), stderr_capture.lines()), f"launch error: {exc}"
163
+
164
+ threads = [
165
+ threading.Thread(
166
+ target=forward_reader,
167
+ args=(process.stdout, platform, "stdout", sys.stdout, stdout_capture, skip_line_ref, capture_lock),
168
+ daemon=True,
169
+ ),
170
+ threading.Thread(
171
+ target=forward_reader,
172
+ args=(process.stderr, platform, "stderr", sys.stderr, stderr_capture, skip_line_ref, capture_lock),
173
+ daemon=True,
174
+ ),
175
+ ]
176
+ for thread in threads:
177
+ thread.start()
178
+
179
+ timed_out = False
180
+ try:
181
+ exit_code = process.wait(timeout=timeout_seconds)
182
+ except subprocess.TimeoutExpired:
183
+ timed_out = True
184
+ terminate_process_group(process, platform)
185
+ exit_code = 124
186
+
187
+ for thread in threads:
188
+ thread.join(timeout=5)
189
+ pipe_open = any(thread.is_alive() for thread in threads)
190
+
191
+ output = snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock)
192
+ if timed_out:
193
+ return exit_code, output, f"timeout after {timeout_seconds:g}s"
194
+ if pipe_open:
195
+ with OUTPUT_LOCK:
196
+ print(f"[{platform}] warning: helper output pipe remained open after process exit", file=sys.stderr)
197
+ return exit_code, output, None
198
+
199
+
200
+ def terminate_process_group(process, platform):
201
+ try:
202
+ os.killpg(process.pid, signal.SIGTERM)
203
+ except Exception:
204
+ with OUTPUT_LOCK:
205
+ print(f"[{platform}] warning: could not terminate process group {process.pid}", file=sys.stderr)
206
+ try:
207
+ process.terminate()
208
+ except Exception:
209
+ with OUTPUT_LOCK:
210
+ print(f"[{platform}] warning: could not terminate process {process.pid}", file=sys.stderr)
211
+ pass
212
+ try:
213
+ process.wait(timeout=2)
214
+ return
215
+ except Exception:
216
+ pass
217
+ try:
218
+ os.killpg(process.pid, signal.SIGKILL)
219
+ except Exception:
220
+ with OUTPUT_LOCK:
221
+ print(f"[{platform}] warning: could not kill process group {process.pid}", file=sys.stderr)
222
+ try:
223
+ process.kill()
224
+ except Exception:
225
+ with OUTPUT_LOCK:
226
+ print(f"[{platform}] warning: could not kill process {process.pid}", file=sys.stderr)
227
+ pass
228
+ try:
229
+ process.wait(timeout=2)
230
+ except Exception:
231
+ pass
232
+
233
+
234
+ def is_skip_line(line):
235
+ return line.startswith("SKIP_") or line.startswith("BUILD SKIPPED")
236
+
237
+
238
+ def first_skip_line(output):
239
+ if output.stdout_skip_line is not None:
240
+ return output.stdout_skip_line
241
+ if output.stderr_skip_line is not None:
242
+ return output.stderr_skip_line
243
+ for lines in (output.stdout_lines, output.stderr_lines):
244
+ for line in lines:
245
+ normalized = line.rstrip("\r\n")
246
+ if is_skip_line(normalized):
247
+ return normalized
248
+ return None
249
+
250
+
251
+ def output_excerpt(output):
252
+ for lines in (output.stderr_lines, output.stdout_lines):
253
+ text = "".join(line for line in lines if not is_omission_marker(line)).strip()
254
+ if text:
255
+ return " ".join(text.split())
256
+ return ""
257
+
258
+
259
+ def is_omission_marker(line):
260
+ return line.startswith("...(") and line.endswith(" lines omitted)...\n")
261
+
262
+
263
+ def cap_reason(reason):
264
+ if len(reason) <= REASON_LIMIT:
265
+ return reason
266
+ return reason[: REASON_LIMIT - len(TRUNCATION_MARKER)] + TRUNCATION_MARKER
267
+
268
+
269
+ def classify_result(platform, command, exit_code, output, launch_or_timeout_reason=None):
270
+ command_payload = [str(item) for item in command]
271
+ if launch_or_timeout_reason is not None:
272
+ return platform_result(platform, "failed", exit_code, cap_reason(launch_or_timeout_reason), command_payload)
273
+
274
+ if exit_code != 0:
275
+ excerpt = output_excerpt(output)
276
+ reason = f"exit_code={exit_code}"
277
+ if excerpt:
278
+ reason = f"{reason}; {excerpt}"
279
+ return platform_result(platform, "failed", exit_code, cap_reason(reason), command_payload)
280
+
281
+ if platform != "web":
282
+ marker = first_skip_line(output)
283
+ if marker is not None:
284
+ return platform_result(platform, "skipped", exit_code, cap_reason(marker), command_payload)
285
+
286
+ return platform_result(platform, "success", exit_code, "", command_payload)
287
+
288
+
289
+ def platform_result(platform, status, exit_code, reason, command):
290
+ return {
291
+ "platform": platform,
292
+ "status": status,
293
+ "exit_code": int(exit_code),
294
+ "reason": reason,
295
+ "command": command,
296
+ }
297
+
298
+
299
+ def aggregate_summary(results):
300
+ statuses = [item["status"] for item in results]
301
+ if any(status == "failed" for status in statuses):
302
+ overall_status = "failed"
303
+ elif statuses and all(status == "skipped" for status in statuses):
304
+ overall_status = "skipped"
305
+ else:
306
+ overall_status = "success"
307
+ exit_code = 1 if overall_status == "failed" else 0
308
+ return {
309
+ "schema_version": 1,
310
+ "overall_status": overall_status,
311
+ "overall_exit_code": exit_code,
312
+ "platforms": results,
313
+ }
314
+
315
+
316
+ def emit_summary(summary):
317
+ payload = SUMMARY_PREFIX + json.dumps(summary, separators=(",", ":")) + "\n"
318
+ with OUTPUT_LOCK:
319
+ sys.stdout.write(payload)
320
+ sys.stdout.flush()
321
+
322
+
323
+ def command_payload(command):
324
+ return [str(part) for part in command] if command else ["<command-unavailable>"]
325
+
326
+
327
+ def run_all(root, platform, config):
328
+ timeout = helper_timeout_seconds()
329
+ results = []
330
+ platforms = selected_platforms(platform)
331
+ for index, item in enumerate(platforms):
332
+ command = []
333
+ try:
334
+ command = helper_command(root, item, config)
335
+ exit_code, output, launch_or_timeout_reason = run_helper(command, item, timeout)
336
+ results.append(classify_result(item, command, exit_code, output, launch_or_timeout_reason))
337
+ except Exception as exc:
338
+ results.append(
339
+ platform_result(
340
+ item,
341
+ "failed",
342
+ 1,
343
+ cap_reason(f"internal orchestrator error: {exc}"),
344
+ command_payload(command),
345
+ )
346
+ )
347
+ for remaining in platforms[index + 1 :]:
348
+ remaining_command = []
349
+ try:
350
+ remaining_command = helper_command(root, remaining, config)
351
+ except Exception:
352
+ pass
353
+ results.append(
354
+ platform_result(
355
+ remaining,
356
+ "failed",
357
+ 1,
358
+ cap_reason(f"not run after internal orchestrator error in {item}: {exc}"),
359
+ command_payload(remaining_command),
360
+ )
361
+ )
362
+ break
363
+ return aggregate_summary(results)
364
+
365
+
366
+ def fallback_internal_summary(platform, root, config, exc):
367
+ results = []
368
+ for index, item in enumerate(selected_platforms(platform)):
369
+ try:
370
+ command = helper_command(root, item, config)
371
+ except Exception:
372
+ command = []
373
+ reason = f"internal orchestrator error: {exc}" if index == 0 else f"not run after internal orchestrator error: {exc}"
374
+ results.append(platform_result(item, "failed", 1, cap_reason(reason), command_payload(command)))
375
+ return aggregate_summary(results)
376
+
377
+
378
+ def main(argv=None):
379
+ parser = argparse.ArgumentParser(description="Run SuperSDK template platform builds and emit one root summary")
380
+ parser.add_argument("--root", required=True)
381
+ parser.add_argument("--platform", choices=["all", *PLATFORMS], required=True)
382
+ parser.add_argument("--config", required=True)
383
+ args = parser.parse_args(argv)
384
+
385
+ root = Path(args.root).resolve()
386
+ config = Path(args.config).resolve()
387
+ try:
388
+ summary = run_all(root, args.platform, config)
389
+ except Exception as exc:
390
+ summary = fallback_internal_summary(args.platform, root, config, exc)
391
+ try:
392
+ emit_summary(summary)
393
+ except Exception as exc:
394
+ print(f"internal orchestrator error while emitting summary: {exc}", file=sys.stderr)
395
+ return 1
396
+ return summary["overall_exit_code"]
397
+
398
+
399
+ if __name__ == "__main__":
400
+ raise SystemExit(main())