@dazitech/cli 3.0.1 → 3.0.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.
package/README.md CHANGED
@@ -78,7 +78,7 @@ pnpm run publish:cli
78
78
 
79
79
  ```powershell
80
80
  # 全局
81
- pnpm add -g @dazitech/cli@3.0.0
81
+ pnpm add -g @dazitech/cli@3.0.3
82
82
 
83
83
  # 确认 PATH(pnpm 全局 bin)
84
84
  pnpm bin -g
@@ -91,7 +91,7 @@ dazi auth whoami
91
91
  在 `dazi-work` 根目录:
92
92
 
93
93
  ```powershell
94
- dazi flow project status --dir "项目\flow_xxx\流程\MyFlow"
94
+ dazi flow project status --dir "D:\path\to\dazi-work\项目\<业务名>\流程\flows\MyFlow"
95
95
  ```
96
96
 
97
97
  ## 项目内安装(可选)
@@ -13775,7 +13775,7 @@ function applyPlaceholdersInTree(targetDir, ph, oldAppId = "${appId}") {
13775
13775
  walk(targetDir);
13776
13776
  }
13777
13777
  function replacePlaceholders(text, ph, oldAppId) {
13778
- return text.split("${appId}").join(ph.appId).split("${spaceId}").join(ph.spaceId).split("${appName}").join(ph.appName).split("space__demo").join(ph.spaceId).split(`/runtime-apps/${oldAppId}`).join(`/runtime-apps/${ph.appId}`).split(oldAppId).join(ph.appId);
13778
+ return text.split('"${spaceId}"').join(JSON.stringify(ph.spaceId)).split("${appId}").join(ph.appId).split("${spaceId}").join(ph.spaceId).split("${appName}").join(ph.appName).split("space__demo").join(ph.spaceId).split(`/runtime-apps/${oldAppId}`).join(`/runtime-apps/${ph.appId}`).split(oldAppId).join(ph.appId);
13779
13779
  }
13780
13780
  function writeContextMd(targetDir, ph) {
13781
13781
  const aiDir = import_node_path9.default.join(targetDir, ".ai");
@@ -13910,6 +13910,34 @@ function parseDataspaceId(permissions) {
13910
13910
  }
13911
13911
  return void 0;
13912
13912
  }
13913
+ function resolveManifestSpaceId(manifest) {
13914
+ const fromField = String(manifest.space_id ?? "").trim();
13915
+ if (fromField) return fromField;
13916
+ return parseDataspaceId(manifest.permissions);
13917
+ }
13918
+ function syncManifestSpace(cwd, spaceId) {
13919
+ const sid = spaceId.trim();
13920
+ if (!sid) throw new Error("spaceId \u4E0D\u80FD\u4E3A\u7A7A");
13921
+ const manifestPath = import_node_path10.default.join(cwd, "manifest.json");
13922
+ const manifest = JSON.parse(
13923
+ import_node_fs11.default.readFileSync(manifestPath, "utf8")
13924
+ );
13925
+ const previous = resolveManifestSpaceId(manifest);
13926
+ const required = `dataspace:${sid}`;
13927
+ const perms = Array.isArray(manifest.permissions) ? manifest.permissions.map((p) => String(p).trim()) : [];
13928
+ const nextPerms = [
13929
+ ...perms.filter((p) => !p.startsWith("dataspace:")),
13930
+ required
13931
+ ];
13932
+ const changed = manifest.space_id !== sid || JSON.stringify(manifest.permissions) !== JSON.stringify(nextPerms);
13933
+ manifest.space_id = sid;
13934
+ manifest.permissions = nextPerms;
13935
+ if (changed) {
13936
+ import_node_fs11.default.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}
13937
+ `, "utf8");
13938
+ }
13939
+ return { changed, previous: previous ?? void 0 };
13940
+ }
13913
13941
  function validateDataSource(ds, index, projectRoot) {
13914
13942
  const base = `data_sources[${index}]`;
13915
13943
  const issues = [];
@@ -14229,23 +14257,55 @@ function validateManifestRecord(manifest, opts) {
14229
14257
  }
14230
14258
  }
14231
14259
  }
14260
+ const declaredSpace = String(manifest.space_id ?? "").trim();
14232
14261
  const perms = manifest.permissions;
14233
- if (!Array.isArray(perms) || perms.length === 0) {
14262
+ const permSpace = parseDataspaceId(perms);
14263
+ if (!declaredSpace && !permSpace) {
14234
14264
  issues.push(
14235
14265
  issue(
14236
14266
  "error",
14237
- "PERMISSIONS_REQUIRED",
14238
- "permissions",
14239
- "\u81F3\u5C11\u58F0\u660E permissions\uFF08\u5982 dataspace:<spaceId>\uFF09"
14267
+ "SPACE_ID_REQUIRED",
14268
+ "space_id",
14269
+ "\u987B\u914D\u7F6E space_id\uFF08\u63A8\u8350\uFF09\u6216 permissions \u4E2D\u7684 dataspace:<\u7A7A\u95F4Id>"
14240
14270
  )
14241
14271
  );
14242
- } else if (!parseDataspaceId(perms)) {
14272
+ } else if (declaredSpace && permSpace && declaredSpace !== permSpace) {
14273
+ issues.push(
14274
+ issue(
14275
+ "error",
14276
+ "SPACE_ID_MISMATCH",
14277
+ "space_id",
14278
+ `space_id=${JSON.stringify(declaredSpace)} \u4E0E permissions dataspace:${permSpace} \u4E0D\u4E00\u81F4`
14279
+ )
14280
+ );
14281
+ }
14282
+ if (!Array.isArray(perms) || perms.length === 0) {
14283
+ if (!declaredSpace) {
14284
+ issues.push(
14285
+ issue(
14286
+ "error",
14287
+ "PERMISSIONS_REQUIRED",
14288
+ "permissions",
14289
+ "\u81F3\u5C11\u58F0\u660E permissions\uFF08\u5982 dataspace:<spaceId>\uFF09\u6216\u914D\u7F6E space_id"
14290
+ )
14291
+ );
14292
+ } else {
14293
+ issues.push(
14294
+ issue(
14295
+ "warning",
14296
+ "PERMISSIONS_DATASPACE",
14297
+ "permissions",
14298
+ `upload \u65F6\u5C06\u81EA\u52A8\u8865\u9F50 dataspace:${declaredSpace}`
14299
+ )
14300
+ );
14301
+ }
14302
+ } else if (!permSpace && !declaredSpace) {
14243
14303
  issues.push(
14244
14304
  issue(
14245
14305
  "warning",
14246
14306
  "PERMISSIONS_DATASPACE",
14247
14307
  "permissions",
14248
- "\u672A\u627E\u5230 dataspace:<id>\uFF0Cupload \u65F6\u9700 --space \u6216\u8865\u5168 permissions"
14308
+ "\u672A\u627E\u5230 dataspace:<id>\uFF1B\u8BF7\u914D\u7F6E manifest.space_id"
14249
14309
  )
14250
14310
  );
14251
14311
  }
@@ -14409,7 +14469,7 @@ function validateManifest(cwd, opts = {}) {
14409
14469
  manifestPath,
14410
14470
  appId: String(manifest.appId ?? "").trim() || void 0,
14411
14471
  version: String(manifest.version ?? "").trim() || void 0,
14412
- spaceId: parseDataspaceId(manifest.permissions),
14472
+ spaceId: resolveManifestSpaceId(manifest),
14413
14473
  dataSourceKeys,
14414
14474
  kinds: [...kindSet],
14415
14475
  issues,
@@ -14564,6 +14624,22 @@ function registerUpload(program3) {
14564
14624
  program3.command("upload").description("\u6253\u5305\u5E76\u4E0A\u4F20\u5230 Registry\uFF08\u65E0 app \u5219\u5148 create\uFF09").option("--cwd <dir>", "DRAP \u9879\u76EE\u76EE\u5F55\uFF08\u9ED8\u8BA4\u81EA\u52A8\u8BC6\u522B\uFF1Ashell \u76EE\u5F55\u6216\u542B manifest.json \u7684\u7956\u5148\uFF09").option("--space <id>", "\u6570\u636E\u7A7A\u95F4 id\uFF08\u5FC5\u586B\uFF0C\u9996\u6B21 create\uFF09").option("--activate", "\u4E0A\u4F20\u540E\u6FC0\u6D3B", false).option("--changelog <text>", "\u53D8\u66F4\u8BF4\u660E").option("--file <path>", "\u5DF2\u6709 .dazi-app\uFF0C\u8DF3\u8FC7 package").option("--skip-validate", "\u8DF3\u8FC7 manifest \u6821\u9A8C\uFF08\u4E0D\u63A8\u8350\uFF09").option("--no-source", "\u4E0D\u4E0A\u4F20\u6E90\u7801\u5FEB\u7167\uFF08\u9ED8\u8BA4\u4E0A\u4F20\uFF0C\u4F9B release \u8F6C\u6A21\u677F\uFF09").option("--json").action(async (opts) => {
14565
14625
  if (!loadAuth()) throw new Error("\u8BF7\u5148 dazi-app auth login");
14566
14626
  const cwd = requireProjectCwd(opts.cwd);
14627
+ const manifestEarly = JSON.parse(
14628
+ import_node_fs13.default.readFileSync(import_node_path12.default.join(cwd, "manifest.json"), "utf8")
14629
+ );
14630
+ const uploadSpaceId = String(opts.space || "").trim() || resolveManifestSpaceId(manifestEarly) || "";
14631
+ if (!uploadSpaceId) {
14632
+ throw new Error(
14633
+ "manifest \u987B\u914D\u7F6E space_id\uFF0C\u6216 permissions \u542B dataspace:<\u7A7A\u95F4Id>\uFF1B\u4E5F\u53EF upload --space <id>"
14634
+ );
14635
+ }
14636
+ const sync = syncManifestSpace(cwd, uploadSpaceId);
14637
+ if (sync.changed && !opts.json) {
14638
+ const prev = sync.previous ? `\uFF08\u539F ${sync.previous}\uFF09` : "";
14639
+ console.warn(
14640
+ `\u5DF2\u540C\u6B65 manifest space_id / permissions \u2192 ${uploadSpaceId}${prev}`
14641
+ );
14642
+ }
14567
14643
  if (!opts.skipValidate) {
14568
14644
  const vr = validateManifest(cwd, { scanSrc: true });
14569
14645
  if (!vr.ok) {
@@ -15416,10 +15492,13 @@ function registerInit(program3) {
15416
15492
  const manifest = JSON.parse(import_node_fs22.default.readFileSync(manifestPath, "utf8"));
15417
15493
  manifest.appId = appId;
15418
15494
  manifest.name = appName;
15495
+ manifest.space_id = spaceId;
15419
15496
  if (Array.isArray(manifest.permissions)) {
15420
15497
  manifest.permissions = manifest.permissions.map(
15421
15498
  (p) => p.startsWith("dataspace:") ? `dataspace:${spaceId}` : p
15422
15499
  );
15500
+ } else {
15501
+ manifest.permissions = [`dataspace:${spaceId}`];
15423
15502
  }
15424
15503
  import_node_fs22.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
15425
15504
  patchPackageJsonForApp(outDir, appId, appName);
@@ -16672,7 +16751,9 @@ function registerLegacyCompatCommands(program3) {
16672
16751
 
16673
16752
  // cli/dazi-app/src/index.ts
16674
16753
  var program2 = new Command();
16675
- program2.name("dazi-app").description("\u642D\u5B50 App CLI \u2014 DRAP \u524D\u7AEF\u5E94\u7528\uFF08manifest / build / upload / preview\uFF09").version("3.0.0", "-v, --version");
16754
+ program2.name("dazi-app").description(
16755
+ "\u642D\u5B50 App CLI \u2014 DRAP \u524D\u7AEF\u5E94\u7528\uFF08manifest / build / upload / preview\uFF09"
16756
+ ).version("3.0.3", "-v, --version");
16676
16757
  registerAuth(program2);
16677
16758
  registerBuild(program2);
16678
16759
  registerDev(program2);