@supersdk/supercli 0.3.2-staging.44 → 0.3.2
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/cli.js +11 -22
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +31 -79
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/analytics.js +9 -15
- package/dist/commands/analytics.js.map +1 -1
- package/dist/commands/db.js +19 -24
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.js +751 -434
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/env.js +8 -8
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/image.js +20 -31
- package/dist/commands/image.js.map +1 -1
- package/dist/commands/init.js +37 -68
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/logs.js +7 -16
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/publishSite.js +943 -28
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/commands/register.js +30 -51
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/settings.js +6 -10
- package/dist/commands/settings.js.map +1 -1
- package/dist/config/appConfig.js +36 -40
- package/dist/config/appConfig.js.map +1 -1
- package/dist/docker/dockerCli.js +1 -63
- package/dist/docker/dockerCli.js.map +1 -1
- package/dist/output/envelope.js +1 -5
- package/dist/output/envelope.js.map +1 -1
- package/dist/output/resultPrinter.js +0 -3
- package/dist/output/resultPrinter.js.map +1 -1
- package/dist/publish/responseClassifier.js +4 -4
- package/dist/publish/responseClassifier.js.map +1 -1
- package/dist/publish/runClient.js +11 -11
- package/dist/publish/runClient.js.map +1 -1
- package/dist/publish/siteConfig.js +649 -0
- package/dist/publish/siteConfig.js.map +1 -0
- package/dist/publish/siteZip.js +5 -4
- package/dist/publish/siteZip.js.map +1 -1
- package/dist/template/README.md +227 -64
- package/dist/template/android/app/src/main/java/com/supersdk/simple/EnvironmentStore.java +1 -1
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +2 -2
- package/dist/template/android/gradle/supersdk-config-reader.gradle +5 -6
- package/dist/template/android/supersdk-default.config.json +2 -3
- package/dist/template/ios/Sources/App/AppDelegate.swift +1 -1
- package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +1 -1
- package/dist/template/scripts/build_android.sh +10 -26
- package/dist/template/scripts/build_ios.sh +9 -41
- package/dist/template/scripts/build_site.sh +26 -40
- package/dist/template/scripts/lib/workspace.sh +4 -4
- package/dist/template/scripts/serve_web.py +4 -2
- package/dist/template/scripts/super_build_orchestrator.py +355 -278
- package/dist/template/scripts/supersdk_template.py +181 -414
- package/dist/template/scripts/web_package.py +8 -9
- package/dist/template/super_build.sh +113 -39
- package/dist/template/{super.json → supersdk.json} +1 -20
- package/dist/template/template_manifest.json +4 -5
- package/dist/workspace/config.js +119 -81
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/identity.js +14 -15
- package/dist/workspace/identity.js.map +1 -1
- package/dist/workspace/inspect.js +0 -1
- package/dist/workspace/inspect.js.map +1 -1
- package/dist/workspace/projectIdentity.js +96 -53
- package/dist/workspace/projectIdentity.js.map +1 -1
- package/dist/workspace/template.js +8 -5
- package/dist/workspace/template.js.map +1 -1
- package/package.json +2 -2
- package/dist/build/artifactIntegrity.js +0 -119
- package/dist/build/artifactIntegrity.js.map +0 -1
- package/dist/commands/build.js +0 -231
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/config.js +0 -170
- package/dist/commands/config.js.map +0 -1
- package/dist/config/superConfig.js +0 -429
- package/dist/config/superConfig.js.map +0 -1
- package/dist/deploy/adapterTypes.js +0 -3
- package/dist/deploy/adapterTypes.js.map +0 -1
- package/dist/deploy/manifest.js +0 -381
- package/dist/deploy/manifest.js.map +0 -1
- package/dist/deploy/preflight.js +0 -202
- package/dist/deploy/preflight.js.map +0 -1
- package/dist/deploy/resultWriter.js +0 -178
- package/dist/deploy/resultWriter.js.map +0 -1
- package/dist/deploy/runAdapter.js +0 -299
- package/dist/deploy/runAdapter.js.map +0 -1
- package/dist/deploy/siteAdapter.js +0 -182
- package/dist/deploy/siteAdapter.js.map +0 -1
- package/dist/template/scripts/build_service.sh +0 -89
- package/dist/template/service/Dockerfile +0 -2
- package/dist/workspace/projectContext.js +0 -93
- package/dist/workspace/projectContext.js.map +0 -1
|
@@ -19,7 +19,7 @@ EXCLUDED_ASSETS = {"__super_meta.json", ".DS_Store", "js/supersdk.provenance.jso
|
|
|
19
19
|
HEX64 = set("0123456789abcdef")
|
|
20
20
|
VERSION_PATTERN = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+$")
|
|
21
21
|
INTEGRITY_PATTERN = re.compile(r"^sha512-[A-Za-z0-9+/]+={0,2}$")
|
|
22
|
-
CONFIG_FILENAME = "
|
|
22
|
+
CONFIG_FILENAME = "supersdk.json"
|
|
23
23
|
|
|
24
24
|
# `<project>/src` is authored input; `<project>/dist` is the single publishable build
|
|
25
25
|
# output. It is what the offline zip is built from AND what `supercli publish-site <dir>`
|
|
@@ -153,7 +153,7 @@ def zip_staging(staging, output_dir, host, version):
|
|
|
153
153
|
temp_zip.unlink()
|
|
154
154
|
|
|
155
155
|
|
|
156
|
-
def build_dist(project_root, managed_config
|
|
156
|
+
def build_dist(project_root, managed_config):
|
|
157
157
|
"""Render <project>/src + the managed config into the publishable <project>/dist.
|
|
158
158
|
|
|
159
159
|
Built in a sibling temp dir and swapped in, so a failed build never leaves a
|
|
@@ -165,7 +165,7 @@ def build_dist(project_root, managed_config, output_dir=DIST_DIRNAME):
|
|
|
165
165
|
"""
|
|
166
166
|
project_root = Path(project_root)
|
|
167
167
|
source_root = validate_source(project_root / SRC_DIRNAME)
|
|
168
|
-
dist = project_root /
|
|
168
|
+
dist = project_root / DIST_DIRNAME
|
|
169
169
|
dist.parent.mkdir(parents=True, exist_ok=True)
|
|
170
170
|
staging_parent = Path(tempfile.mkdtemp(prefix=".supersdk-web-dist-", dir=dist.parent))
|
|
171
171
|
staging = staging_parent / DIST_DIRNAME
|
|
@@ -214,8 +214,8 @@ def package_managed(root, project):
|
|
|
214
214
|
config_path = project_root / ".supersdk" / "managed" / "config.json"
|
|
215
215
|
if not config_path.is_file():
|
|
216
216
|
raise WebPackageError(
|
|
217
|
-
f"site managed config missing; run scripts/supersdk_template.py inject --platform site --project
|
|
218
|
-
|
|
217
|
+
f"site managed config missing; run scripts/supersdk_template.py inject --platform site --project {project} "
|
|
218
|
+
"or ./super_build.sh --platform site --build"
|
|
219
219
|
)
|
|
220
220
|
try:
|
|
221
221
|
config = json.loads(config_path.read_text(encoding="utf-8"))
|
|
@@ -230,7 +230,6 @@ def package_managed(root, project):
|
|
|
230
230
|
raise WebPackageError("site managed config invalid")
|
|
231
231
|
|
|
232
232
|
host = platform_config.get("host")
|
|
233
|
-
output_dir = platform_config.get("outputDir", DIST_DIRNAME)
|
|
234
233
|
# 🔴 offline.host 是可选的、由服务端回填的:首次发布成功后 CLI 才把服务端签发的域名
|
|
235
234
|
# 记回配置。CLI 绝不自己拼域名,所以没有它就**跳过离线打包并显式说明原因** ——
|
|
236
235
|
# dist 照常产出(publish-site 要的就是它),静默跳过才是不可接受的那一种。
|
|
@@ -238,10 +237,10 @@ def package_managed(root, project):
|
|
|
238
237
|
# host 缺席不代表可以少校验:版本号照样要合法,dist 照样要产出。
|
|
239
238
|
validate_version(version.get("name"))
|
|
240
239
|
validate_source(project_root / SRC_DIRNAME)
|
|
241
|
-
dist = build_dist(project_root, config
|
|
240
|
+
dist = build_dist(project_root, config)
|
|
242
241
|
reason = (
|
|
243
242
|
f"offline package not built for {project}: projects[].offline.host is not set. "
|
|
244
|
-
"
|
|
243
|
+
"Publish the site once so the CLI records the server-issued host, or set it by hand in supersdk.json."
|
|
245
244
|
)
|
|
246
245
|
print(reason, file=sys.stderr)
|
|
247
246
|
return {"host": None, "version": version.get("name"), "zip": None, "dist": str(dist), "offline_skipped": reason}
|
|
@@ -250,7 +249,7 @@ def package_managed(root, project):
|
|
|
250
249
|
# Validate host/version/source before anything is written, so a bad host cannot
|
|
251
250
|
# leave a stale or partly-rendered dist on disk.
|
|
252
251
|
validate_inputs(project_root / SRC_DIRNAME, host, version.get("name"))
|
|
253
|
-
dist = build_dist(project_root, config
|
|
252
|
+
dist = build_dist(project_root, config)
|
|
254
253
|
# 🔴 output/ 是工作空间级的,但同名 zip 会被 unlink 后 replace:两个站点
|
|
255
254
|
# 同 host + 同 version 就会互相顶掉。按项目目录分仓,冲突从根上消失。
|
|
256
255
|
result = package(dist, host, version.get("name"), workspace_root / "output" / project, require_provenance=False)
|
|
@@ -11,60 +11,134 @@ ORCHESTRATOR="$WORKSPACE_ROOT/scripts/super_build_orchestrator.py"
|
|
|
11
11
|
|
|
12
12
|
usage() {
|
|
13
13
|
cat <<'EOF'
|
|
14
|
-
Usage: ./super_build.sh [--
|
|
14
|
+
Usage: ./super_build.sh [--platform all|android|ios|site] [--project DIR] [--plan|--build] [--force] [--config path]
|
|
15
15
|
|
|
16
16
|
Options:
|
|
17
|
-
--
|
|
18
|
-
--
|
|
19
|
-
--
|
|
20
|
-
--
|
|
21
|
-
--
|
|
22
|
-
--
|
|
23
|
-
--help
|
|
17
|
+
--platform VALUE Project type to plan/build. Default: all.
|
|
18
|
+
--project DIR Single project directory (as written in supersdk.json projects[].dir).
|
|
19
|
+
--plan Validate and print the build plan. Default when no mode is set.
|
|
20
|
+
--build Validate, inject managed config, then call project build helpers.
|
|
21
|
+
--force Allow replacing unmanaged target files during injection.
|
|
22
|
+
--config PATH Config file. Default: <workspace root>/supersdk.json.
|
|
23
|
+
--help Show this help.
|
|
24
24
|
EOF
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
config="$WORKSPACE_ROOT/super.json"
|
|
27
|
+
platform="all"
|
|
29
28
|
project=""
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
config="$WORKSPACE_ROOT/supersdk.json"
|
|
30
|
+
mode="plan"
|
|
32
31
|
mode_set=false
|
|
33
|
-
|
|
32
|
+
platform_set=false
|
|
34
33
|
project_set=false
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
config_set=false
|
|
35
|
+
force_set=false
|
|
36
|
+
force=false
|
|
37
37
|
|
|
38
38
|
while [ "$#" -gt 0 ]; do
|
|
39
39
|
case "$1" in
|
|
40
|
-
--help|-h)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
--
|
|
45
|
-
if [ "$
|
|
46
|
-
|
|
40
|
+
--help|-h)
|
|
41
|
+
usage
|
|
42
|
+
exit 0
|
|
43
|
+
;;
|
|
44
|
+
--platform)
|
|
45
|
+
if [ "$platform_set" = true ]; then
|
|
46
|
+
echo "error: --platform specified more than once" >&2
|
|
47
|
+
exit 2
|
|
48
|
+
fi
|
|
49
|
+
if [ "$#" -lt 2 ]; then
|
|
50
|
+
echo "error: --platform requires a value" >&2
|
|
51
|
+
exit 2
|
|
52
|
+
fi
|
|
53
|
+
platform="$2"
|
|
54
|
+
platform_set=true
|
|
55
|
+
shift 2
|
|
56
|
+
;;
|
|
47
57
|
--project)
|
|
48
|
-
if [ "$project_set" = true ]
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
if [ "$project_set" = true ]; then
|
|
59
|
+
echo "error: --project specified more than once" >&2
|
|
60
|
+
exit 2
|
|
61
|
+
fi
|
|
62
|
+
if [ "$#" -lt 2 ]; then
|
|
63
|
+
echo "error: --project requires a value" >&2
|
|
64
|
+
exit 2
|
|
65
|
+
fi
|
|
66
|
+
project="$2"
|
|
67
|
+
project_set=true
|
|
68
|
+
shift 2
|
|
69
|
+
;;
|
|
70
|
+
--config)
|
|
71
|
+
if [ "$config_set" = true ]; then
|
|
72
|
+
echo "error: --config specified more than once" >&2
|
|
73
|
+
exit 2
|
|
74
|
+
fi
|
|
75
|
+
if [ "$#" -lt 2 ]; then
|
|
76
|
+
echo "error: --config requires a value" >&2
|
|
77
|
+
exit 2
|
|
78
|
+
fi
|
|
79
|
+
config="$2"
|
|
80
|
+
config_set=true
|
|
81
|
+
shift 2
|
|
82
|
+
;;
|
|
83
|
+
--plan)
|
|
84
|
+
if [ "$mode_set" = true ]; then
|
|
85
|
+
echo "error: mode specified more than once" >&2
|
|
86
|
+
exit 2
|
|
87
|
+
fi
|
|
88
|
+
mode="plan"
|
|
89
|
+
mode_set=true
|
|
90
|
+
shift
|
|
91
|
+
;;
|
|
92
|
+
--build)
|
|
93
|
+
if [ "$mode_set" = true ]; then
|
|
94
|
+
echo "error: mode specified more than once" >&2
|
|
95
|
+
exit 2
|
|
96
|
+
fi
|
|
97
|
+
mode="build"
|
|
98
|
+
mode_set=true
|
|
99
|
+
shift
|
|
100
|
+
;;
|
|
101
|
+
--force)
|
|
102
|
+
if [ "$force_set" = true ]; then
|
|
103
|
+
echo "error: --force specified more than once" >&2
|
|
104
|
+
exit 2
|
|
105
|
+
fi
|
|
106
|
+
force=true
|
|
107
|
+
force_set=true
|
|
108
|
+
shift
|
|
109
|
+
;;
|
|
110
|
+
*)
|
|
111
|
+
echo "error: unknown option $1" >&2
|
|
112
|
+
exit 2
|
|
113
|
+
;;
|
|
57
114
|
esac
|
|
58
115
|
done
|
|
59
116
|
|
|
117
|
+
case "$platform" in
|
|
118
|
+
all|android|ios|site) ;;
|
|
119
|
+
*)
|
|
120
|
+
echo "error: invalid platform $platform" >&2
|
|
121
|
+
exit 2
|
|
122
|
+
;;
|
|
123
|
+
esac
|
|
124
|
+
|
|
125
|
+
selection=(--platform "$platform")
|
|
126
|
+
if [ "$project_set" = true ]; then
|
|
127
|
+
selection+=(--project "$project")
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# 引擎版本比对:managed config 记录了写它的那一版引擎。模板是 vendored 进每个工作空间的,
|
|
131
|
+
# 升级后不重新投影就会拿旧形状去喂新构建脚本。只 warn,不阻断。
|
|
132
|
+
"$PYTHON_BIN" "$HELPER" engine-check --root "$WORKSPACE_ROOT" --config "$config" || true
|
|
133
|
+
|
|
60
134
|
if [ "$mode" = "plan" ]; then
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
135
|
+
exec "$PYTHON_BIN" "$HELPER" plan --root "$WORKSPACE_ROOT" --config "$config" "${selection[@]}"
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
inject_args=(inject --root "$WORKSPACE_ROOT" --config "$config" "${selection[@]}")
|
|
139
|
+
if [ "$force" = true ]; then
|
|
140
|
+
inject_args+=(--force)
|
|
65
141
|
fi
|
|
142
|
+
"$PYTHON_BIN" "$HELPER" "${inject_args[@]}"
|
|
66
143
|
|
|
67
|
-
|
|
68
|
-
if [ -n "$project" ]; then args+=(--project "$project"); fi
|
|
69
|
-
if [ -n "$cli_version" ]; then args+=(--cli-version "$cli_version"); fi
|
|
70
|
-
exec "$PYTHON_BIN" "$ORCHESTRATOR" "${args[@]}"
|
|
144
|
+
exec "$PYTHON_BIN" "$ORCHESTRATOR" --root "$WORKSPACE_ROOT" --config "$config" "${selection[@]}"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"schemaVersion":
|
|
2
|
+
"schemaVersion": 3,
|
|
3
3
|
"spid": "demo0001",
|
|
4
4
|
"name": "SuperSDK Simple",
|
|
5
5
|
"version": {
|
|
@@ -11,14 +11,12 @@
|
|
|
11
11
|
},
|
|
12
12
|
"projects": [
|
|
13
13
|
{
|
|
14
|
-
"projectId": "android",
|
|
15
14
|
"type": "android",
|
|
16
15
|
"dir": "android",
|
|
17
16
|
"name": "SuperSDK Simple",
|
|
18
17
|
"package": "com.supersdk.simple.host"
|
|
19
18
|
},
|
|
20
19
|
{
|
|
21
|
-
"projectId": "ios",
|
|
22
20
|
"type": "ios",
|
|
23
21
|
"dir": "ios",
|
|
24
22
|
"name": "SuperSDK Simple",
|
|
@@ -26,29 +24,12 @@
|
|
|
26
24
|
"spmMode": "mock"
|
|
27
25
|
},
|
|
28
26
|
{
|
|
29
|
-
"projectId": "web",
|
|
30
27
|
"type": "site",
|
|
31
28
|
"dir": "web",
|
|
32
29
|
"name": "SuperSDK Simple Web",
|
|
33
|
-
"build": {
|
|
34
|
-
"outputDir": "dist"
|
|
35
|
-
},
|
|
36
30
|
"offline": {
|
|
37
31
|
"host": "simple.supersdk.com"
|
|
38
32
|
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"projectId": "service",
|
|
42
|
-
"type": "service",
|
|
43
|
-
"dir": "service",
|
|
44
|
-
"name": "SuperSDK Simple Service",
|
|
45
|
-
"build": {
|
|
46
|
-
"context": ".",
|
|
47
|
-
"dockerfile": "Dockerfile",
|
|
48
|
-
"platform": "linux/amd64",
|
|
49
|
-
"argsFromEnv": []
|
|
50
|
-
},
|
|
51
|
-
"deploy": []
|
|
52
33
|
}
|
|
53
34
|
]
|
|
54
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"engineVersion": "
|
|
3
|
-
"schemaVersion":
|
|
2
|
+
"engineVersion": "3.0.0",
|
|
3
|
+
"schemaVersion": 3,
|
|
4
4
|
"source": "app_repo_example",
|
|
5
5
|
"comment": [
|
|
6
6
|
"模板的拆分契约,给 supercli 消费:`init` 落地 workspace 级共享物一次,`add <type> <dir>` 拷贝对应类型的项目模板。",
|
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
"projects": {
|
|
18
18
|
"android": "android",
|
|
19
19
|
"ios": "ios",
|
|
20
|
-
"site": "web"
|
|
21
|
-
"service": "service"
|
|
20
|
+
"site": "web"
|
|
22
21
|
},
|
|
23
22
|
"generated": [
|
|
24
|
-
"
|
|
23
|
+
"supersdk.json"
|
|
25
24
|
]
|
|
26
25
|
}
|
package/dist/workspace/config.js
CHANGED
|
@@ -45,14 +45,18 @@ exports.isValidConfigFile = isValidConfigFile;
|
|
|
45
45
|
exports.legacyConfigIn = legacyConfigIn;
|
|
46
46
|
exports.createWorkspaceConfig = createWorkspaceConfig;
|
|
47
47
|
exports.appendProject = appendProject;
|
|
48
|
+
exports.unsupportedSchemaMessage = unsupportedSchemaMessage;
|
|
48
49
|
exports.findEnclosingWorkspace = findEnclosingWorkspace;
|
|
49
50
|
exports.legacyMigrationMessage = legacyMigrationMessage;
|
|
50
|
-
// `
|
|
51
|
+
// `supersdk.json` v3 —— **工作空间写侧**(`supercli init` / `supercli add`)需要的那部分。
|
|
51
52
|
//
|
|
52
|
-
// 一个 workspace = 一个 spid,`
|
|
53
|
+
// 一个 workspace = 一个 spid,`supersdk.json` 所在目录即工作空间根。
|
|
53
54
|
//
|
|
54
|
-
// 🔴
|
|
55
|
-
//
|
|
55
|
+
// 🔴 这里**不再重写一遍校验**。文件的合法性判定只有一份,在 `src/publish/siteConfig.ts` 的
|
|
56
|
+
// `parseConfig` / `findConfig`(schemaVersion、退役根键、重复键、spid、projects[].dir 唯一且
|
|
57
|
+
// 互不为祖先、deploy[] 形状……)。写侧再写一份「差不多的」校验,等于给同一个文件准备了两套
|
|
58
|
+
// 判据:某天两边口径分岔时,就会出现「add 写得出去、publish-site 立刻拒绝」这种同一棵树上
|
|
59
|
+
// 两端打架的状态 —— 本轮统一配置要消灭的正是它。
|
|
56
60
|
//
|
|
57
61
|
// 本模块只补写侧真正独有的三件事:
|
|
58
62
|
// 1. 一个**全项目**视角(parseConfig 的产物只暴露站点项目,登记新目录时要跟所有项目比对);
|
|
@@ -60,11 +64,11 @@ exports.legacyMigrationMessage = legacyMigrationMessage;
|
|
|
60
64
|
// 3. `projects[]` 的追加写入(加锁 → parse → 只改自己那段 → stringify)。
|
|
61
65
|
const fs = __importStar(require("node:fs"));
|
|
62
66
|
const path = __importStar(require("node:path"));
|
|
63
|
-
const node_crypto_1 = require("node:crypto");
|
|
64
67
|
const appConfig_1 = require("../config/appConfig");
|
|
65
|
-
const
|
|
68
|
+
const siteConfig_1 = require("../publish/siteConfig");
|
|
66
69
|
const fsAtomic_1 = require("../util/fsAtomic");
|
|
67
70
|
const shell_1 = require("../util/shell");
|
|
71
|
+
const identity_1 = require("./identity");
|
|
68
72
|
exports.CONFIG_FILENAME = appConfig_1.APP_CONFIG_FILENAME;
|
|
69
73
|
exports.SCHEMA_VERSION = appConfig_1.APP_CONFIG_SCHEMA_VERSION;
|
|
70
74
|
class WorkspaceConfigError extends Error {
|
|
@@ -75,10 +79,10 @@ exports.WorkspaceConfigError = WorkspaceConfigError;
|
|
|
75
79
|
// ---------------------------------------------------------------------------
|
|
76
80
|
/**
|
|
77
81
|
* 归一化一个候选目录,失败时给出**可读的原因**(用于面向用户的报错)。
|
|
78
|
-
* 归一化规则本身来自
|
|
82
|
+
* 归一化规则本身来自 siteConfig.normalizeProjectDir —— 这里只负责把 `undefined` 翻译成人话。
|
|
79
83
|
*/
|
|
80
84
|
function checkProjectDir(raw) {
|
|
81
|
-
const normalized = (0,
|
|
85
|
+
const normalized = (0, siteConfig_1.normalizeProjectDir)(raw);
|
|
82
86
|
if (normalized === undefined) {
|
|
83
87
|
return {
|
|
84
88
|
error: 'must be a relative POSIX path inside the workspace (no leading "/", no drive letter, ' +
|
|
@@ -129,7 +133,7 @@ function projectsOf(document) {
|
|
|
129
133
|
continue;
|
|
130
134
|
if (typeof item.type !== 'string' || typeof item.dir !== 'string')
|
|
131
135
|
continue;
|
|
132
|
-
const normalized = (0,
|
|
136
|
+
const normalized = (0, siteConfig_1.normalizeProjectDir)(item.dir);
|
|
133
137
|
if (normalized === undefined)
|
|
134
138
|
continue;
|
|
135
139
|
projects.push({ ...item, type: item.type, dir: normalized });
|
|
@@ -138,15 +142,36 @@ function projectsOf(document) {
|
|
|
138
142
|
}
|
|
139
143
|
/** parseConfig / findConfig 的失败结果 → 面向用户的一段话。成功时返回 undefined。 */
|
|
140
144
|
function describeConfigProblem(result, startDir) {
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
switch (result.kind) {
|
|
146
|
+
case 'valid':
|
|
147
|
+
return undefined;
|
|
148
|
+
case 'absent':
|
|
149
|
+
return (`no ${exports.CONFIG_FILENAME} found in ${startDir} or any parent directory ` +
|
|
150
|
+
`(searched: ${result.searched.join(', ')}).\n` +
|
|
151
|
+
'`supercli add` registers a project inside an existing workspace — create one first:\n\n' +
|
|
152
|
+
// 占位符必须带引号:裸 `<spid>` 粘进 bash 是 `syntax error near unexpected token 'newline'`,
|
|
153
|
+
// 引号版粘进去则会撞上 init 自己的 --spid 校验,那才是人需要看到的报错。
|
|
154
|
+
` supercli init . --spid ${(0, shell_1.shellQuote)(`<${identity_1.SPID_PATTERN_SOURCE}>`)}`);
|
|
155
|
+
case 'legacy-app-yaml':
|
|
156
|
+
case 'legacy-site-yml':
|
|
157
|
+
return legacyMigrationMessage(result.path, result.existingConfigPath !== undefined);
|
|
158
|
+
case 'unsupported-schema':
|
|
159
|
+
return unsupportedSchemaMessage(result.path, result.found);
|
|
160
|
+
case 'invalid':
|
|
161
|
+
return `${result.path}: ${result.reason}`;
|
|
162
|
+
default: {
|
|
163
|
+
// 穷尽性检查:ConfigReadResult 加了新分支而这里没跟上时,编译期就会失败。
|
|
164
|
+
const exhaustive = result;
|
|
165
|
+
return String(exhaustive);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
143
168
|
}
|
|
144
169
|
/**
|
|
145
170
|
* 从 `startDir` 向上找到工作空间并读出全项目视角。
|
|
146
171
|
* 查找与校验都走 `findConfig`(发布侧同一份实现),这里只负责把结果翻译成写侧要的形状。
|
|
147
172
|
*/
|
|
148
|
-
function loadWorkspace(startDir
|
|
149
|
-
const found = (0,
|
|
173
|
+
function loadWorkspace(startDir) {
|
|
174
|
+
const found = (0, siteConfig_1.findConfig)(startDir);
|
|
150
175
|
const problem = describeConfigProblem(found, path.resolve(startDir));
|
|
151
176
|
if (problem !== undefined || found.kind !== 'valid') {
|
|
152
177
|
return { kind: 'error', message: problem ?? `cannot read ${exports.CONFIG_FILENAME}` };
|
|
@@ -184,7 +209,7 @@ function loadWorkspace(startDir, explicitPath) {
|
|
|
184
209
|
*/
|
|
185
210
|
function isValidConfigFile(configPath) {
|
|
186
211
|
try {
|
|
187
|
-
return (0,
|
|
212
|
+
return (0, siteConfig_1.parseConfig)(fs.readFileSync(configPath, 'utf8'), configPath).kind === 'valid';
|
|
188
213
|
}
|
|
189
214
|
catch {
|
|
190
215
|
return false;
|
|
@@ -212,7 +237,7 @@ function writePreservingMode(filePath, content) {
|
|
|
212
237
|
mode = undefined;
|
|
213
238
|
}
|
|
214
239
|
(0, fsAtomic_1.atomicWriteFileSync)(filePath, content);
|
|
215
|
-
// atomicWriteFileSync 以 0600 建临时文件再 rename。
|
|
240
|
+
// atomicWriteFileSync 以 0600 建临时文件再 rename。supersdk.json 是人机共写、通常入库的
|
|
216
241
|
// 普通配置,不该被一次机器写入悄悄收紧成 0600。
|
|
217
242
|
if (mode !== undefined) {
|
|
218
243
|
try {
|
|
@@ -223,66 +248,28 @@ function writePreservingMode(filePath, content) {
|
|
|
223
248
|
}
|
|
224
249
|
}
|
|
225
250
|
}
|
|
226
|
-
/**
|
|
251
|
+
/** 写出前自证:写出去的东西必须能被**发布侧同一个解析器**读回来。 */
|
|
227
252
|
function serializeVerified(configPath, document) {
|
|
228
253
|
const serialized = (0, appConfig_1.serializeAppConfig)(document);
|
|
229
|
-
const verified = (0,
|
|
254
|
+
const verified = (0, siteConfig_1.parseConfig)(serialized, configPath);
|
|
230
255
|
if (verified.kind !== 'valid') {
|
|
231
256
|
const detail = verified.kind === 'invalid' ? verified.reason : verified.kind;
|
|
232
257
|
throw new WorkspaceConfigError(`refusing to write an invalid ${exports.CONFIG_FILENAME}: ${detail}`);
|
|
233
258
|
}
|
|
234
259
|
return serialized;
|
|
235
260
|
}
|
|
236
|
-
function fsyncDirectory(directory) {
|
|
237
|
-
if (process.platform === 'win32')
|
|
238
|
-
return;
|
|
239
|
-
const fd = fs.openSync(directory, 'r');
|
|
240
|
-
try {
|
|
241
|
-
fs.fsyncSync(fd);
|
|
242
|
-
}
|
|
243
|
-
finally {
|
|
244
|
-
fs.closeSync(fd);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
261
|
/**
|
|
248
|
-
*
|
|
249
|
-
*
|
|
262
|
+
* 首次落盘。用 `wx` 独占创建:`supersdk.json` 已存在时**必须**失败而不是覆盖 ——
|
|
263
|
+
* 覆盖会把一个已有工作空间的 projects[] / orgId 整份抹掉。
|
|
250
264
|
*/
|
|
251
|
-
function createWorkspaceConfig(configPath, document
|
|
265
|
+
function createWorkspaceConfig(configPath, document) {
|
|
252
266
|
const serialized = serializeVerified(configPath, document);
|
|
253
|
-
|
|
254
|
-
fs.
|
|
255
|
-
const temporaryPath = path.join(directory, `.${path.basename(configPath)}.init.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`);
|
|
256
|
-
let fd;
|
|
257
|
-
try {
|
|
258
|
-
fd = fs.openSync(temporaryPath, 'wx', 0o666);
|
|
259
|
-
fs.writeFileSync(fd, serialized, { encoding: 'utf8' });
|
|
260
|
-
fs.fsyncSync(fd);
|
|
261
|
-
fs.closeSync(fd);
|
|
262
|
-
fd = undefined;
|
|
263
|
-
hooks.beforeInstall?.(temporaryPath);
|
|
264
|
-
fs.linkSync(temporaryPath, configPath);
|
|
265
|
-
fs.unlinkSync(temporaryPath);
|
|
266
|
-
fsyncDirectory(directory);
|
|
267
|
-
}
|
|
268
|
-
finally {
|
|
269
|
-
if (fd !== undefined) {
|
|
270
|
-
try {
|
|
271
|
-
fs.closeSync(fd);
|
|
272
|
-
}
|
|
273
|
-
catch { /* preserve the original write failure */ }
|
|
274
|
-
}
|
|
275
|
-
try {
|
|
276
|
-
fs.unlinkSync(temporaryPath);
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
if (error.code !== 'ENOENT') { /* best-effort owned-temp cleanup */ }
|
|
280
|
-
}
|
|
281
|
-
}
|
|
267
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
268
|
+
fs.writeFileSync(configPath, serialized, { encoding: 'utf8', flag: 'wx' });
|
|
282
269
|
}
|
|
283
270
|
/**
|
|
284
|
-
* `加锁 → parse → 只改 projects[] → stringify
|
|
285
|
-
*
|
|
271
|
+
* `加锁 → parse → 只改 projects[] → stringify`。整份文档在**锁内**从磁盘重新读取,未知键随
|
|
272
|
+
* 对象一并带回,只有 projects 一处被触碰。
|
|
286
273
|
*
|
|
287
274
|
* 🔴 跨进程锁不是可选项:`readFileSync → 改 → atomicWriteFileSync` 里的 atomic rename 只保证
|
|
288
275
|
* 文件不撕裂,**不防 lost update**。两个 `supercli add` 并行时,后写者会把先写者刚落盘的条目
|
|
@@ -293,7 +280,7 @@ function appendProject(configPath, entry) {
|
|
|
293
280
|
try {
|
|
294
281
|
// 必须在锁内重读:锁外读到的可能已被其他进程改写。
|
|
295
282
|
const before = fs.readFileSync(configPath, 'utf8');
|
|
296
|
-
const gate = (0,
|
|
283
|
+
const gate = (0, siteConfig_1.parseConfig)(before, configPath);
|
|
297
284
|
if (gate.kind !== 'valid') {
|
|
298
285
|
const detail = gate.kind === 'invalid' ? gate.reason : gate.kind;
|
|
299
286
|
throw new WorkspaceConfigError(`refusing to write an unparseable ${exports.CONFIG_FILENAME}: ${detail}`);
|
|
@@ -314,16 +301,73 @@ function appendProject(configPath, entry) {
|
|
|
314
301
|
}
|
|
315
302
|
}
|
|
316
303
|
// ---------------------------------------------------------------------------
|
|
304
|
+
// v2 → v3 的迁移提示
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
/**
|
|
307
|
+
* schemaVersion 不是 3 时的 fail-closed 指引。
|
|
308
|
+
*
|
|
309
|
+
* 🔴 两条纪律,都是上一版这段文案违反过的:
|
|
310
|
+
*
|
|
311
|
+
* 1. **绝不让人重建工作空间**。`rm supersdk.json` + 重新 init/add 会丢掉 publish-site 回填的
|
|
312
|
+
* `orgId` 和全部 `sites[]`/`deploy[]` 绑定 —— 那些是服务端签发过的东西,重跑一遍拿不回来。
|
|
313
|
+
* 而仓库里 vendored 的引擎自带**无损**的 `migrate`(未知根键、orgId、每条发布绑定原样带过),
|
|
314
|
+
* 指引必须指向它。
|
|
315
|
+
* 2. **命令要能原样粘进 shell**。裸 `<spid>` 粘进 bash 是 `syntax error near unexpected token
|
|
316
|
+
* 'newline'`(退出码 2),人根本走不到「这条命令想干什么」那一步。所以这里唯一的可执行块
|
|
317
|
+
* 里没有占位符:路径全是运行时算出来的真值,剩下的说明一律是散文。
|
|
318
|
+
*
|
|
319
|
+
* 命令形态**不在这里自己拼**:单点在 `config/appConfig.ts` 的 `engineMigrateCommand()`
|
|
320
|
+
* (发布侧 publishSite.ts 用的是同一个函数)。`--config` 在权威侧是 `required=True`,
|
|
321
|
+
* 少这一个参数照抄下去就是 `error: the following arguments are required: --config`、退出码 2。
|
|
322
|
+
*/
|
|
323
|
+
function unsupportedSchemaMessage(configPath, found) {
|
|
324
|
+
const root = path.dirname(configPath);
|
|
325
|
+
const migrate = `cd ${(0, shell_1.shellQuote)(root)} && ${(0, appConfig_1.engineMigrateCommand)(path.basename(configPath))}`;
|
|
326
|
+
const head = `${configPath} has schemaVersion ${JSON.stringify(found)}; supercli only reads schemaVersion ${exports.SCHEMA_VERSION}.`;
|
|
327
|
+
if (typeof found === 'number' && found > exports.SCHEMA_VERSION) {
|
|
328
|
+
return [
|
|
329
|
+
head,
|
|
330
|
+
'this file was written by a newer supercli. do NOT hand-edit the version down — run `supercli update` and retry.',
|
|
331
|
+
].join('\n');
|
|
332
|
+
}
|
|
333
|
+
return [
|
|
334
|
+
head,
|
|
335
|
+
`v${exports.SCHEMA_VERSION} is a breaking change with no backward compatibility, but nothing has to be re-created: the ` +
|
|
336
|
+
'build engine vendored under scripts/ migrates this file in place and loses nothing — orgId, every publish ' +
|
|
337
|
+
'binding and every unknown key are carried over.',
|
|
338
|
+
'',
|
|
339
|
+
'Preview it, then apply it:',
|
|
340
|
+
'',
|
|
341
|
+
` ${migrate} --dry-run`,
|
|
342
|
+
` ${migrate}`,
|
|
343
|
+
'',
|
|
344
|
+
'What it changes: "android" / "ios" / "web" each become one entry in "projects" (keeping name/package/bundleId/' +
|
|
345
|
+
'spmMode); every "sites" entry moves unchanged, as {slug, name, env, dir}, into the "deploy" array of the site ' +
|
|
346
|
+
'project that owns it; "environment" is dropped because the SDK environment is a runtime argument of ' +
|
|
347
|
+
'SuperSDK.init() (omitting it means prod); "orgId", "version" and "sdk" stay exactly where they are.',
|
|
348
|
+
'',
|
|
349
|
+
`If \`migrate\` comes back as an unknown subcommand, the engine vendored at ${appConfig_1.ENGINE_SCRIPT_RELPATH} predates ` +
|
|
350
|
+
`v${exports.SCHEMA_VERSION}. Run \`supercli init\` in a new empty directory and copy that workspace's scripts/ and ` +
|
|
351
|
+
'super_build.sh over yours first — init and add never overwrite files that are already in place, so they ' +
|
|
352
|
+
'cannot refresh them for you.',
|
|
353
|
+
'',
|
|
354
|
+
`Migrating by hand instead? This is the complete v${exports.SCHEMA_VERSION} shape:`,
|
|
355
|
+
'',
|
|
356
|
+
(0, appConfig_1.appConfigSkeleton)(),
|
|
357
|
+
].join('\n');
|
|
358
|
+
}
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
317
360
|
// 工作空间嵌套
|
|
318
361
|
// ---------------------------------------------------------------------------
|
|
319
362
|
/**
|
|
320
363
|
* `target` **之上**是否已经有一份工作空间配置;有就返回最近的那份的路径。
|
|
321
364
|
*
|
|
322
|
-
* 🔴 为什么 `init`
|
|
323
|
-
* `
|
|
365
|
+
* 🔴 为什么 `init` 必须查这个:`findConfig` 是「从 cwd 向上找到第一份就停」,所以嵌套出来的
|
|
366
|
+
* 内层 `supersdk.json` 会**遮蔽**外层 —— 之后每一次 `add` / `publish-site` 都悄悄绑到内层那个
|
|
367
|
+
* spid 上,两份配置各自漂移,全程零告警。`add` 早就把「项目目录不得互为祖先」当硬失败
|
|
324
368
|
* (findDirConflict),`init` 不查就等于在同一棵树上给了两套判据。
|
|
325
369
|
*
|
|
326
|
-
* 判定复用 `
|
|
370
|
+
* 判定复用 `findConfig` 而不是另写一次向上遍历:停止边界(.git 仓库根 / 家目录 / 文件系统根 /
|
|
327
371
|
* 深度上限)必须与真正会去读配置的那条路径逐字一致,否则「init 说不嵌套、add 却找到了外层」。
|
|
328
372
|
*/
|
|
329
373
|
function findEnclosingWorkspace(target) {
|
|
@@ -331,15 +375,18 @@ function findEnclosingWorkspace(target) {
|
|
|
331
375
|
const parent = path.dirname(resolved);
|
|
332
376
|
if (parent === resolved)
|
|
333
377
|
return undefined;
|
|
334
|
-
const found = (0,
|
|
378
|
+
const found = (0, siteConfig_1.findConfig)(parent);
|
|
335
379
|
switch (found.kind) {
|
|
336
380
|
case 'valid':
|
|
337
381
|
return found.config.path;
|
|
338
|
-
//
|
|
382
|
+
// 这两种只可能来自一个真实存在的 supersdk.json(v2 的、或写坏了的)—— 一样会遮蔽。
|
|
383
|
+
case 'unsupported-schema':
|
|
339
384
|
case 'invalid':
|
|
340
385
|
return found.path;
|
|
341
|
-
|
|
342
|
-
|
|
386
|
+
// 上层是退役 YAML:它不参与 supersdk.json 的向上查找,只有同目录确实还有一份 JSON 时才算嵌套。
|
|
387
|
+
case 'legacy-app-yaml':
|
|
388
|
+
case 'legacy-site-yml':
|
|
389
|
+
return found.existingConfigPath;
|
|
343
390
|
case 'absent':
|
|
344
391
|
return undefined;
|
|
345
392
|
default: {
|
|
@@ -358,7 +405,7 @@ function findEnclosingWorkspace(target) {
|
|
|
358
405
|
* required field is a dead end, so the skeleton carries the complete set.
|
|
359
406
|
*
|
|
360
407
|
* 两种情形,动作顺序不同(且不能反):
|
|
361
|
-
* - 目录里**已经有一份合法的
|
|
408
|
+
* - 目录里**已经有一份合法的 supersdk.json** → 没有任何字段需要搬运,只发 `rm <legacy>`。
|
|
362
409
|
* 再让人照抄一遍 `cat >` 会用占位值覆盖掉他已经写好的真配置。
|
|
363
410
|
* - 没有 → 先写新文件、**再**删旧文件:旧文件是字段的唯一来源,先删就没得抄了。
|
|
364
411
|
*/
|
|
@@ -366,7 +413,7 @@ function legacyMigrationMessage(yamlPath, jsonAlreadyValid = false) {
|
|
|
366
413
|
const legacyName = path.basename(yamlPath);
|
|
367
414
|
const dir = path.dirname(yamlPath);
|
|
368
415
|
const head = [
|
|
369
|
-
`${legacyName}
|
|
416
|
+
`${legacyName} (retired schema_version: 1 dialect) is no longer supported — supercli reads ` +
|
|
370
417
|
`${exports.CONFIG_FILENAME} (schemaVersion ${exports.SCHEMA_VERSION}) only, and there is no compatibility fallback.`,
|
|
371
418
|
`found: ${yamlPath}`,
|
|
372
419
|
'',
|
|
@@ -380,15 +427,6 @@ function legacyMigrationMessage(yamlPath, jsonAlreadyValid = false) {
|
|
|
380
427
|
`rm ${(0, shell_1.shellQuote)(legacyName)}`,
|
|
381
428
|
].join('\n');
|
|
382
429
|
}
|
|
383
|
-
if (legacyName === 'supersdk.json') {
|
|
384
|
-
return [
|
|
385
|
-
...head,
|
|
386
|
-
'Migrate schema v3 atomically; the source is retained and the target must not already exist:',
|
|
387
|
-
'',
|
|
388
|
-
`cd ${(0, shell_1.shellQuote)(dir)}`,
|
|
389
|
-
`supercli config migrate --from ${(0, shell_1.shellQuote)(legacyName)} --to ${(0, shell_1.shellQuote)(exports.CONFIG_FILENAME)}`,
|
|
390
|
-
].join('\n');
|
|
391
|
-
}
|
|
392
430
|
return [
|
|
393
431
|
...head,
|
|
394
432
|
'Migrate it once — replace the placeholder values with the ones already in your YAML, then run:',
|