@supersdk/supercli 0.1.2 → 0.2.0-staging.14
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.
- package/dist/commands/createApp.js +274 -7
- package/dist/commands/createApp.js.map +1 -1
- package/dist/commands/publishSite.js +218 -91
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/config/appConfig.js +187 -0
- package/dist/config/appConfig.js.map +1 -0
- package/dist/createApp/copyTemplate.js +337 -45
- package/dist/createApp/copyTemplate.js.map +1 -1
- package/dist/publish/siteConfig.js +352 -165
- package/dist/publish/siteConfig.js.map +1 -1
- package/dist/publish/siteZip.js +7 -2
- package/dist/publish/siteZip.js.map +1 -1
- package/dist/template/README.md +59 -9
- package/dist/template/android/app/build.gradle.kts +7 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +1 -1
- package/dist/template/ios/Sources/App/AppDelegate.swift +1 -1
- package/dist/template/scripts/android_snapshot_canary.py +1 -1
- package/dist/template/scripts/build_android.sh +1 -1
- package/dist/template/scripts/build_ios.sh +5 -10
- package/dist/template/scripts/serve_web.py +15 -3
- package/dist/template/scripts/supersdk_template.py +164 -140
- package/dist/template/scripts/web_package.py +65 -8
- package/dist/template/super_build.sh +2 -2
- package/dist/template/supersdk.json +23 -0
- package/dist/template/web/src/js/app.js +5 -2
- package/dist/util/prompt.js +23 -0
- package/dist/util/prompt.js.map +1 -1
- package/dist/util/shell.js +21 -0
- package/dist/util/shell.js.map +1 -0
- package/package.json +1 -1
- package/dist/template/supersdk.yaml +0 -16
|
@@ -4,6 +4,7 @@ import ipaddress
|
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
6
|
import re
|
|
7
|
+
import shlex
|
|
7
8
|
import sys
|
|
8
9
|
import uuid
|
|
9
10
|
from pathlib import Path
|
|
@@ -14,13 +15,26 @@ from web_host_validator import HostValidationError, normalize_host
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
MANAGED_BY = "supersdk-template"
|
|
18
|
+
# Managed projections under <platform>/.supersdk/managed/config.json keep their own
|
|
19
|
+
# snake_case `schema_version`; it is a different contract from the root config file.
|
|
17
20
|
MANAGED_CONFIG_SCHEMA_VERSION = 2
|
|
18
21
|
MANAGED_SCHEMA_VERSION = MANAGED_CONFIG_SCHEMA_VERSION
|
|
19
22
|
MANAGED_CONFIG_KEYS = ("managed_by", "schema_version", "spid", "environment", "name", "platform", "version", "sdk", "platform_config")
|
|
23
|
+
|
|
24
|
+
# Root project config: one human+machine writable standard JSON file at the repo root.
|
|
25
|
+
CONFIG_FILENAME = "supersdk.json"
|
|
26
|
+
CONFIG_SCHEMA_VERSION = 2
|
|
27
|
+
LEGACY_CONFIG_FILENAMES = ("supersdk.yaml", "supersdk.yml", "super-site.yml")
|
|
28
|
+
# Retired root keys keep a targeted diagnostic; every other unknown root key is
|
|
29
|
+
# preserved and ignored so CLI-owned and hand-written fields never break a build.
|
|
30
|
+
RETIRED_ROOT_KEYS = {
|
|
31
|
+
"schema_version": f"retired schema v1 key; use camelCase schemaVersion: {CONFIG_SCHEMA_VERSION}",
|
|
32
|
+
"app_id": "retired key; rename it to spid",
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
ANDROID_NAMESPACE = "com.supersdk.simple"
|
|
21
36
|
ANDROID_VERSION_RE = r"^[0-9]+\.[0-9]+\.[0-9]+(?:[-.][A-Za-z0-9]+)*$"
|
|
22
37
|
PLATFORMS = ("android", "ios", "web")
|
|
23
|
-
ROOT_KEYS = {"schema_version", "spid", "environment", "name", "android", "ios", "web", "version", "sdk"}
|
|
24
38
|
NAMESPACE_KEYS = {
|
|
25
39
|
"android": {"package"},
|
|
26
40
|
"ios": {"bundleId", "spmMode"},
|
|
@@ -38,6 +52,33 @@ SDK_PROJECTION = {
|
|
|
38
52
|
"web": {"mock": (), "real": ()},
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
# Every required field is present on purpose: a migration hint that omits one is
|
|
56
|
+
# a dead end for whoever copies it.
|
|
57
|
+
MIGRATION_TEMPLATE = """{
|
|
58
|
+
"schemaVersion": 2,
|
|
59
|
+
"spid": "demo0001",
|
|
60
|
+
"name": "SuperSDK Simple",
|
|
61
|
+
"environment": "prod",
|
|
62
|
+
"android": {
|
|
63
|
+
"package": "com.example.app"
|
|
64
|
+
},
|
|
65
|
+
"ios": {
|
|
66
|
+
"bundleId": "com.example.app",
|
|
67
|
+
"spmMode": "mock"
|
|
68
|
+
},
|
|
69
|
+
"web": {
|
|
70
|
+
"host": "app.example.com"
|
|
71
|
+
},
|
|
72
|
+
"version": {
|
|
73
|
+
"name": "1.0.0",
|
|
74
|
+
"code": 1
|
|
75
|
+
},
|
|
76
|
+
"sdk": {
|
|
77
|
+
"androidVersion": "1.0.0.54-SNAPSHOT"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
"""
|
|
81
|
+
|
|
41
82
|
|
|
42
83
|
class ConfigError(Exception):
|
|
43
84
|
def __init__(self, field, message):
|
|
@@ -46,143 +87,109 @@ class ConfigError(Exception):
|
|
|
46
87
|
self.message = message
|
|
47
88
|
|
|
48
89
|
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
in_double = False
|
|
52
|
-
escaped = False
|
|
53
|
-
for index, char in enumerate(line):
|
|
54
|
-
if in_double and escaped:
|
|
55
|
-
escaped = False
|
|
56
|
-
continue
|
|
57
|
-
if in_double and char == "\\":
|
|
58
|
-
escaped = True
|
|
59
|
-
continue
|
|
60
|
-
if char == "'" and not in_double:
|
|
61
|
-
in_single = not in_single
|
|
62
|
-
elif char == '"' and not in_single:
|
|
63
|
-
in_double = not in_double
|
|
64
|
-
elif char == "#" and not in_single and not in_double and (index == 0 or line[index - 1].isspace()):
|
|
65
|
-
return line[:index]
|
|
66
|
-
return line
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def parse_scalar(raw):
|
|
70
|
-
value = raw.strip()
|
|
71
|
-
if value == "":
|
|
72
|
-
return None
|
|
73
|
-
if value[0:1] in ("[", "{", "&", "*") or value.startswith("|") or value.startswith(">"):
|
|
74
|
-
raise ConfigError("yaml", "unsupported YAML feature in schema v1")
|
|
75
|
-
if value.startswith('"') and value.endswith('"'):
|
|
76
|
-
inner = value[1:-1]
|
|
77
|
-
if "\\" in inner:
|
|
78
|
-
raise ConfigError("yaml", "unsupported escape in schema v1 scalar; use --parser pyyaml")
|
|
79
|
-
return inner
|
|
80
|
-
if value.startswith("'") and value.endswith("'"):
|
|
81
|
-
inner = value[1:-1]
|
|
82
|
-
if "''" in inner:
|
|
83
|
-
raise ConfigError("yaml", "unsupported escape in schema v1 scalar; use --parser pyyaml")
|
|
84
|
-
return value[1:-1]
|
|
85
|
-
if re.fullmatch(r"-?\d+", value):
|
|
86
|
-
return int(value)
|
|
87
|
-
if re.fullmatch(r"-?(\d+\.\d*|\d*\.\d+)", value):
|
|
88
|
-
return float(value)
|
|
89
|
-
if value == "true":
|
|
90
|
-
return True
|
|
91
|
-
if value == "false":
|
|
92
|
-
return False
|
|
93
|
-
if value in ("null", "~"):
|
|
94
|
-
return None
|
|
95
|
-
return value
|
|
90
|
+
def config_file_state(target_path):
|
|
91
|
+
"""Classify an existing supersdk.json so the hint never overwrites real values.
|
|
96
92
|
|
|
93
|
+
Returns ("missing" | "valid" | "invalid", reason). It parses the target directly
|
|
94
|
+
instead of going through load_config(), which would re-trigger the legacy scan.
|
|
95
|
+
"""
|
|
96
|
+
if not target_path.is_file():
|
|
97
|
+
return "missing", ""
|
|
98
|
+
try:
|
|
99
|
+
validate_config(read_config_document(target_path))
|
|
100
|
+
except ConfigError as exc:
|
|
101
|
+
return "invalid", exc.message
|
|
102
|
+
return "valid", ""
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
104
|
+
|
|
105
|
+
def migration_hint(legacy_path, target_path):
|
|
106
|
+
legacy = shlex.quote(str(legacy_path))
|
|
107
|
+
target = shlex.quote(str(target_path))
|
|
108
|
+
skeleton = f"cat > {target} <<'SUPERSDK_JSON'\n{MIGRATION_TEMPLATE}SUPERSDK_JSON\n"
|
|
109
|
+
header = (
|
|
110
|
+
f"legacy config {legacy_path} is not supported; the template reads standard JSON "
|
|
111
|
+
f"{CONFIG_FILENAME} (schemaVersion {CONFIG_SCHEMA_VERSION}) only.\n"
|
|
112
|
+
)
|
|
113
|
+
state, reason = config_file_state(target_path)
|
|
114
|
+
if state == "valid":
|
|
115
|
+
# The only safe action here: the real config already exists, so emitting a
|
|
116
|
+
# `cat >` skeleton would replace live spid/package/bundleId/host with defaults.
|
|
117
|
+
return (
|
|
118
|
+
header
|
|
119
|
+
+ f"your {target_path} is already in place and valid, so nothing needs to be written; "
|
|
120
|
+
"the legacy file is the only leftover. Copy-paste to remove it:\n"
|
|
121
|
+
+ f"rm {legacy}\n"
|
|
122
|
+
)
|
|
123
|
+
if state == "invalid":
|
|
124
|
+
return (
|
|
125
|
+
header
|
|
126
|
+
+ f"{target_path} exists but is not usable ({reason}), so back it up before replacing it. "
|
|
127
|
+
"Copy-paste to migrate, then replace every value with the one from the legacy file "
|
|
128
|
+
"(the legacy file is deleted last because it is the source of those values):\n"
|
|
129
|
+
+ f"cp {target} {shlex.quote(str(target_path) + '.bak')}\n"
|
|
130
|
+
+ skeleton
|
|
131
|
+
+ f"rm {legacy}\n"
|
|
132
|
+
)
|
|
133
|
+
return (
|
|
134
|
+
header
|
|
135
|
+
+ "Copy-paste to migrate, then replace every value with the one from the legacy file "
|
|
136
|
+
"(the new file is written first and the legacy file is deleted last, because the legacy "
|
|
137
|
+
"file is the source of those values):\n"
|
|
138
|
+
+ skeleton
|
|
139
|
+
+ f"rm {legacy}\n"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def reject_duplicate_keys(pairs):
|
|
144
|
+
mapping = {}
|
|
145
|
+
for key, value in pairs:
|
|
146
|
+
if key in mapping:
|
|
147
|
+
raise ConfigError(key, "duplicate key")
|
|
148
|
+
mapping[key] = value
|
|
149
|
+
return mapping
|
|
137
150
|
|
|
138
151
|
|
|
139
|
-
def
|
|
152
|
+
def reject_json_constant(name):
|
|
153
|
+
# stdlib json accepts NaN/Infinity/-Infinity; JSON.parse in supercli does not.
|
|
154
|
+
# Both sides must read the same file the same way, so reject them here too.
|
|
155
|
+
raise ConfigError(CONFIG_FILENAME, f"{name} is not standard JSON; use a number, string, or null")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def read_config_document(config_path):
|
|
159
|
+
"""Read and parse one config file. No legacy scanning, so it is reentrant."""
|
|
160
|
+
config_path = Path(config_path)
|
|
161
|
+
if not config_path.is_file():
|
|
162
|
+
raise ConfigError(CONFIG_FILENAME, f"not found: {config_path}")
|
|
140
163
|
try:
|
|
141
|
-
|
|
142
|
-
except
|
|
143
|
-
raise ConfigError(
|
|
144
|
-
class UniqueKeyLoader(yaml.SafeLoader):
|
|
145
|
-
pass
|
|
146
|
-
|
|
147
|
-
def construct_unique_mapping(loader, node, deep=False):
|
|
148
|
-
mapping = {}
|
|
149
|
-
for key_node, value_node in node.value:
|
|
150
|
-
key = loader.construct_object(key_node, deep=deep)
|
|
151
|
-
if key in mapping:
|
|
152
|
-
raise ConfigError("yaml", f"duplicate key {key}")
|
|
153
|
-
mapping[key] = loader.construct_object(value_node, deep=deep)
|
|
154
|
-
return mapping
|
|
155
|
-
|
|
156
|
-
UniqueKeyLoader.add_constructor(
|
|
157
|
-
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
|
|
158
|
-
construct_unique_mapping,
|
|
159
|
-
)
|
|
164
|
+
text = config_path.read_text(encoding="utf-8")
|
|
165
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
166
|
+
raise ConfigError(CONFIG_FILENAME, f"unreadable: {exc}") from exc
|
|
160
167
|
try:
|
|
161
|
-
|
|
168
|
+
return json.loads(text, object_pairs_hook=reject_duplicate_keys, parse_constant=reject_json_constant)
|
|
162
169
|
except ConfigError:
|
|
163
170
|
raise
|
|
164
|
-
except
|
|
165
|
-
raise ConfigError(
|
|
166
|
-
return {} if loaded is None else loaded
|
|
171
|
+
except json.JSONDecodeError as exc:
|
|
172
|
+
raise ConfigError(CONFIG_FILENAME, f"invalid JSON at line {exc.lineno} column {exc.colno}: {exc.msg}") from exc
|
|
167
173
|
|
|
168
174
|
|
|
169
|
-
def
|
|
175
|
+
def load_config(path):
|
|
170
176
|
config_path = Path(path)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
target_path = config_path.parent / CONFIG_FILENAME
|
|
178
|
+
# Fail closed on the retired dialects instead of guessing an equivalent JSON doc.
|
|
179
|
+
if config_path.name in LEGACY_CONFIG_FILENAMES or config_path.suffix.lower() in (".yaml", ".yml"):
|
|
180
|
+
raise ConfigError(config_path.name, migration_hint(config_path, target_path))
|
|
181
|
+
for legacy_name in LEGACY_CONFIG_FILENAMES:
|
|
182
|
+
legacy_path = config_path.parent / legacy_name
|
|
183
|
+
if legacy_path.is_file():
|
|
184
|
+
raise ConfigError(legacy_name, migration_hint(legacy_path, target_path))
|
|
185
|
+
return read_config_document(config_path)
|
|
179
186
|
|
|
180
187
|
|
|
181
188
|
def require_mapping(value, field):
|
|
182
189
|
if value is None:
|
|
183
190
|
return {}
|
|
184
191
|
if not isinstance(value, dict):
|
|
185
|
-
raise ConfigError(field, "must be a
|
|
192
|
+
raise ConfigError(field, "must be a JSON object")
|
|
186
193
|
return value
|
|
187
194
|
|
|
188
195
|
|
|
@@ -263,16 +270,29 @@ def validate_ios_version(value):
|
|
|
263
270
|
return value
|
|
264
271
|
|
|
265
272
|
|
|
273
|
+
def validate_cli_owned_keys(raw):
|
|
274
|
+
# `orgId` and `sites` belong to supercli. The template only type-checks them so a
|
|
275
|
+
# site-side schema change can never break an app build, then ignores them wholesale.
|
|
276
|
+
if "orgId" in raw and not isinstance(raw["orgId"], str):
|
|
277
|
+
raise ConfigError("orgId", "must be a string")
|
|
278
|
+
if "sites" in raw and not isinstance(raw["sites"], list):
|
|
279
|
+
raise ConfigError("sites", "must be an array")
|
|
280
|
+
|
|
281
|
+
|
|
266
282
|
def validate_config(raw, selected=None):
|
|
267
283
|
selected = set(selected or PLATFORMS)
|
|
268
284
|
if not isinstance(raw, dict):
|
|
269
|
-
raise ConfigError(
|
|
270
|
-
for key in
|
|
271
|
-
if key
|
|
272
|
-
raise ConfigError(key,
|
|
285
|
+
raise ConfigError(CONFIG_FILENAME, "top-level document must be a JSON object")
|
|
286
|
+
for key, reason in RETIRED_ROOT_KEYS.items():
|
|
287
|
+
if key in raw:
|
|
288
|
+
raise ConfigError(key, reason)
|
|
289
|
+
|
|
290
|
+
schema_version = raw.get("schemaVersion")
|
|
291
|
+
if isinstance(schema_version, bool) or not isinstance(schema_version, int) or schema_version != CONFIG_SCHEMA_VERSION:
|
|
292
|
+
raise ConfigError("schemaVersion", f"must be {CONFIG_SCHEMA_VERSION}")
|
|
293
|
+
|
|
294
|
+
validate_cli_owned_keys(raw)
|
|
273
295
|
|
|
274
|
-
if type(raw.get("schema_version")) is not int or raw.get("schema_version") != 1:
|
|
275
|
-
raise ConfigError("schema_version", "must be 1")
|
|
276
296
|
spid = require_string(raw.get("spid"), "spid")
|
|
277
297
|
if not re.fullmatch(SPID_PATTERN, spid):
|
|
278
298
|
raise ConfigError("spid", f"must match ^{SPID_PATTERN}$")
|
|
@@ -334,7 +354,7 @@ def validate_config(raw, selected=None):
|
|
|
334
354
|
version_code = validate_version_code(version.get("code", 1))
|
|
335
355
|
|
|
336
356
|
return {
|
|
337
|
-
"
|
|
357
|
+
"schemaVersion": CONFIG_SCHEMA_VERSION,
|
|
338
358
|
"spid": spid,
|
|
339
359
|
"environment": environment,
|
|
340
360
|
"name": name,
|
|
@@ -377,6 +397,13 @@ def require_android_config(normalized):
|
|
|
377
397
|
|
|
378
398
|
def require_ios_config(normalized):
|
|
379
399
|
ios = normalized["platforms"]["ios"]
|
|
400
|
+
# Symmetric with require_android_config: an iOS app identity is never derived.
|
|
401
|
+
# Guessing one would ship a third-party app under the SDK's own reverse domain.
|
|
402
|
+
bundle_id = ios.get("bundleId")
|
|
403
|
+
if bundle_id is None or not isinstance(bundle_id, str) or bundle_id.strip() == "":
|
|
404
|
+
raise ConfigError("ios.bundleId", "required for ios platform")
|
|
405
|
+
if not re.fullmatch(BUNDLE_ID_PATTERN, bundle_id):
|
|
406
|
+
raise ConfigError("ios.bundleId", "must be a valid bundle identifier")
|
|
380
407
|
if ios.get("spmMode", "mock") != "real":
|
|
381
408
|
return
|
|
382
409
|
for key in SDK_PROJECTION["ios"]["real"]:
|
|
@@ -391,8 +418,8 @@ def enforce_platform_contracts(normalized, platform):
|
|
|
391
418
|
require_ios_config(normalized)
|
|
392
419
|
|
|
393
420
|
|
|
394
|
-
def load_and_validate(config_path,
|
|
395
|
-
return validate_config(
|
|
421
|
+
def load_and_validate(config_path, selected=None):
|
|
422
|
+
return validate_config(load_config(config_path), selected)
|
|
396
423
|
|
|
397
424
|
|
|
398
425
|
def selected_platforms(platform):
|
|
@@ -466,9 +493,9 @@ def build_write_plan(root, normalized, platform):
|
|
|
466
493
|
]
|
|
467
494
|
|
|
468
495
|
|
|
469
|
-
def inject(root, config, platform,
|
|
496
|
+
def inject(root, config, platform, force, dry_run):
|
|
470
497
|
root_path = Path(root)
|
|
471
|
-
normalized = load_and_validate(config,
|
|
498
|
+
normalized = load_and_validate(config, selected_platforms(platform))
|
|
472
499
|
plan = build_write_plan(root, normalized, platform)
|
|
473
500
|
if dry_run:
|
|
474
501
|
refused = [str(path) for path, _ in plan if not force and not is_managed_or_empty(path)]
|
|
@@ -571,8 +598,8 @@ def inject(root, config, platform, parser, force, dry_run):
|
|
|
571
598
|
print(json.dumps({"written": [str(path) for path, _ in plan], "skipped": [], "refused": []}, indent=2, sort_keys=True))
|
|
572
599
|
|
|
573
600
|
|
|
574
|
-
def print_plan(root, config, platform
|
|
575
|
-
normalized = load_and_validate(config,
|
|
601
|
+
def print_plan(root, config, platform):
|
|
602
|
+
normalized = load_and_validate(config, selected_platforms(platform))
|
|
576
603
|
enforce_platform_contracts(normalized, platform)
|
|
577
604
|
for item in selected_platforms(platform):
|
|
578
605
|
print(f"platform={item} helper={Path(root) / 'scripts' / ('build_' + item + '.sh')} mode=plan")
|
|
@@ -584,30 +611,27 @@ def main(argv):
|
|
|
584
611
|
|
|
585
612
|
validate = sub.add_parser("validate")
|
|
586
613
|
validate.add_argument("--config", required=True)
|
|
587
|
-
validate.add_argument("--parser", choices=["auto", "pyyaml", "fallback"], default="auto")
|
|
588
614
|
|
|
589
615
|
plan = sub.add_parser("plan")
|
|
590
616
|
plan.add_argument("--root", required=True)
|
|
591
617
|
plan.add_argument("--config", required=True)
|
|
592
618
|
plan.add_argument("--platform", choices=["all", *PLATFORMS], default="all")
|
|
593
|
-
plan.add_argument("--parser", choices=["auto", "pyyaml", "fallback"], default="auto")
|
|
594
619
|
|
|
595
620
|
inject_cmd = sub.add_parser("inject")
|
|
596
621
|
inject_cmd.add_argument("--root", required=True)
|
|
597
622
|
inject_cmd.add_argument("--config", required=True)
|
|
598
623
|
inject_cmd.add_argument("--platform", choices=["all", *PLATFORMS], default="all")
|
|
599
|
-
inject_cmd.add_argument("--parser", choices=["auto", "pyyaml", "fallback"], default="auto")
|
|
600
624
|
inject_cmd.add_argument("--force", action="store_true")
|
|
601
625
|
inject_cmd.add_argument("--dry-run", action="store_true")
|
|
602
626
|
|
|
603
627
|
args = parser.parse_args(argv)
|
|
604
628
|
try:
|
|
605
629
|
if args.command == "validate":
|
|
606
|
-
print(json.dumps(load_and_validate(args.config
|
|
630
|
+
print(json.dumps(load_and_validate(args.config), indent=2, sort_keys=True))
|
|
607
631
|
elif args.command == "plan":
|
|
608
|
-
print_plan(args.root, args.config, args.platform
|
|
632
|
+
print_plan(args.root, args.config, args.platform)
|
|
609
633
|
elif args.command == "inject":
|
|
610
|
-
inject(args.root, args.config, args.platform, args.
|
|
634
|
+
inject(args.root, args.config, args.platform, args.force, args.dry_run)
|
|
611
635
|
except ConfigError as exc:
|
|
612
636
|
print(str(exc), file=sys.stderr)
|
|
613
637
|
return 1
|
|
@@ -18,6 +18,18 @@ REQUIRED_ASSETS = ("index.html", "js/app.js", "js/supersdk.js", "css/style.css")
|
|
|
18
18
|
EXCLUDED_ASSETS = {"__super_meta.json", ".DS_Store", "js/supersdk.provenance.json"}
|
|
19
19
|
HEX64 = set("0123456789abcdef")
|
|
20
20
|
VERSION_PATTERN = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+$")
|
|
21
|
+
CONFIG_FILENAME = "supersdk.json"
|
|
22
|
+
|
|
23
|
+
# `web/src` is authored input; `web/dist` is the single publishable build output.
|
|
24
|
+
# It is what the offline zip is built from AND what `supercli publish-site <dir>`
|
|
25
|
+
# takes: a directory with a root index.html and no build-only sidecars.
|
|
26
|
+
# Same source tree, not identical content: the zip additionally carries the offline
|
|
27
|
+
# manifest `__super_meta.json` at its root, which never belongs in a published site.
|
|
28
|
+
DIST_DIRNAME = "dist"
|
|
29
|
+
# Runtime config lives INSIDE the package root. The old `../.supersdk/managed/config.json`
|
|
30
|
+
# path sat outside the zip/site root and was dropped by the publisher's dotdir rule.
|
|
31
|
+
DIST_CONFIG_ASSET = "supersdk-config.json"
|
|
32
|
+
DIST_EXCLUDED_ASSETS = ("js/supersdk.provenance.json", "__super_meta.json", ".DS_Store")
|
|
21
33
|
|
|
22
34
|
|
|
23
35
|
class WebPackageError(Exception):
|
|
@@ -38,14 +50,15 @@ def validate_version(value):
|
|
|
38
50
|
return value
|
|
39
51
|
|
|
40
52
|
|
|
41
|
-
def validate_source(src):
|
|
53
|
+
def validate_source(src, require_provenance=True):
|
|
42
54
|
root = Path(src)
|
|
43
55
|
if not root.is_dir():
|
|
44
56
|
raise WebPackageError(f"web package source missing: {root}")
|
|
45
57
|
for asset in REQUIRED_ASSETS:
|
|
46
58
|
if not (root / asset).is_file():
|
|
47
59
|
raise WebPackageError(f"web package asset missing: {asset}")
|
|
48
|
-
|
|
60
|
+
if require_provenance:
|
|
61
|
+
validate_provenance(root)
|
|
49
62
|
return root
|
|
50
63
|
|
|
51
64
|
|
|
@@ -66,13 +79,13 @@ def validate_provenance(root):
|
|
|
66
79
|
raise WebPackageError("supersdk.provenance.json: vendored_sha256 mismatch")
|
|
67
80
|
|
|
68
81
|
|
|
69
|
-
def validate_inputs(src, host, version):
|
|
82
|
+
def validate_inputs(src, host, version, require_provenance=True):
|
|
70
83
|
try:
|
|
71
84
|
normalized_host = normalize_host(host)
|
|
72
85
|
except HostValidationError as exc:
|
|
73
86
|
raise WebPackageError(f"web.host: {exc}") from exc
|
|
74
87
|
normalized_version = validate_version(version)
|
|
75
|
-
source_root = validate_source(src)
|
|
88
|
+
source_root = validate_source(src, require_provenance=require_provenance)
|
|
76
89
|
return source_root, normalized_host, normalized_version
|
|
77
90
|
|
|
78
91
|
|
|
@@ -127,8 +140,46 @@ def zip_staging(staging, output_dir, host, version):
|
|
|
127
140
|
temp_zip.unlink()
|
|
128
141
|
|
|
129
142
|
|
|
130
|
-
def
|
|
131
|
-
|
|
143
|
+
def build_dist(app_root, managed_config):
|
|
144
|
+
"""Render web/src + the managed config into the publishable web/dist directory.
|
|
145
|
+
|
|
146
|
+
Built in a sibling temp dir and swapped in, so a failed build never leaves a
|
|
147
|
+
half-written dist behind for `publish-site` to upload.
|
|
148
|
+
|
|
149
|
+
`package()` then zips a copy of this same tree; the zip is not byte-identical to
|
|
150
|
+
dist because `write_meta` adds the offline manifest `__super_meta.json` to the
|
|
151
|
+
package root. Same source tree, one extra offline-only file.
|
|
152
|
+
"""
|
|
153
|
+
app_root = Path(app_root)
|
|
154
|
+
source_root = validate_source(app_root / "web" / "src")
|
|
155
|
+
dist = app_root / "web" / DIST_DIRNAME
|
|
156
|
+
dist.parent.mkdir(parents=True, exist_ok=True)
|
|
157
|
+
staging_parent = Path(tempfile.mkdtemp(prefix=".supersdk-web-dist-", dir=dist.parent))
|
|
158
|
+
staging = staging_parent / DIST_DIRNAME
|
|
159
|
+
try:
|
|
160
|
+
shutil.copytree(source_root, staging)
|
|
161
|
+
for relative in DIST_EXCLUDED_ASSETS:
|
|
162
|
+
candidate = staging / relative
|
|
163
|
+
if candidate.is_file():
|
|
164
|
+
candidate.unlink()
|
|
165
|
+
(staging / DIST_CONFIG_ASSET).write_text(
|
|
166
|
+
json.dumps(managed_config, indent=2, sort_keys=True) + "\n", encoding="utf-8"
|
|
167
|
+
)
|
|
168
|
+
validate_source(staging, require_provenance=False)
|
|
169
|
+
if dist.is_symlink() or (dist.exists() and not dist.is_dir()):
|
|
170
|
+
dist.unlink()
|
|
171
|
+
elif dist.is_dir():
|
|
172
|
+
shutil.rmtree(dist)
|
|
173
|
+
os.replace(staging, dist)
|
|
174
|
+
finally:
|
|
175
|
+
shutil.rmtree(staging_parent, ignore_errors=True)
|
|
176
|
+
return dist
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def package(src, host, version, output_dir, require_provenance=True):
|
|
180
|
+
source_root, normalized_host, normalized_version = validate_inputs(
|
|
181
|
+
src, host, version, require_provenance=require_provenance
|
|
182
|
+
)
|
|
132
183
|
staging_parent, staging = copy_package_root(source_root)
|
|
133
184
|
try:
|
|
134
185
|
meta = write_meta(staging, normalized_version)
|
|
@@ -162,12 +213,18 @@ def package_managed(root):
|
|
|
162
213
|
if not isinstance(platform_config, dict) or not isinstance(version, dict):
|
|
163
214
|
raise WebPackageError("web managed config invalid")
|
|
164
215
|
try:
|
|
165
|
-
|
|
216
|
+
# Validate host/version/source before anything is written, so a bad host cannot
|
|
217
|
+
# leave a stale or partly-rendered dist on disk.
|
|
218
|
+
validate_inputs(app_root / "web" / "src", platform_config.get("host"), version.get("name"))
|
|
219
|
+
dist = build_dist(app_root, config)
|
|
220
|
+
result = package(dist, platform_config.get("host"), version.get("name"), app_root / "output", require_provenance=False)
|
|
166
221
|
except WebPackageError as exc:
|
|
167
222
|
message = str(exc)
|
|
168
223
|
if message.startswith("web.host:"):
|
|
169
|
-
raise WebPackageError(f"web.host (from
|
|
224
|
+
raise WebPackageError(f"web.host (from {CONFIG_FILENAME}):{message[len('web.host:'):]}") from exc
|
|
170
225
|
raise
|
|
226
|
+
result["dist"] = str(dist)
|
|
227
|
+
return result
|
|
171
228
|
|
|
172
229
|
|
|
173
230
|
def main(argv=None):
|
|
@@ -15,13 +15,13 @@ Options:
|
|
|
15
15
|
--plan Validate and print the build plan. Default when no mode is set.
|
|
16
16
|
--build Validate, inject managed config, then call platform build stubs.
|
|
17
17
|
--force Allow replacing unmanaged target files during injection.
|
|
18
|
-
--config PATH Config file. Default: ./supersdk.
|
|
18
|
+
--config PATH Config file. Default: ./supersdk.json.
|
|
19
19
|
--help Show this help.
|
|
20
20
|
EOF
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
platform="all"
|
|
24
|
-
config="$APP_ROOT/supersdk.
|
|
24
|
+
config="$APP_ROOT/supersdk.json"
|
|
25
25
|
mode="plan"
|
|
26
26
|
mode_set=false
|
|
27
27
|
platform_set=false
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 2,
|
|
3
|
+
"spid": "demo0001",
|
|
4
|
+
"name": "SuperSDK Simple",
|
|
5
|
+
"environment": "prod",
|
|
6
|
+
"android": {
|
|
7
|
+
"package": "com.supersdk.simple.host"
|
|
8
|
+
},
|
|
9
|
+
"ios": {
|
|
10
|
+
"bundleId": "com.supersdk.simple",
|
|
11
|
+
"spmMode": "mock"
|
|
12
|
+
},
|
|
13
|
+
"web": {
|
|
14
|
+
"host": "simple.supersdk.com"
|
|
15
|
+
},
|
|
16
|
+
"version": {
|
|
17
|
+
"name": "1.0.0",
|
|
18
|
+
"code": 1
|
|
19
|
+
},
|
|
20
|
+
"sdk": {
|
|
21
|
+
"androidVersion": "1.0.0.54-SNAPSHOT"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
(function() {
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Package-root relative on purpose: the file is emitted into web/dist by
|
|
5
|
+
// scripts/build_web.sh, so the same path resolves in the offline package, on a
|
|
6
|
+
// published site, and on the local dev server.
|
|
7
|
+
var CONFIG_PATH = "supersdk-config.json";
|
|
5
8
|
|
|
6
9
|
function text(id, value) {
|
|
7
10
|
var element = document.getElementById(id);
|
|
@@ -46,7 +49,7 @@
|
|
|
46
49
|
|
|
47
50
|
function loadConfig() {
|
|
48
51
|
if (!window.location || window.location.protocol === "file:") {
|
|
49
|
-
return Promise.reject(new Error("
|
|
52
|
+
return Promise.reject(new Error("Run scripts/build_web.sh then serve web/dist over the local HTTP server"));
|
|
50
53
|
}
|
|
51
54
|
var url = new URL(CONFIG_PATH, window.location.href).toString();
|
|
52
55
|
return fetch(url).then(function(response) {
|
package/dist/util/prompt.js
CHANGED
|
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.promptLineSync = promptLineSync;
|
|
37
|
+
exports.isInteractiveStdin = isInteractiveStdin;
|
|
38
|
+
exports.promptLineWithDefaultSync = promptLineWithDefaultSync;
|
|
37
39
|
exports.promptHiddenSync = promptHiddenSync;
|
|
38
40
|
// Synchronous terminal prompts. Kept synchronous (blocking read on fd 0)
|
|
39
41
|
// deliberately: CredentialBackend.get/set are synchronous (store/credentialStore.ts),
|
|
@@ -87,6 +89,27 @@ function promptLineSync(question) {
|
|
|
87
89
|
}
|
|
88
90
|
return result;
|
|
89
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* stdin 是否连着真人终端。
|
|
94
|
+
*
|
|
95
|
+
* 🔴 非 TTY(CI、`| tee`、agent 里跑、任何被脚本调用的场景)下,调用方必须 fail-closed:
|
|
96
|
+
* 没有人可问的时候,"拿默认值继续"等于替真人做了他没做的决定 —— 生成一个带着 SuperSDK
|
|
97
|
+
* 自己包名的工程,比直接报错难查得多。
|
|
98
|
+
*/
|
|
99
|
+
function isInteractiveStdin() {
|
|
100
|
+
return Boolean(process.stdin.isTTY);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 带默认值的可见行输入:直接回车取默认值;没有默认值时回车返回空串,由调用方决定
|
|
104
|
+
* 是重问还是失败。返回值已 trim。
|
|
105
|
+
*/
|
|
106
|
+
function promptLineWithDefaultSync(question, defaultValue) {
|
|
107
|
+
const suffix = defaultValue === undefined || defaultValue === '' ? '' : ` [${defaultValue}]`;
|
|
108
|
+
const answer = promptLineSync(`${question}${suffix}: `).trim();
|
|
109
|
+
if (answer === '' && defaultValue !== undefined)
|
|
110
|
+
return defaultValue;
|
|
111
|
+
return answer;
|
|
112
|
+
}
|
|
90
113
|
/** Masked input where the terminal supports raw mode; falls back to visible input otherwise (piped stdin, CI). */
|
|
91
114
|
function promptHiddenSync(question) {
|
|
92
115
|
const stdin = process.stdin;
|