@supersdk/supercli 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/build/artifactIntegrity.js +119 -0
  2. package/dist/build/artifactIntegrity.js.map +1 -0
  3. package/dist/cli.js +22 -11
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/add.js +79 -31
  6. package/dist/commands/add.js.map +1 -1
  7. package/dist/commands/analytics.js +15 -9
  8. package/dist/commands/analytics.js.map +1 -1
  9. package/dist/commands/build.js +231 -0
  10. package/dist/commands/build.js.map +1 -0
  11. package/dist/commands/config.js +170 -0
  12. package/dist/commands/config.js.map +1 -0
  13. package/dist/commands/db.js +24 -19
  14. package/dist/commands/db.js.map +1 -1
  15. package/dist/commands/deploy.js +434 -751
  16. package/dist/commands/deploy.js.map +1 -1
  17. package/dist/commands/env.js +8 -8
  18. package/dist/commands/env.js.map +1 -1
  19. package/dist/commands/image.js +31 -20
  20. package/dist/commands/image.js.map +1 -1
  21. package/dist/commands/init.js +68 -37
  22. package/dist/commands/init.js.map +1 -1
  23. package/dist/commands/logs.js +16 -7
  24. package/dist/commands/logs.js.map +1 -1
  25. package/dist/commands/publishSite.js +28 -943
  26. package/dist/commands/publishSite.js.map +1 -1
  27. package/dist/commands/register.js +51 -30
  28. package/dist/commands/register.js.map +1 -1
  29. package/dist/commands/settings.js +10 -6
  30. package/dist/commands/settings.js.map +1 -1
  31. package/dist/config/appConfig.js +40 -36
  32. package/dist/config/appConfig.js.map +1 -1
  33. package/dist/config/superConfig.js +429 -0
  34. package/dist/config/superConfig.js.map +1 -0
  35. package/dist/deploy/adapterTypes.js +3 -0
  36. package/dist/deploy/adapterTypes.js.map +1 -0
  37. package/dist/deploy/manifest.js +381 -0
  38. package/dist/deploy/manifest.js.map +1 -0
  39. package/dist/deploy/preflight.js +202 -0
  40. package/dist/deploy/preflight.js.map +1 -0
  41. package/dist/deploy/resultWriter.js +178 -0
  42. package/dist/deploy/resultWriter.js.map +1 -0
  43. package/dist/deploy/runAdapter.js +299 -0
  44. package/dist/deploy/runAdapter.js.map +1 -0
  45. package/dist/deploy/siteAdapter.js +182 -0
  46. package/dist/deploy/siteAdapter.js.map +1 -0
  47. package/dist/docker/dockerCli.js +63 -1
  48. package/dist/docker/dockerCli.js.map +1 -1
  49. package/dist/output/envelope.js +5 -1
  50. package/dist/output/envelope.js.map +1 -1
  51. package/dist/output/resultPrinter.js +3 -0
  52. package/dist/output/resultPrinter.js.map +1 -1
  53. package/dist/publish/responseClassifier.js +4 -4
  54. package/dist/publish/responseClassifier.js.map +1 -1
  55. package/dist/publish/runClient.js +11 -11
  56. package/dist/publish/runClient.js.map +1 -1
  57. package/dist/publish/siteZip.js +4 -5
  58. package/dist/publish/siteZip.js.map +1 -1
  59. package/dist/template/README.md +64 -227
  60. package/dist/template/android/app/src/main/java/com/supersdk/simple/EnvironmentStore.java +1 -1
  61. package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +2 -2
  62. package/dist/template/android/gradle/supersdk-config-reader.gradle +6 -5
  63. package/dist/template/android/supersdk-default.config.json +3 -2
  64. package/dist/template/ios/Sources/App/AppDelegate.swift +1 -1
  65. package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +1 -1
  66. package/dist/template/scripts/build_android.sh +26 -10
  67. package/dist/template/scripts/build_ios.sh +41 -9
  68. package/dist/template/scripts/build_service.sh +89 -0
  69. package/dist/template/scripts/build_site.sh +40 -26
  70. package/dist/template/scripts/lib/workspace.sh +4 -4
  71. package/dist/template/scripts/serve_web.py +2 -4
  72. package/dist/template/scripts/super_build_orchestrator.py +278 -355
  73. package/dist/template/scripts/supersdk_template.py +414 -181
  74. package/dist/template/scripts/web_package.py +9 -8
  75. package/dist/template/service/Dockerfile +2 -0
  76. package/dist/template/{supersdk.json → super.json} +20 -1
  77. package/dist/template/super_build.sh +39 -113
  78. package/dist/template/template_manifest.json +5 -4
  79. package/dist/workspace/config.js +81 -119
  80. package/dist/workspace/config.js.map +1 -1
  81. package/dist/workspace/identity.js +15 -14
  82. package/dist/workspace/identity.js.map +1 -1
  83. package/dist/workspace/inspect.js +1 -0
  84. package/dist/workspace/inspect.js.map +1 -1
  85. package/dist/workspace/projectContext.js +93 -0
  86. package/dist/workspace/projectContext.js.map +1 -0
  87. package/dist/workspace/projectIdentity.js +53 -96
  88. package/dist/workspace/projectIdentity.js.map +1 -1
  89. package/dist/workspace/template.js +5 -8
  90. package/dist/workspace/template.js.map +1 -1
  91. package/package.json +2 -2
  92. package/dist/publish/siteConfig.js +0 -649
  93. package/dist/publish/siteConfig.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 = "supersdk.json"
22
+ CONFIG_FILENAME = "super.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, output_dir=DIST_DIRNAME):
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):
165
165
  """
166
166
  project_root = Path(project_root)
167
167
  source_root = validate_source(project_root / SRC_DIRNAME)
168
- dist = project_root / DIST_DIRNAME
168
+ dist = project_root / output_dir
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 {project} "
218
- "or ./super_build.sh --platform site --build"
217
+ f"site managed config missing; run scripts/supersdk_template.py inject --platform site --project <projectId> "
218
+ f"or ./super_build.sh --project <projectId> --build (resolved directory: {project})"
219
219
  )
220
220
  try:
221
221
  config = json.loads(config_path.read_text(encoding="utf-8"))
@@ -230,6 +230,7 @@ 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)
233
234
  # 🔴 offline.host 是可选的、由服务端回填的:首次发布成功后 CLI 才把服务端签发的域名
234
235
  # 记回配置。CLI 绝不自己拼域名,所以没有它就**跳过离线打包并显式说明原因** ——
235
236
  # dist 照常产出(publish-site 要的就是它),静默跳过才是不可接受的那一种。
@@ -237,10 +238,10 @@ def package_managed(root, project):
237
238
  # host 缺席不代表可以少校验:版本号照样要合法,dist 照样要产出。
238
239
  validate_version(version.get("name"))
239
240
  validate_source(project_root / SRC_DIRNAME)
240
- dist = build_dist(project_root, config)
241
+ dist = build_dist(project_root, config, output_dir)
241
242
  reason = (
242
243
  f"offline package not built for {project}: projects[].offline.host is not set. "
243
- "Publish the site once so the CLI records the server-issued host, or set it by hand in supersdk.json."
244
+ "Set projects[].offline.host in super.json when an offline package is required."
244
245
  )
245
246
  print(reason, file=sys.stderr)
246
247
  return {"host": None, "version": version.get("name"), "zip": None, "dist": str(dist), "offline_skipped": reason}
@@ -249,7 +250,7 @@ def package_managed(root, project):
249
250
  # Validate host/version/source before anything is written, so a bad host cannot
250
251
  # leave a stale or partly-rendered dist on disk.
251
252
  validate_inputs(project_root / SRC_DIRNAME, host, version.get("name"))
252
- dist = build_dist(project_root, config)
253
+ dist = build_dist(project_root, config, output_dir)
253
254
  # 🔴 output/ 是工作空间级的,但同名 zip 会被 unlink 后 replace:两个站点
254
255
  # 同 host + 同 version 就会互相顶掉。按项目目录分仓,冲突从根上消失。
255
256
  result = package(dist, host, version.get("name"), workspace_root / "output" / project, require_provenance=False)
@@ -0,0 +1,2 @@
1
+ FROM scratch
2
+ LABEL org.opencontainers.image.title="supersdk-simple-service"
@@ -1,5 +1,5 @@
1
1
  {
2
- "schemaVersion": 3,
2
+ "schemaVersion": 4,
3
3
  "spid": "demo0001",
4
4
  "name": "SuperSDK Simple",
5
5
  "version": {
@@ -11,12 +11,14 @@
11
11
  },
12
12
  "projects": [
13
13
  {
14
+ "projectId": "android",
14
15
  "type": "android",
15
16
  "dir": "android",
16
17
  "name": "SuperSDK Simple",
17
18
  "package": "com.supersdk.simple.host"
18
19
  },
19
20
  {
21
+ "projectId": "ios",
20
22
  "type": "ios",
21
23
  "dir": "ios",
22
24
  "name": "SuperSDK Simple",
@@ -24,12 +26,29 @@
24
26
  "spmMode": "mock"
25
27
  },
26
28
  {
29
+ "projectId": "web",
27
30
  "type": "site",
28
31
  "dir": "web",
29
32
  "name": "SuperSDK Simple Web",
33
+ "build": {
34
+ "outputDir": "dist"
35
+ },
30
36
  "offline": {
31
37
  "host": "simple.supersdk.com"
32
38
  }
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": []
33
52
  }
34
53
  ]
35
54
  }
@@ -11,134 +11,60 @@ ORCHESTRATOR="$WORKSPACE_ROOT/scripts/super_build_orchestrator.py"
11
11
 
12
12
  usage() {
13
13
  cat <<'EOF'
14
- Usage: ./super_build.sh [--platform all|android|ios|site] [--project DIR] [--plan|--build] [--force] [--config path]
14
+ Usage: ./super_build.sh [--build|--plan] [--config PATH] [--project PROJECT_ID] [--output-dir DIR] [--cli-version VERSION]
15
15
 
16
16
  Options:
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.
17
+ --build Build selected projects and write super-build-manifest.json.
18
+ --plan Validate and print the fixed-helper plan (default).
19
+ --config PATH Config file (default: <workspace>/super.json).
20
+ --project PROJECT_ID Build exactly one stable projects[].projectId; omit for all.
21
+ --output-dir DIR New portable output directory (default: <workspace>/output).
22
+ --cli-version VERSION Calling SuperCLI version; standalone builds leave it null.
23
+ --help Show this help.
24
24
  EOF
25
25
  }
26
26
 
27
- platform="all"
28
- project=""
29
- config="$WORKSPACE_ROOT/supersdk.json"
30
27
  mode="plan"
28
+ config="$WORKSPACE_ROOT/super.json"
29
+ project=""
30
+ output_dir="$WORKSPACE_ROOT/output"
31
+ cli_version=""
31
32
  mode_set=false
32
- platform_set=false
33
- project_set=false
34
33
  config_set=false
35
- force_set=false
36
- force=false
34
+ project_set=false
35
+ output_set=false
36
+ cli_version_set=false
37
37
 
38
38
  while [ "$#" -gt 0 ]; do
39
39
  case "$1" in
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
- ;;
57
- --project)
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
- ;;
40
+ --help|-h) usage; exit 0 ;;
41
+ --build|--plan)
42
+ if [ "$mode_set" = true ]; then echo "error: mode specified more than once" >&2; exit 2; fi
43
+ mode="${1#--}"; mode_set=true; shift ;;
70
44
  --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
- ;;
45
+ if [ "$config_set" = true ] || [ "$#" -lt 2 ]; then echo "error: --config requires exactly one value" >&2; exit 2; fi
46
+ config="$2"; config_set=true; shift 2 ;;
47
+ --project)
48
+ if [ "$project_set" = true ] || [ "$#" -lt 2 ]; then echo "error: --project requires exactly one value" >&2; exit 2; fi
49
+ project="$2"; project_set=true; shift 2 ;;
50
+ --output-dir)
51
+ if [ "$output_set" = true ] || [ "$#" -lt 2 ]; then echo "error: --output-dir requires exactly one value" >&2; exit 2; fi
52
+ output_dir="$2"; output_set=true; shift 2 ;;
53
+ --cli-version)
54
+ if [ "$cli_version_set" = true ] || [ "$#" -lt 2 ]; then echo "error: --cli-version requires exactly one value" >&2; exit 2; fi
55
+ cli_version="$2"; cli_version_set=true; shift 2 ;;
56
+ *) echo "error: unknown option $1" >&2; exit 2 ;;
114
57
  esac
115
58
  done
116
59
 
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
-
134
60
  if [ "$mode" = "plan" ]; then
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)
61
+ if [ -n "$project" ]; then
62
+ exec "$PYTHON_BIN" "$HELPER" plan --root "$WORKSPACE_ROOT" --config "$config" --project "$project"
63
+ fi
64
+ exec "$PYTHON_BIN" "$HELPER" plan --root "$WORKSPACE_ROOT" --config "$config"
141
65
  fi
142
- "$PYTHON_BIN" "$HELPER" "${inject_args[@]}"
143
66
 
144
- exec "$PYTHON_BIN" "$ORCHESTRATOR" --root "$WORKSPACE_ROOT" --config "$config" "${selection[@]}"
67
+ args=(--root "$WORKSPACE_ROOT" --config "$config" --output-dir "$output_dir")
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[@]}"
@@ -1,6 +1,6 @@
1
1
  {
2
- "engineVersion": "3.0.0",
3
- "schemaVersion": 3,
2
+ "engineVersion": "4.0.0",
3
+ "schemaVersion": 4,
4
4
  "source": "app_repo_example",
5
5
  "comment": [
6
6
  "模板的拆分契约,给 supercli 消费:`init` 落地 workspace 级共享物一次,`add <type> <dir>` 拷贝对应类型的项目模板。",
@@ -17,9 +17,10 @@
17
17
  "projects": {
18
18
  "android": "android",
19
19
  "ios": "ios",
20
- "site": "web"
20
+ "site": "web",
21
+ "service": "service"
21
22
  },
22
23
  "generated": [
23
- "supersdk.json"
24
+ "super.json"
24
25
  ]
25
26
  }
@@ -45,18 +45,14 @@ exports.isValidConfigFile = isValidConfigFile;
45
45
  exports.legacyConfigIn = legacyConfigIn;
46
46
  exports.createWorkspaceConfig = createWorkspaceConfig;
47
47
  exports.appendProject = appendProject;
48
- exports.unsupportedSchemaMessage = unsupportedSchemaMessage;
49
48
  exports.findEnclosingWorkspace = findEnclosingWorkspace;
50
49
  exports.legacyMigrationMessage = legacyMigrationMessage;
51
- // `supersdk.json` v3 —— **工作空间写侧**(`supercli init` / `supercli add`)需要的那部分。
50
+ // `super.json` schema v4 —— **工作空间写侧**(init / add / register)。
52
51
  //
53
- // 一个 workspace = 一个 spid,`supersdk.json` 所在目录即工作空间根。
52
+ // 一个 workspace = 一个 spid,`super.json` 所在目录即工作空间根。
54
53
  //
55
- // 🔴 这里**不再重写一遍校验**。文件的合法性判定只有一份,在 `src/publish/siteConfig.ts` 的
56
- // `parseConfig` / `findConfig`(schemaVersion、退役根键、重复键、spid、projects[].dir 唯一且
57
- // 互不为祖先、deploy[] 形状……)。写侧再写一份「差不多的」校验,等于给同一个文件准备了两套
58
- // 判据:某天两边口径分岔时,就会出现「add 写得出去、publish-site 立刻拒绝」这种同一棵树上
59
- // 两端打架的状态 —— 本轮统一配置要消灭的正是它。
54
+ // 🔴 这里**不再重写一遍校验**。读侧与写后自证都调用 `config/superConfig.ts`
55
+ // 的 strict parser/discovery,与 Python authority 有字节级 parity 测试。
60
56
  //
61
57
  // 本模块只补写侧真正独有的三件事:
62
58
  // 1. 一个**全项目**视角(parseConfig 的产物只暴露站点项目,登记新目录时要跟所有项目比对);
@@ -64,11 +60,11 @@ exports.legacyMigrationMessage = legacyMigrationMessage;
64
60
  // 3. `projects[]` 的追加写入(加锁 → parse → 只改自己那段 → stringify)。
65
61
  const fs = __importStar(require("node:fs"));
66
62
  const path = __importStar(require("node:path"));
63
+ const node_crypto_1 = require("node:crypto");
67
64
  const appConfig_1 = require("../config/appConfig");
68
- const siteConfig_1 = require("../publish/siteConfig");
65
+ const superConfig_1 = require("../config/superConfig");
69
66
  const fsAtomic_1 = require("../util/fsAtomic");
70
67
  const shell_1 = require("../util/shell");
71
- const identity_1 = require("./identity");
72
68
  exports.CONFIG_FILENAME = appConfig_1.APP_CONFIG_FILENAME;
73
69
  exports.SCHEMA_VERSION = appConfig_1.APP_CONFIG_SCHEMA_VERSION;
74
70
  class WorkspaceConfigError extends Error {
@@ -79,10 +75,10 @@ exports.WorkspaceConfigError = WorkspaceConfigError;
79
75
  // ---------------------------------------------------------------------------
80
76
  /**
81
77
  * 归一化一个候选目录,失败时给出**可读的原因**(用于面向用户的报错)。
82
- * 归一化规则本身来自 siteConfig.normalizeProjectDir —— 这里只负责把 `undefined` 翻译成人话。
78
+ * 归一化规则本身来自 superConfig.normalizeProjectDir —— 这里只负责把 `undefined` 翻译成人话。
83
79
  */
84
80
  function checkProjectDir(raw) {
85
- const normalized = (0, siteConfig_1.normalizeProjectDir)(raw);
81
+ const normalized = (0, superConfig_1.normalizeProjectDir)(raw);
86
82
  if (normalized === undefined) {
87
83
  return {
88
84
  error: 'must be a relative POSIX path inside the workspace (no leading "/", no drive letter, ' +
@@ -133,7 +129,7 @@ function projectsOf(document) {
133
129
  continue;
134
130
  if (typeof item.type !== 'string' || typeof item.dir !== 'string')
135
131
  continue;
136
- const normalized = (0, siteConfig_1.normalizeProjectDir)(item.dir);
132
+ const normalized = (0, superConfig_1.normalizeProjectDir)(item.dir);
137
133
  if (normalized === undefined)
138
134
  continue;
139
135
  projects.push({ ...item, type: item.type, dir: normalized });
@@ -142,36 +138,15 @@ function projectsOf(document) {
142
138
  }
143
139
  /** parseConfig / findConfig 的失败结果 → 面向用户的一段话。成功时返回 undefined。 */
144
140
  function describeConfigProblem(result, startDir) {
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
- }
141
+ void startDir;
142
+ return (0, superConfig_1.configProblem)(result);
168
143
  }
169
144
  /**
170
145
  * 从 `startDir` 向上找到工作空间并读出全项目视角。
171
146
  * 查找与校验都走 `findConfig`(发布侧同一份实现),这里只负责把结果翻译成写侧要的形状。
172
147
  */
173
- function loadWorkspace(startDir) {
174
- const found = (0, siteConfig_1.findConfig)(startDir);
148
+ function loadWorkspace(startDir, explicitPath) {
149
+ const found = (0, superConfig_1.findSuperConfig)(startDir, explicitPath);
175
150
  const problem = describeConfigProblem(found, path.resolve(startDir));
176
151
  if (problem !== undefined || found.kind !== 'valid') {
177
152
  return { kind: 'error', message: problem ?? `cannot read ${exports.CONFIG_FILENAME}` };
@@ -209,7 +184,7 @@ function loadWorkspace(startDir) {
209
184
  */
210
185
  function isValidConfigFile(configPath) {
211
186
  try {
212
- return (0, siteConfig_1.parseConfig)(fs.readFileSync(configPath, 'utf8'), configPath).kind === 'valid';
187
+ return (0, superConfig_1.parseSuperConfig)(fs.readFileSync(configPath, 'utf8'), configPath).kind === 'valid';
213
188
  }
214
189
  catch {
215
190
  return false;
@@ -237,7 +212,7 @@ function writePreservingMode(filePath, content) {
237
212
  mode = undefined;
238
213
  }
239
214
  (0, fsAtomic_1.atomicWriteFileSync)(filePath, content);
240
- // atomicWriteFileSync 以 0600 建临时文件再 rename。supersdk.json 是人机共写、通常入库的
215
+ // atomicWriteFileSync 以 0600 建临时文件再 rename。super.json 是人机共写、通常入库的
241
216
  // 普通配置,不该被一次机器写入悄悄收紧成 0600。
242
217
  if (mode !== undefined) {
243
218
  try {
@@ -248,28 +223,66 @@ function writePreservingMode(filePath, content) {
248
223
  }
249
224
  }
250
225
  }
251
- /** 写出前自证:写出去的东西必须能被**发布侧同一个解析器**读回来。 */
226
+ /** 写出前自证:写出去的东西必须能被 strict parser 读回来。 */
252
227
  function serializeVerified(configPath, document) {
253
228
  const serialized = (0, appConfig_1.serializeAppConfig)(document);
254
- const verified = (0, siteConfig_1.parseConfig)(serialized, configPath);
229
+ const verified = (0, superConfig_1.parseSuperConfig)(serialized, configPath);
255
230
  if (verified.kind !== 'valid') {
256
231
  const detail = verified.kind === 'invalid' ? verified.reason : verified.kind;
257
232
  throw new WorkspaceConfigError(`refusing to write an invalid ${exports.CONFIG_FILENAME}: ${detail}`);
258
233
  }
259
234
  return serialized;
260
235
  }
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
+ }
261
247
  /**
262
- * 首次落盘。用 `wx` 独占创建:`supersdk.json` 已存在时**必须**失败而不是覆盖 ——
263
- * 覆盖会把一个已有工作空间的 projects[] / orgId 整份抹掉。
248
+ * 首次落盘:同目录临时文件完整写入并 fsync,再用 hard-link 做原子 no-clobber 安装。
249
+ * `link` 与目标已存在检查是同一个原子操作,因此并发创建也绝不覆盖已有 projects[] / orgId。
264
250
  */
265
- function createWorkspaceConfig(configPath, document) {
251
+ function createWorkspaceConfig(configPath, document, hooks = {}) {
266
252
  const serialized = serializeVerified(configPath, document);
267
- fs.mkdirSync(path.dirname(configPath), { recursive: true });
268
- fs.writeFileSync(configPath, serialized, { encoding: 'utf8', flag: 'wx' });
253
+ const directory = path.dirname(configPath);
254
+ fs.mkdirSync(directory, { recursive: true });
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
+ }
269
282
  }
270
283
  /**
271
- * `加锁 → parse → 只改 projects[] → stringify`。整份文档在**锁内**从磁盘重新读取,未知键随
272
- * 对象一并带回,只有 projects 一处被触碰。
284
+ * `加锁 → parse → 只改 projects[] → stringify`。整份文档在**锁内**从磁盘重新读取,
285
+ * 只有 projects 一处被触碰。
273
286
  *
274
287
  * 🔴 跨进程锁不是可选项:`readFileSync → 改 → atomicWriteFileSync` 里的 atomic rename 只保证
275
288
  * 文件不撕裂,**不防 lost update**。两个 `supercli add` 并行时,后写者会把先写者刚落盘的条目
@@ -280,7 +293,7 @@ function appendProject(configPath, entry) {
280
293
  try {
281
294
  // 必须在锁内重读:锁外读到的可能已被其他进程改写。
282
295
  const before = fs.readFileSync(configPath, 'utf8');
283
- const gate = (0, siteConfig_1.parseConfig)(before, configPath);
296
+ const gate = (0, superConfig_1.parseSuperConfig)(before, configPath);
284
297
  if (gate.kind !== 'valid') {
285
298
  const detail = gate.kind === 'invalid' ? gate.reason : gate.kind;
286
299
  throw new WorkspaceConfigError(`refusing to write an unparseable ${exports.CONFIG_FILENAME}: ${detail}`);
@@ -301,73 +314,16 @@ function appendProject(configPath, entry) {
301
314
  }
302
315
  }
303
316
  // ---------------------------------------------------------------------------
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
- // ---------------------------------------------------------------------------
360
317
  // 工作空间嵌套
361
318
  // ---------------------------------------------------------------------------
362
319
  /**
363
320
  * `target` **之上**是否已经有一份工作空间配置;有就返回最近的那份的路径。
364
321
  *
365
- * 🔴 为什么 `init` 必须查这个:`findConfig` 是「从 cwd 向上找到第一份就停」,所以嵌套出来的
366
- * 内层 `supersdk.json` 会**遮蔽**外层 —— 之后每一次 `add` / `publish-site` 都悄悄绑到内层那个
367
- * spid 上,两份配置各自漂移,全程零告警。`add` 早就把「项目目录不得互为祖先」当硬失败
322
+ * 🔴 为什么 `init` 必须查这个:嵌套的 `super.json` 会让不同 cwd 选中不同权威,之后每一次
323
+ * `add` / `build` / `deploy` 都可能绑到不同 spid。`add` 早就把「项目目录不得互为祖先」当硬失败
368
324
  * (findDirConflict),`init` 不查就等于在同一棵树上给了两套判据。
369
325
  *
370
- * 判定复用 `findConfig` 而不是另写一次向上遍历:停止边界(.git 仓库根 / 家目录 / 文件系统根 /
326
+ * 判定复用 `findSuperConfig` 而不是另写一次向上遍历:停止边界(.git 仓库根 / 家目录 / 文件系统根 /
371
327
  * 深度上限)必须与真正会去读配置的那条路径逐字一致,否则「init 说不嵌套、add 却找到了外层」。
372
328
  */
373
329
  function findEnclosingWorkspace(target) {
@@ -375,18 +331,15 @@ function findEnclosingWorkspace(target) {
375
331
  const parent = path.dirname(resolved);
376
332
  if (parent === resolved)
377
333
  return undefined;
378
- const found = (0, siteConfig_1.findConfig)(parent);
334
+ const found = (0, superConfig_1.findSuperConfig)(parent);
379
335
  switch (found.kind) {
380
336
  case 'valid':
381
337
  return found.config.path;
382
- // 这两种只可能来自一个真实存在的 supersdk.json(v2 的、或写坏了的)—— 一样会遮蔽。
383
- case 'unsupported-schema':
338
+ // 写坏的 v4 或 discovery chain 上的 legacy 配置一样会遮蔽。
384
339
  case 'invalid':
385
340
  return found.path;
386
- // 上层是退役 YAML:它不参与 supersdk.json 的向上查找,只有同目录确实还有一份 JSON 时才算嵌套。
387
- case 'legacy-app-yaml':
388
- case 'legacy-site-yml':
389
- return found.existingConfigPath;
341
+ case 'ambiguous':
342
+ return found.paths[0];
390
343
  case 'absent':
391
344
  return undefined;
392
345
  default: {
@@ -405,7 +358,7 @@ function findEnclosingWorkspace(target) {
405
358
  * required field is a dead end, so the skeleton carries the complete set.
406
359
  *
407
360
  * 两种情形,动作顺序不同(且不能反):
408
- * - 目录里**已经有一份合法的 supersdk.json** → 没有任何字段需要搬运,只发 `rm <legacy>`。
361
+ * - 目录里**已经有一份合法的 super.json** → 没有任何字段需要搬运,只发 `rm <legacy>`。
409
362
  * 再让人照抄一遍 `cat >` 会用占位值覆盖掉他已经写好的真配置。
410
363
  * - 没有 → 先写新文件、**再**删旧文件:旧文件是字段的唯一来源,先删就没得抄了。
411
364
  */
@@ -413,7 +366,7 @@ function legacyMigrationMessage(yamlPath, jsonAlreadyValid = false) {
413
366
  const legacyName = path.basename(yamlPath);
414
367
  const dir = path.dirname(yamlPath);
415
368
  const head = [
416
- `${legacyName} (retired schema_version: 1 dialect) is no longer supported — supercli reads ` +
369
+ `${legacyName} is a retired configuration and is no longer read — supercli reads ` +
417
370
  `${exports.CONFIG_FILENAME} (schemaVersion ${exports.SCHEMA_VERSION}) only, and there is no compatibility fallback.`,
418
371
  `found: ${yamlPath}`,
419
372
  '',
@@ -427,6 +380,15 @@ function legacyMigrationMessage(yamlPath, jsonAlreadyValid = false) {
427
380
  `rm ${(0, shell_1.shellQuote)(legacyName)}`,
428
381
  ].join('\n');
429
382
  }
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
+ }
430
392
  return [
431
393
  ...head,
432
394
  'Migrate it once — replace the placeholder values with the ones already in your YAML, then run:',