@supersdk/supercli 0.1.2 → 0.2.0-staging.13
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/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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// supersdk.json 的 **单一信源**:文件名、schemaVersion、退役文件集、键序、写盘纪律。
|
|
3
|
+
//
|
|
4
|
+
// 🔴 为什么必须只有一份:create-app 侧(src/createApp/copyTemplate.ts)与 publish-site 侧
|
|
5
|
+
// (src/publish/siteConfig.ts)都要读写同一个文件。两边各写一份常量时,「今天碰巧一致」
|
|
6
|
+
// 不构成任何保证 —— 一旦哪边先改了键序或 schemaVersion,另一边就会把同一份文档写成
|
|
7
|
+
// 另一种字节形态,git diff 里出现整文件重排,甚至一边认为合法另一边 fail-closed。
|
|
8
|
+
//
|
|
9
|
+
// 权威规则本身在 Python 侧(supersimples/app_repo_example/scripts/supersdk_template.py):
|
|
10
|
+
// CONFIG_FILENAME / CONFIG_SCHEMA_VERSION / LEGACY_CONFIG_FILENAMES / RETIRED_ROOT_KEYS /
|
|
11
|
+
// reject_duplicate_keys。本模块是它在 TypeScript 侧的镜像,改动一律以 Python 为准。
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.APP_CONFIG_SKELETON = exports.RETIRED_ROOT_KEYS = exports.NESTED_KEY_ORDER = exports.ROOT_KEY_ORDER = exports.LEGACY_APP_CONFIG_FILENAMES = exports.APP_CONFIG_SCHEMA_VERSION = exports.APP_CONFIG_FILENAME = void 0;
|
|
14
|
+
exports.hasOwn = hasOwn;
|
|
15
|
+
exports.orderRootKeys = orderRootKeys;
|
|
16
|
+
exports.serializeAppConfig = serializeAppConfig;
|
|
17
|
+
exports.findDuplicateKey = findDuplicateKey;
|
|
18
|
+
exports.appConfigSkeleton = appConfigSkeleton;
|
|
19
|
+
exports.APP_CONFIG_FILENAME = 'supersdk.json';
|
|
20
|
+
exports.APP_CONFIG_SCHEMA_VERSION = 2;
|
|
21
|
+
/**
|
|
22
|
+
* 已退役的配置文件名,与 supersdk_template.py 的 LEGACY_CONFIG_FILENAMES **逐字一致**。
|
|
23
|
+
* 三端(Python / create-app / publish-site)必须认同一套:任何一端漏认一个文件名,就会
|
|
24
|
+
* 出现「这一端生成/发布成功、另一端立刻 fail-closed」的撕裂。
|
|
25
|
+
*
|
|
26
|
+
* - supersdk.yaml / supersdk.yml:schema_version: 1 的受限 YAML 方言,位于仓库根
|
|
27
|
+
* - super-site.yml:手写行解析器时代的站点绑定,位于发布目录内
|
|
28
|
+
*/
|
|
29
|
+
exports.LEGACY_APP_CONFIG_FILENAMES = ['supersdk.yaml', 'supersdk.yml', 'super-site.yml'];
|
|
30
|
+
/** 固定根键序。未知键按原有相对顺序追加在末尾(未知键必须原样保留,见 orderRootKeys)。 */
|
|
31
|
+
exports.ROOT_KEY_ORDER = [
|
|
32
|
+
'schemaVersion',
|
|
33
|
+
'spid',
|
|
34
|
+
'orgId',
|
|
35
|
+
'name',
|
|
36
|
+
'environment',
|
|
37
|
+
'android',
|
|
38
|
+
'ios',
|
|
39
|
+
'web',
|
|
40
|
+
'version',
|
|
41
|
+
'sdk',
|
|
42
|
+
'sites',
|
|
43
|
+
];
|
|
44
|
+
/** 各命名空间内部的固定键序,镜像 supersdk_template.py 的 NAMESPACE_KEYS / SDK_KEYS。 */
|
|
45
|
+
exports.NESTED_KEY_ORDER = {
|
|
46
|
+
android: ['package'],
|
|
47
|
+
ios: ['bundleId', 'spmMode'],
|
|
48
|
+
web: ['host'],
|
|
49
|
+
version: ['name', 'code'],
|
|
50
|
+
sdk: ['androidVersion', 'iosPackageUrl', 'iosVersion'],
|
|
51
|
+
};
|
|
52
|
+
/** 镜像 supersdk_template.py 的 RETIRED_ROOT_KEYS:给定向诊断,而不是当作「未知键」带过去。 */
|
|
53
|
+
exports.RETIRED_ROOT_KEYS = {
|
|
54
|
+
schema_version: `is a retired schema v1 key; use camelCase "schemaVersion": ${exports.APP_CONFIG_SCHEMA_VERSION}`,
|
|
55
|
+
app_id: 'is a retired key; rename it to "spid"',
|
|
56
|
+
};
|
|
57
|
+
function hasOwn(value, key) {
|
|
58
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 只按 order 排根键,未知键原序追加。
|
|
62
|
+
*
|
|
63
|
+
* 累加器用 `Object.create(null)`:`JSON.parse('{"__proto__":1}')` 会产生一个**自有**
|
|
64
|
+
* `__proto__` 属性,写进普通 `{}` 会走 [[Set]] 触发原型 setter 而被静默丢弃 —— 那就违反了
|
|
65
|
+
* 「未知键必须原样保留」。
|
|
66
|
+
*/
|
|
67
|
+
function orderRootKeys(document, order = exports.ROOT_KEY_ORDER) {
|
|
68
|
+
const ordered = Object.create(null);
|
|
69
|
+
for (const key of order) {
|
|
70
|
+
if (hasOwn(document, key))
|
|
71
|
+
ordered[key] = document[key];
|
|
72
|
+
}
|
|
73
|
+
for (const key of Object.keys(document)) {
|
|
74
|
+
if (!order.includes(key))
|
|
75
|
+
ordered[key] = document[key];
|
|
76
|
+
}
|
|
77
|
+
return ordered;
|
|
78
|
+
}
|
|
79
|
+
function isPlainObject(value) {
|
|
80
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 固定键序(根 + 命名空间内部)、2 空格缩进、结尾换行 —— 让 git diff 里只出现真实变更。
|
|
84
|
+
*
|
|
85
|
+
* `NESTED_KEY_ORDER` 必须用 hasOwnProperty 取:裸 `NESTED_KEY_ORDER[key]` 在根键叫
|
|
86
|
+
* `constructor` / `toString` 时会取到 Object.prototype 上的函数,随后 `for (const k of order)`
|
|
87
|
+
* 直接抛 `TypeError: order is not iterable`。
|
|
88
|
+
*/
|
|
89
|
+
function serializeAppConfig(document) {
|
|
90
|
+
const ordered = orderRootKeys(document);
|
|
91
|
+
const out = Object.create(null);
|
|
92
|
+
for (const key of Object.keys(ordered)) {
|
|
93
|
+
const value = ordered[key];
|
|
94
|
+
if (hasOwn(exports.NESTED_KEY_ORDER, key) && isPlainObject(value)) {
|
|
95
|
+
out[key] = orderRootKeys(value, exports.NESTED_KEY_ORDER[key]);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
out[key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return `${JSON.stringify(out, null, 2)}\n`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 在**已经通过 JSON.parse 的文本**上扫描重复键,返回第一个重复的键名。
|
|
105
|
+
*
|
|
106
|
+
* 🔴 权威侧 supersdk_template.py 用 `object_pairs_hook=reject_duplicate_keys` 对重复键硬失败。
|
|
107
|
+
* `JSON.parse` 则静默取最后一个 —— 若两边不一致,CLI 会把一份 Python 认定非法的文件「洗」成
|
|
108
|
+
* 合法文件并丢掉数据。这里只做检测,不做解析,所以可以假定输入是合法 JSON。
|
|
109
|
+
*/
|
|
110
|
+
function findDuplicateKey(raw) {
|
|
111
|
+
const stack = [];
|
|
112
|
+
let i = 0;
|
|
113
|
+
while (i < raw.length) {
|
|
114
|
+
const ch = raw[i];
|
|
115
|
+
if (ch === '"') {
|
|
116
|
+
const start = i;
|
|
117
|
+
i += 1;
|
|
118
|
+
while (i < raw.length) {
|
|
119
|
+
if (raw[i] === '\\') {
|
|
120
|
+
i += 2;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (raw[i] === '"') {
|
|
124
|
+
i += 1;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
i += 1;
|
|
128
|
+
}
|
|
129
|
+
const top = stack[stack.length - 1];
|
|
130
|
+
if (top && top.expectKey) {
|
|
131
|
+
let key;
|
|
132
|
+
try {
|
|
133
|
+
// 用 JSON.parse 还原转义,"a" 与 "a" 对 JSON.parse 是同一个键。
|
|
134
|
+
key = JSON.parse(raw.slice(start, i));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
if (top.keys.has(key))
|
|
140
|
+
return key;
|
|
141
|
+
top.keys.add(key);
|
|
142
|
+
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (ch === '{') {
|
|
146
|
+
stack.push({ keys: new Set(), expectKey: true });
|
|
147
|
+
}
|
|
148
|
+
else if (ch === '[') {
|
|
149
|
+
stack.push(null);
|
|
150
|
+
}
|
|
151
|
+
else if (ch === '}' || ch === ']') {
|
|
152
|
+
stack.pop();
|
|
153
|
+
}
|
|
154
|
+
else if (ch === ',') {
|
|
155
|
+
const top = stack[stack.length - 1];
|
|
156
|
+
if (top)
|
|
157
|
+
top.expectKey = true;
|
|
158
|
+
}
|
|
159
|
+
else if (ch === ':') {
|
|
160
|
+
const top = stack[stack.length - 1];
|
|
161
|
+
if (top)
|
|
162
|
+
top.expectKey = false;
|
|
163
|
+
}
|
|
164
|
+
i += 1;
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 可照抄落盘的完整骨架。**每个必填字段都在**(name/environment/android/ios/web/version/sdk):
|
|
170
|
+
* 少一个字段的迁移提示对照抄的人就是死路 —— 本仓刚因为同类问题修过一次。
|
|
171
|
+
* 与 supersdk_template.py 的 MIGRATION_TEMPLATE 字段集一致。
|
|
172
|
+
*/
|
|
173
|
+
function appConfigSkeleton(spid = 'a1b2c3d4') {
|
|
174
|
+
return `{
|
|
175
|
+
"schemaVersion": ${exports.APP_CONFIG_SCHEMA_VERSION},
|
|
176
|
+
"spid": ${JSON.stringify(spid)},
|
|
177
|
+
"name": "My App",
|
|
178
|
+
"environment": "prod",
|
|
179
|
+
"android": { "package": "com.acme.myapp" },
|
|
180
|
+
"ios": { "bundleId": "com.acme.myapp", "spmMode": "mock" },
|
|
181
|
+
"web": { "host": "myapp.example.com" },
|
|
182
|
+
"version": { "name": "1.0.0", "code": 1 },
|
|
183
|
+
"sdk": { "androidVersion": "1.0.0.54-SNAPSHOT" }
|
|
184
|
+
}`;
|
|
185
|
+
}
|
|
186
|
+
exports.APP_CONFIG_SKELETON = appConfigSkeleton();
|
|
187
|
+
//# sourceMappingURL=appConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appConfig.js","sourceRoot":"","sources":["../../src/config/appConfig.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,0DAA0D;AAC1D,oDAAoD;AACpD,qDAAqD;AACrD,EAAE;AACF,gFAAgF;AAChF,0FAA0F;AAC1F,gEAAgE;;;AAgDhE,wBAE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SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACpC,KAAK,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACtB,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACpC,IAAI,GAAG;gBAAE,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;QAChC,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACtB,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACpC,IAAI,GAAG;gBAAE,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;QACjC,CAAC;QACD,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAI,GAAG,UAAU;IACjD,OAAO;qBACY,iCAAyB;YAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;;;;;;EAQ9B,CAAC;AACH,CAAC;AAEY,QAAA,mBAAmB,GAAG,iBAAiB,EAAE,CAAC"}
|
|
@@ -33,28 +33,185 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.PLATFORM_DIRS = exports.IGNORE_SUFFIXES = exports.IGNORE_NAMES = exports.SPID_PATTERN_SOURCE = void 0;
|
|
36
|
+
exports.stringifyAppConfig = exports.PLATFORM_DIRS = exports.IGNORE_SUFFIXES = exports.IGNORE_NAMES = exports.WEB_HOST_DIAGNOSTIC = exports.TEMPLATE_DEFAULTS = exports.ANDROID_NAMESPACE = exports.IOS_BUNDLE_ID_PATTERN_SOURCE = exports.ANDROID_PACKAGE_PATTERN_SOURCE = exports.ENVIRONMENT_PATTERN_SOURCE = exports.SPID_PATTERN_SOURCE = exports.LEGACY_APP_CONFIG_FILENAMES = exports.APP_CONFIG_SKELETON = exports.APP_CONFIG_SCHEMA_VERSION = exports.APP_CONFIG_FILENAME = void 0;
|
|
37
37
|
exports.isValidSpid = isValidSpid;
|
|
38
|
+
exports.checkSpid = checkSpid;
|
|
39
|
+
exports.checkEnvironment = checkEnvironment;
|
|
40
|
+
exports.checkAppName = checkAppName;
|
|
41
|
+
exports.checkAndroidPackage = checkAndroidPackage;
|
|
42
|
+
exports.checkIosBundleId = checkIosBundleId;
|
|
43
|
+
exports.normalizeWebHost = normalizeWebHost;
|
|
44
|
+
exports.checkWebHost = checkWebHost;
|
|
38
45
|
exports.isValidPlatform = isValidPlatform;
|
|
46
|
+
exports.selectedPlatforms = selectedPlatforms;
|
|
39
47
|
exports.locateDefaultTemplateRoot = locateDefaultTemplateRoot;
|
|
40
48
|
exports.copyTemplateInto = copyTemplateInto;
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
43
|
-
|
|
44
|
-
//
|
|
49
|
+
exports.legacyYamlMigrationMessage = legacyYamlMigrationMessage;
|
|
50
|
+
exports.parseAppConfig = parseAppConfig;
|
|
51
|
+
exports.applyAppIdentity = applyAppIdentity;
|
|
52
|
+
// BL-005/BL-008 create-app: template discovery + `supersdk.json` identity injection.
|
|
45
53
|
//
|
|
46
|
-
// The copy step is intentionally a plain byte-for-byte file copy (no
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
54
|
+
// The copy step is intentionally a plain byte-for-byte file copy (no templating
|
|
55
|
+
// engine). The ONLY content edit is the generated project's root
|
|
56
|
+
// `supersdk.json`, and that edit is a real `JSON.parse -> mutate -> stringify`
|
|
57
|
+
// round-trip (never a regex over the file text):
|
|
58
|
+
//
|
|
59
|
+
// * every unknown key is preserved — a human may add fields the CLI does not
|
|
60
|
+
// know about, and a machine write must not erase them;
|
|
61
|
+
// * output uses a fixed key order, 2-space indentation and a trailing newline,
|
|
62
|
+
// so `git diff` shows only real changes — the order, the schemaVersion and the
|
|
63
|
+
// retired-file set all come from src/config/appConfig.ts, the single copy the
|
|
64
|
+
// publish-site side reads too;
|
|
65
|
+
// * `orgId` / `sites` are owned by supercli's publish-site side. create-app
|
|
66
|
+
// never writes them, only carries them through untouched.
|
|
67
|
+
//
|
|
68
|
+
// There is NO compatibility path for the retired YAML dialects (schema_version:
|
|
69
|
+
// 1). Meeting one is a hard failure with a copy-pasteable migration snippet.
|
|
51
70
|
const fs = __importStar(require("node:fs"));
|
|
52
71
|
const path = __importStar(require("node:path"));
|
|
72
|
+
const appConfig_1 = require("../config/appConfig");
|
|
73
|
+
Object.defineProperty(exports, "APP_CONFIG_FILENAME", { enumerable: true, get: function () { return appConfig_1.APP_CONFIG_FILENAME; } });
|
|
74
|
+
Object.defineProperty(exports, "APP_CONFIG_SCHEMA_VERSION", { enumerable: true, get: function () { return appConfig_1.APP_CONFIG_SCHEMA_VERSION; } });
|
|
75
|
+
Object.defineProperty(exports, "APP_CONFIG_SKELETON", { enumerable: true, get: function () { return appConfig_1.APP_CONFIG_SKELETON; } });
|
|
76
|
+
Object.defineProperty(exports, "LEGACY_APP_CONFIG_FILENAMES", { enumerable: true, get: function () { return appConfig_1.LEGACY_APP_CONFIG_FILENAMES; } });
|
|
77
|
+
const shell_1 = require("../util/shell");
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Local validation, mirrored from the authoritative Python implementation.
|
|
80
|
+
//
|
|
81
|
+
// 🔴 权威在 Python 侧,不在这里:
|
|
82
|
+
// supersimples/app_repo_example/scripts/supersdk_template.py
|
|
83
|
+
// - SPID_PATTERN / ENVIRONMENT_PATTERN / BUNDLE_ID_PATTERN
|
|
84
|
+
// - ANDROID_NAMESPACE + require_android_config()(Java 包名、label 规则)
|
|
85
|
+
// supersimples/app_repo_example/scripts/web_host_validator.py
|
|
86
|
+
// - normalize_host()(web.host 归一化与拒绝规则)
|
|
87
|
+
// 下面这些函数只是把「build 期才会炸的错误」提前到 create 期暴露的镜像实现。
|
|
88
|
+
// Python 侧规则一旦改动,必须以 Python 为准同步到这里;两边不一致时以 Python 为准。
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
53
90
|
exports.SPID_PATTERN_SOURCE = '[a-z0-9]{8}';
|
|
91
|
+
exports.ENVIRONMENT_PATTERN_SOURCE = '[a-z0-9]{1,10}';
|
|
92
|
+
exports.ANDROID_PACKAGE_PATTERN_SOURCE = '[A-Za-z][A-Za-z0-9_]*(\\.[A-Za-z][A-Za-z0-9_]*)+';
|
|
93
|
+
exports.IOS_BUNDLE_ID_PATTERN_SOURCE = '[A-Za-z0-9][A-Za-z0-9-]*(\\.[A-Za-z0-9][A-Za-z0-9-]*)+';
|
|
94
|
+
/** Fixed Gradle namespace baked into the template's android module (ANDROID_NAMESPACE in supersdk_template.py). */
|
|
95
|
+
exports.ANDROID_NAMESPACE = 'com.supersdk.simple';
|
|
96
|
+
/**
|
|
97
|
+
* The template's own SuperSDK identity. create-app must never let any of these
|
|
98
|
+
* survive into a generated project — a repo carrying them cannot be shipped.
|
|
99
|
+
* Listed here so failure messages can name them explicitly.
|
|
100
|
+
*/
|
|
101
|
+
exports.TEMPLATE_DEFAULTS = {
|
|
102
|
+
name: 'SuperSDK Simple',
|
|
103
|
+
androidPackage: 'com.supersdk.simple.host',
|
|
104
|
+
iosBundleId: 'com.supersdk.simple',
|
|
105
|
+
webHost: 'simple.supersdk.com',
|
|
106
|
+
};
|
|
54
107
|
const SPID_PATTERN = new RegExp(`^${exports.SPID_PATTERN_SOURCE}$`);
|
|
108
|
+
const ENVIRONMENT_PATTERN = new RegExp(`^${exports.ENVIRONMENT_PATTERN_SOURCE}$`);
|
|
109
|
+
const ANDROID_PACKAGE_PATTERN = new RegExp(`^${exports.ANDROID_PACKAGE_PATTERN_SOURCE}$`);
|
|
110
|
+
const IOS_BUNDLE_ID_PATTERN = new RegExp(`^${exports.IOS_BUNDLE_ID_PATTERN_SOURCE}$`);
|
|
55
111
|
function isValidSpid(spid) {
|
|
56
112
|
return SPID_PATTERN.test(spid);
|
|
57
113
|
}
|
|
114
|
+
/** Validators return `undefined` when the value is acceptable, otherwise a human-readable reason. */
|
|
115
|
+
function checkSpid(value) {
|
|
116
|
+
return isValidSpid(value) ? undefined : `must match ^${exports.SPID_PATTERN_SOURCE}$ (8 lowercase letters or digits, issued by Console)`;
|
|
117
|
+
}
|
|
118
|
+
function checkEnvironment(value) {
|
|
119
|
+
return ENVIRONMENT_PATTERN.test(value) ? undefined : `must match ^${exports.ENVIRONMENT_PATTERN_SOURCE}$ (e.g. prod, staging)`;
|
|
120
|
+
}
|
|
121
|
+
/** Android app label rules from require_android_config(): non-empty, no control chars, no surrounding whitespace. */
|
|
122
|
+
function checkAppName(value) {
|
|
123
|
+
if (value.trim() === '')
|
|
124
|
+
return 'must not be empty';
|
|
125
|
+
if (value !== value.trim())
|
|
126
|
+
return 'must not have leading or trailing whitespace';
|
|
127
|
+
for (const char of value) {
|
|
128
|
+
// Python authority uses `ord(char) < 32`; deliberately identical, no extra rules.
|
|
129
|
+
if ((char.codePointAt(0) ?? 0) < 32)
|
|
130
|
+
return 'must not contain control characters';
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
function checkAndroidPackage(value) {
|
|
135
|
+
if (!ANDROID_PACKAGE_PATTERN.test(value)) {
|
|
136
|
+
return `must be a Java package matching ^${exports.ANDROID_PACKAGE_PATTERN_SOURCE}$ (e.g. com.acme.myapp)`;
|
|
137
|
+
}
|
|
138
|
+
if (value === exports.ANDROID_NAMESPACE) {
|
|
139
|
+
return `must differ from the template's fixed Gradle namespace ${exports.ANDROID_NAMESPACE}`;
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
function checkIosBundleId(value) {
|
|
144
|
+
return IOS_BUNDLE_ID_PATTERN.test(value)
|
|
145
|
+
? undefined
|
|
146
|
+
: `must be a bundle identifier matching ^${exports.IOS_BUNDLE_ID_PATTERN_SOURCE}$ (e.g. com.acme.myapp)`;
|
|
147
|
+
}
|
|
148
|
+
/** Mirrors HOST_DIAGNOSTIC in web_host_validator.py so both sides say the same thing. */
|
|
149
|
+
exports.WEB_HOST_DIAGNOSTIC = 'must be a deployable bare domain; localhost, IP literals, single-label hosts, whitespace, ' +
|
|
150
|
+
'trailing dots, numeric TLDs, and non-ASCII/IDN input are not supported';
|
|
151
|
+
function isIpLiteral(value) {
|
|
152
|
+
if (value.includes(':'))
|
|
153
|
+
return true; // IPv6-ish
|
|
154
|
+
const parts = value.split('.');
|
|
155
|
+
if (parts.length !== 4)
|
|
156
|
+
return false;
|
|
157
|
+
return parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Port of normalize_host() (web_host_validator.py): accepts a bare host or an
|
|
161
|
+
* http(s) URL and returns the lowercased bare host, or an error reason.
|
|
162
|
+
*/
|
|
163
|
+
function normalizeWebHost(raw) {
|
|
164
|
+
const failure = { error: exports.WEB_HOST_DIAGNOSTIC };
|
|
165
|
+
if (raw === '' || raw !== raw.trim() || /\s/.test(raw))
|
|
166
|
+
return failure;
|
|
167
|
+
// eslint-disable-next-line no-control-regex
|
|
168
|
+
if (/[^\x00-\x7f]/.test(raw))
|
|
169
|
+
return failure; // non-ASCII / IDN
|
|
170
|
+
let host;
|
|
171
|
+
if (raw.includes('://')) {
|
|
172
|
+
let parsed;
|
|
173
|
+
try {
|
|
174
|
+
parsed = new URL(raw);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return failure;
|
|
178
|
+
}
|
|
179
|
+
const scheme = parsed.protocol.replace(/:$/, '').toLowerCase();
|
|
180
|
+
if (scheme !== 'http' && scheme !== 'https')
|
|
181
|
+
return failure;
|
|
182
|
+
if (!parsed.hostname || parsed.hostname.startsWith('['))
|
|
183
|
+
return failure;
|
|
184
|
+
host = parsed.hostname.toLowerCase();
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
if (raw.includes(':'))
|
|
188
|
+
return failure;
|
|
189
|
+
host = raw.toLowerCase();
|
|
190
|
+
}
|
|
191
|
+
if (!host || host === 'localhost' || isIpLiteral(host))
|
|
192
|
+
return failure;
|
|
193
|
+
if (host.startsWith('.') || host.endsWith('.') || host.includes('..'))
|
|
194
|
+
return failure;
|
|
195
|
+
if (host.length > 253)
|
|
196
|
+
return failure;
|
|
197
|
+
const labels = host.split('.');
|
|
198
|
+
if (labels.length < 2)
|
|
199
|
+
return failure;
|
|
200
|
+
const labelPattern = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
201
|
+
for (const label of labels) {
|
|
202
|
+
if (label.length < 1 || label.length > 63 || !labelPattern.test(label))
|
|
203
|
+
return failure;
|
|
204
|
+
}
|
|
205
|
+
if (/^\d+$/.test(labels[labels.length - 1]))
|
|
206
|
+
return failure;
|
|
207
|
+
if (labels.length === 4 && labels.every((label) => /^\d+$/.test(label)))
|
|
208
|
+
return failure;
|
|
209
|
+
return { host };
|
|
210
|
+
}
|
|
211
|
+
function checkWebHost(value) {
|
|
212
|
+
const result = normalizeWebHost(value);
|
|
213
|
+
return 'error' in result ? result.error : undefined;
|
|
214
|
+
}
|
|
58
215
|
/**
|
|
59
216
|
* Directory/file names excluded at every depth of the copy — mirrors
|
|
60
217
|
* `ignore_generated` in supersimples/tests/e2e/build_orchestration_smoke.py
|
|
@@ -80,6 +237,16 @@ exports.PLATFORM_DIRS = ['android', 'ios', 'web'];
|
|
|
80
237
|
function isValidPlatform(value) {
|
|
81
238
|
return value === 'all' || exports.PLATFORM_DIRS.includes(value);
|
|
82
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* 本次 create-app 的平台 scope,镜像 supersdk_template.py 的 `selected_platforms()`。
|
|
242
|
+
*
|
|
243
|
+
* 🔴 create 期的必填项必须跟 build 期的 scope 一致:`enforce_platform_contracts()` 只对
|
|
244
|
+
* selected 里的平台跑 require_*_config,所以 `--platform web` 的工程既不该被逼着编一个
|
|
245
|
+
* 假 Java 包名,也不该在 web 进了 scope 时把 web.host 留空 —— 后者下一步 build 就炸。
|
|
246
|
+
*/
|
|
247
|
+
function selectedPlatforms(platform) {
|
|
248
|
+
return platform === 'all' ? [...exports.PLATFORM_DIRS] : [platform];
|
|
249
|
+
}
|
|
83
250
|
/**
|
|
84
251
|
* Locates the create-app template root. Two supported layouts, checked in order:
|
|
85
252
|
*
|
|
@@ -150,7 +317,7 @@ function copyDirRecursive(src, dest) {
|
|
|
150
317
|
* empty build/temp directory), applying the exclude set at every depth and,
|
|
151
318
|
* for platform !== 'all', keeping only the selected platform directory among
|
|
152
319
|
* android/ios/web while always keeping everything else at the template root
|
|
153
|
-
* (the shared root: supersdk.
|
|
320
|
+
* (the shared root: supersdk.json, super_build.sh, README.md, .gitignore,
|
|
154
321
|
* scripts/, ...) — AC-C2/AC-C4.
|
|
155
322
|
*/
|
|
156
323
|
function copyTemplateInto(templateRoot, destDir, platform) {
|
|
@@ -182,41 +349,166 @@ function copyTemplateInto(templateRoot, destDir, platform) {
|
|
|
182
349
|
}
|
|
183
350
|
return { fileCount, platforms };
|
|
184
351
|
}
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// supersdk.json (schemaVersion 2) read / modify / write
|
|
354
|
+
// ---------------------------------------------------------------------------
|
|
355
|
+
function isPlainObject(value) {
|
|
356
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
357
|
+
}
|
|
358
|
+
/** Serializes with the canonical key order, 2-space indent and a trailing newline. */
|
|
359
|
+
exports.stringifyAppConfig = appConfig_1.serializeAppConfig;
|
|
185
360
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
361
|
+
* Fail-closed diagnostic for a retired YAML config. The snippet is meant to be
|
|
362
|
+
* pasted into a shell verbatim — a migration hint that is missing even one
|
|
363
|
+
* required field is a dead end, so the skeleton carries the complete set.
|
|
364
|
+
*
|
|
365
|
+
* 两种情形,动作顺序不同(且不能反):
|
|
366
|
+
* - 目录里**已经有一份合法的 supersdk.json** → 没有任何字段需要搬运,只发 `rm <legacy>`。
|
|
367
|
+
* 再让人照抄一遍 `cat >` 会用占位值覆盖掉他已经写好的真配置。
|
|
368
|
+
* - 没有 → 先写新文件、**再**删旧文件:旧文件是字段的唯一来源,先删就没得抄了。
|
|
190
369
|
*/
|
|
191
|
-
function
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
370
|
+
function legacyYamlMigrationMessage(yamlPath, jsonAlreadyValid = false) {
|
|
371
|
+
const legacyName = path.basename(yamlPath);
|
|
372
|
+
const dir = path.dirname(yamlPath);
|
|
373
|
+
const head = [
|
|
374
|
+
`${legacyName} (retired schema_version: 1 dialect) is no longer supported — supercli reads ` +
|
|
375
|
+
`${appConfig_1.APP_CONFIG_FILENAME} (schemaVersion ${appConfig_1.APP_CONFIG_SCHEMA_VERSION}) only, and there is no compatibility fallback.`,
|
|
376
|
+
`found: ${yamlPath}`,
|
|
377
|
+
'',
|
|
378
|
+
];
|
|
379
|
+
if (jsonAlreadyValid) {
|
|
380
|
+
return [
|
|
381
|
+
...head,
|
|
382
|
+
`your ${appConfig_1.APP_CONFIG_FILENAME} is already in place at ${path.join(dir, appConfig_1.APP_CONFIG_FILENAME)} — nothing to migrate, ` +
|
|
383
|
+
'just delete the retired file:',
|
|
384
|
+
'',
|
|
385
|
+
`cd ${(0, shell_1.shellQuote)(dir)}`,
|
|
386
|
+
`rm ${(0, shell_1.shellQuote)(legacyName)}`,
|
|
387
|
+
].join('\n');
|
|
388
|
+
}
|
|
389
|
+
return [
|
|
390
|
+
...head,
|
|
391
|
+
'Migrate it once — replace the placeholder values with the ones already in your YAML, then run:',
|
|
392
|
+
'',
|
|
393
|
+
`cd ${(0, shell_1.shellQuote)(dir)}`,
|
|
394
|
+
`cat > ${(0, shell_1.shellQuote)(appConfig_1.APP_CONFIG_FILENAME)} <<'SUPERSDK_JSON'`,
|
|
395
|
+
appConfig_1.APP_CONFIG_SKELETON,
|
|
396
|
+
'SUPERSDK_JSON',
|
|
397
|
+
`rm ${(0, shell_1.shellQuote)(legacyName)}`,
|
|
398
|
+
].join('\n');
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Strict schemaVersion-2 parse. Unknown keys are kept (they belong to whoever
|
|
402
|
+
* wrote them), but a wrong/absent schemaVersion, a non-object document, or a
|
|
403
|
+
* malformed `orgId`/`sites` fails closed rather than being "fixed up".
|
|
404
|
+
*/
|
|
405
|
+
function parseAppConfig(raw, sourceLabel) {
|
|
406
|
+
let parsed;
|
|
407
|
+
try {
|
|
408
|
+
parsed = JSON.parse(raw);
|
|
409
|
+
}
|
|
410
|
+
catch (err) {
|
|
411
|
+
throw new Error(`${sourceLabel} is not valid JSON: ${err.message}`);
|
|
412
|
+
}
|
|
413
|
+
// 🔴 JSON.parse 对重复键静默取最后一个,权威侧 reject_duplicate_keys() 是硬失败。
|
|
414
|
+
// 不在这里拦,CLI 就会把一份 Python 认定非法的文件重写成合法文件并丢掉数据。
|
|
415
|
+
const duplicate = (0, appConfig_1.findDuplicateKey)(raw);
|
|
416
|
+
if (duplicate !== undefined) {
|
|
417
|
+
throw new Error(`${sourceLabel}: "${duplicate}": duplicate key — a JSON object must not repeat a key. ` +
|
|
418
|
+
'Keep exactly one of them (the build-time parser rejects the file outright; ' +
|
|
419
|
+
'silently keeping the last one would drop data).');
|
|
420
|
+
}
|
|
421
|
+
if (!isPlainObject(parsed)) {
|
|
422
|
+
throw new Error(`${sourceLabel} must contain a JSON object at the top level`);
|
|
423
|
+
}
|
|
424
|
+
// Retired root keys get a targeted diagnostic instead of being carried through
|
|
425
|
+
// as "unknown keys" (RETIRED_ROOT_KEYS in supersdk_template.py).
|
|
426
|
+
for (const [key, reason] of Object.entries(appConfig_1.RETIRED_ROOT_KEYS)) {
|
|
427
|
+
if ((0, appConfig_1.hasOwn)(parsed, key))
|
|
428
|
+
throw new Error(`${sourceLabel}: "${key}" ${reason}`);
|
|
429
|
+
}
|
|
430
|
+
if (parsed.schemaVersion !== appConfig_1.APP_CONFIG_SCHEMA_VERSION) {
|
|
431
|
+
throw new Error(`${sourceLabel} has schemaVersion ${JSON.stringify(parsed.schemaVersion)}; supercli only reads ` +
|
|
432
|
+
`schemaVersion ${appConfig_1.APP_CONFIG_SCHEMA_VERSION}.\n\nExpected shape:\n\n${appConfig_1.APP_CONFIG_SKELETON}`);
|
|
433
|
+
}
|
|
434
|
+
// `orgId` and `sites` are owned by supercli's publish-site side. create-app
|
|
435
|
+
// only sanity-checks their shape and then carries them through untouched.
|
|
436
|
+
if ((0, appConfig_1.hasOwn)(parsed, 'orgId') && typeof parsed.orgId !== 'string') {
|
|
437
|
+
throw new Error(`${sourceLabel}: "orgId" must be a string`);
|
|
438
|
+
}
|
|
439
|
+
if ((0, appConfig_1.hasOwn)(parsed, 'sites') && !Array.isArray(parsed.sites)) {
|
|
440
|
+
throw new Error(`${sourceLabel}: "sites" must be an array`);
|
|
441
|
+
}
|
|
442
|
+
return parsed;
|
|
443
|
+
}
|
|
444
|
+
function sectionOf(config, key, sourceLabel) {
|
|
445
|
+
const current = (0, appConfig_1.hasOwn)(config, key) ? config[key] : undefined;
|
|
446
|
+
if (current === undefined || current === null) {
|
|
447
|
+
const created = {};
|
|
448
|
+
config[key] = created;
|
|
449
|
+
return created;
|
|
450
|
+
}
|
|
451
|
+
if (!isPlainObject(current)) {
|
|
452
|
+
throw new Error(`${sourceLabel}: "${key}" must be a JSON object`);
|
|
453
|
+
}
|
|
454
|
+
return current;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Sets `<section>.<key>` when the caller resolved a value, and otherwise DELETES
|
|
458
|
+
* it (dropping the section when nothing is left).
|
|
459
|
+
*
|
|
460
|
+
* 🔴 「没解析出值」永远不等于「沿用模板里的值」:模板自带 com.supersdk.simple.host /
|
|
461
|
+
* simple.supersdk.com,让它们混进生成工程等于交付一个发不出去的仓库。
|
|
462
|
+
*/
|
|
463
|
+
function setOrDrop(config, section, key, value, sourceLabel) {
|
|
464
|
+
if (value !== undefined) {
|
|
465
|
+
sectionOf(config, section, sourceLabel)[key] = value;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const current = (0, appConfig_1.hasOwn)(config, section) ? config[section] : undefined;
|
|
469
|
+
if (current === undefined || current === null)
|
|
470
|
+
return;
|
|
471
|
+
const bag = sectionOf(config, section, sourceLabel);
|
|
472
|
+
delete bag[key];
|
|
473
|
+
if (Object.keys(bag).length === 0)
|
|
474
|
+
delete config[section];
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Rewrites `<destDir>/supersdk.json` in place with the caller's identity.
|
|
478
|
+
* `sourceDirForMessages` is only used to make diagnostics point at the template
|
|
479
|
+
* the user can actually inspect, not at the internal temp build directory.
|
|
480
|
+
*/
|
|
481
|
+
function applyAppIdentity(destDir, identity, sourceDirForMessages = destDir) {
|
|
482
|
+
const configPath = path.join(destDir, appConfig_1.APP_CONFIG_FILENAME);
|
|
483
|
+
const sourceLabel = path.join(sourceDirForMessages, appConfig_1.APP_CONFIG_FILENAME);
|
|
484
|
+
// 退役文件集必须与权威侧 LEGACY_CONFIG_FILENAMES 逐字一致:只认 supersdk.yaml 就会
|
|
485
|
+
// 出现「create-app 生成成功、Python 侧同一棵树立刻 fail-closed」。
|
|
486
|
+
for (const legacyName of appConfig_1.LEGACY_APP_CONFIG_FILENAMES) {
|
|
487
|
+
const legacyPath = path.join(destDir, legacyName);
|
|
488
|
+
if (!fs.existsSync(legacyPath))
|
|
489
|
+
continue;
|
|
490
|
+
let jsonAlreadyValid = false;
|
|
491
|
+
try {
|
|
492
|
+
parseAppConfig(fs.readFileSync(configPath, 'utf8'), sourceLabel);
|
|
493
|
+
jsonAlreadyValid = true;
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
jsonAlreadyValid = false; // 缺失/非法 —— 迁移提示要带完整骨架
|
|
497
|
+
}
|
|
498
|
+
throw new Error(legacyYamlMigrationMessage(path.join(sourceDirForMessages, legacyName), jsonAlreadyValid));
|
|
499
|
+
}
|
|
500
|
+
if (!fs.existsSync(configPath)) {
|
|
501
|
+
throw new Error(`template is missing ${appConfig_1.APP_CONFIG_FILENAME} at "${sourceLabel}" — every SuperSDK project repo must carry a ` +
|
|
502
|
+
`schemaVersion ${appConfig_1.APP_CONFIG_SCHEMA_VERSION} ${appConfig_1.APP_CONFIG_FILENAME} at its root.\n\nExpected shape:\n\n${appConfig_1.APP_CONFIG_SKELETON}`);
|
|
503
|
+
}
|
|
504
|
+
const config = parseAppConfig(fs.readFileSync(configPath, 'utf8'), sourceLabel);
|
|
505
|
+
config.schemaVersion = appConfig_1.APP_CONFIG_SCHEMA_VERSION;
|
|
506
|
+
config.spid = identity.spid;
|
|
507
|
+
config.name = identity.name;
|
|
508
|
+
config.environment = identity.environment;
|
|
509
|
+
setOrDrop(config, 'android', 'package', identity.androidPackage, sourceLabel);
|
|
510
|
+
setOrDrop(config, 'ios', 'bundleId', identity.iosBundleId, sourceLabel);
|
|
511
|
+
setOrDrop(config, 'web', 'host', identity.webHost, sourceLabel);
|
|
512
|
+
fs.writeFileSync(configPath, (0, exports.stringifyAppConfig)(config), 'utf8');
|
|
221
513
|
}
|
|
222
514
|
//# sourceMappingURL=copyTemplate.js.map
|