@hcmai/cli 0.21.6 → 0.21.8
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/index.js +66 -57
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9782,6 +9782,9 @@ import {
|
|
|
9782
9782
|
inferMiniWritableTemplateOptionsFromModel,
|
|
9783
9783
|
listWorkspaceFiles,
|
|
9784
9784
|
loadWorkspaceFileContent,
|
|
9785
|
+
MINI_CONTEXT_FILE,
|
|
9786
|
+
MINI_PULL_MANIFEST_FILE,
|
|
9787
|
+
MINI_STATE_DIR,
|
|
9785
9788
|
pullMiniAppProject,
|
|
9786
9789
|
pushMiniAppProject,
|
|
9787
9790
|
runMiniSmokeChecks,
|
|
@@ -9971,14 +9974,7 @@ async function workspaceActiveCommand(args) {
|
|
|
9971
9974
|
fallbackEnv: localContext?.profile
|
|
9972
9975
|
});
|
|
9973
9976
|
const client3 = HcmClient22.fromAuthContext(ctx);
|
|
9974
|
-
const
|
|
9975
|
-
if (response.data?.success === false) {
|
|
9976
|
-
throw new Error("\u5F00\u53D1\u6001\u72B6\u6001\u67E5\u8BE2\u5931\u8D25\uFF0C\u4E0D\u80FD\u5224\u65AD\u662F\u5426\u5DF2\u6FC0\u6D3B\uFF1B\u8BF7\u68C0\u67E5 /api/tenant-extension/dev-mode \u54CD\u5E94\u3002");
|
|
9977
|
-
}
|
|
9978
|
-
const binding = unwrapWorkspaceActionPayload(response.data);
|
|
9979
|
-
if (!binding || typeof binding.enabled !== "boolean" || binding.enabled && !optionalText(binding.workspaceKey)) {
|
|
9980
|
-
throw new Error("\u5F00\u53D1\u6001\u67E5\u8BE2\u8FD4\u56DE\u65E0\u6548\u6570\u636E\uFF0C\u4E0D\u80FD\u5224\u65AD\u662F\u5426\u5DF2\u6FC0\u6D3B\uFF1B\u8BF7\u68C0\u67E5 /api/tenant-extension/dev-mode \u54CD\u5E94\u3002");
|
|
9981
|
-
}
|
|
9977
|
+
const binding = await readWorkspaceDevModeBinding(client3);
|
|
9982
9978
|
const activeWorkspaceKey = binding.enabled ? optionalText(binding.workspaceKey) : null;
|
|
9983
9979
|
const bindingUpdatedAt = typeof binding.updatedAt === "number" && Number.isFinite(binding.updatedAt) && binding.updatedAt > 0 && binding.updatedAt <= 864e13 ? binding.updatedAt : null;
|
|
9984
9980
|
const view = {
|
|
@@ -10335,13 +10331,11 @@ async function workspaceValidateCommand(args) {
|
|
|
10335
10331
|
exitWorkspaceError(e);
|
|
10336
10332
|
}
|
|
10337
10333
|
}
|
|
10338
|
-
function isScriptPath(relativePath) {
|
|
10339
|
-
return relativePath.startsWith("scripts/");
|
|
10340
|
-
}
|
|
10341
10334
|
async function workspacePushCommand(args) {
|
|
10342
10335
|
try {
|
|
10343
10336
|
await withWorkspacePushProgress(async (bindHttp, assertRunning) => {
|
|
10344
10337
|
const rootDir = resolveRootDir(args.dir);
|
|
10338
|
+
await assertWorkspacePushRoot(rootDir);
|
|
10345
10339
|
const context = await requireWorkspaceContext(rootDir);
|
|
10346
10340
|
const miniApps = await discoverMiniApps(rootDir);
|
|
10347
10341
|
for (const app of miniApps) {
|
|
@@ -10357,25 +10351,8 @@ async function workspacePushCommand(args) {
|
|
|
10357
10351
|
await getActiveAuthContextFromCli(args, { fallbackEnv: context.profile })
|
|
10358
10352
|
);
|
|
10359
10353
|
bindHttp(client3.raw());
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
const plan = await pushWorkspaceRawFiles({
|
|
10363
|
-
http: client3.raw(),
|
|
10364
|
-
rootDir,
|
|
10365
|
-
context,
|
|
10366
|
-
dryRun: true
|
|
10367
|
-
});
|
|
10368
|
-
const scriptOps = plan.operations.filter(
|
|
10369
|
-
(op) => isScriptPath(op.remotePath ?? op.localPath)
|
|
10370
|
-
);
|
|
10371
|
-
if (scriptOps.length > 0) {
|
|
10372
|
-
throw new Error(
|
|
10373
|
-
`\u672C\u6B21\u4F1A\u5199 ${scriptOps.length} \u4E2A\u811A\u672C\uFF0C\u4F46\u5F53\u524D\u6FC0\u6D3B\u7684\u5F00\u53D1\u7A7A\u95F4\u662F ${activeWorkspaceKey ? `"${activeWorkspaceKey}"` : "\uFF08\u672A\u6FC0\u6D3B\uFF09"}\uFF0C\u4E0D\u662F\u672C\u7A7A\u95F4 "${context.workspaceKey}"\u3002
|
|
10374
|
-
\u670D\u52A1\u7AEF\u4F1A\u62D2\u7EDD\u5199\u811A\u672C\uFF0C\u800C\u975E\u811A\u672C\u6587\u4EF6\u5DF2\u7ECF\u5199\u8FDB\u53BB\u4E86 \u2014\u2014 \u90A3\u4F1A\u7559\u4E0B\u534A\u63A8\u9001\u72B6\u6001\u3002
|
|
10375
|
-
\u4E0B\u4E00\u6B65\uFF1Ahcm workspace activate ${context.workspaceKey}
|
|
10376
|
-
\u6D89\u53CA\u811A\u672C\uFF1A${scriptOps.map((op) => op.remotePath ?? op.localPath).join(", ")}`
|
|
10377
|
-
);
|
|
10378
|
-
}
|
|
10354
|
+
if (!args.dryRun) {
|
|
10355
|
+
requireWorkspaceActivation(await probeActiveWorkspaceKey(client3), context.workspaceKey);
|
|
10379
10356
|
}
|
|
10380
10357
|
const rawResult = await pushWorkspaceRawFiles({
|
|
10381
10358
|
http: client3.raw(),
|
|
@@ -10392,15 +10369,11 @@ async function workspacePushCommand(args) {
|
|
|
10392
10369
|
});
|
|
10393
10370
|
results.push({ app, result });
|
|
10394
10371
|
}
|
|
10395
|
-
const hint = activationHint(
|
|
10396
|
-
activeWorkspaceKey ?? await probeActiveWorkspaceKey(client3),
|
|
10397
|
-
context.workspaceKey ?? null
|
|
10398
|
-
);
|
|
10399
10372
|
assertRunning();
|
|
10400
10373
|
writeWorkspacePushResult(rawResult, results, args.output ?? "table");
|
|
10401
|
-
if (
|
|
10402
|
-
|
|
10403
|
-
|
|
10374
|
+
if (!args.dryRun) {
|
|
10375
|
+
requireWorkspaceActivation(await probeActiveWorkspaceKey(client3), context.workspaceKey, true);
|
|
10376
|
+
}
|
|
10404
10377
|
process.exitCode = rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0;
|
|
10405
10378
|
}, args.env ?? args.profile);
|
|
10406
10379
|
return;
|
|
@@ -10544,6 +10517,42 @@ function removedMiniCommand() {
|
|
|
10544
10517
|
function resolveRootDir(dir) {
|
|
10545
10518
|
return path9.resolve(dir ?? ".");
|
|
10546
10519
|
}
|
|
10520
|
+
async function workspacePathExists(file) {
|
|
10521
|
+
try {
|
|
10522
|
+
await fs8.access(file);
|
|
10523
|
+
return true;
|
|
10524
|
+
} catch (e) {
|
|
10525
|
+
if (e.code === "ENOENT") return false;
|
|
10526
|
+
throw e;
|
|
10527
|
+
}
|
|
10528
|
+
}
|
|
10529
|
+
async function assertWorkspacePushRoot(rootDir) {
|
|
10530
|
+
const realRoot = await fs8.realpath(rootDir);
|
|
10531
|
+
let workspaceRoot;
|
|
10532
|
+
let insideMiniApp = false;
|
|
10533
|
+
let dir = realRoot;
|
|
10534
|
+
for (; ; ) {
|
|
10535
|
+
const parent = path9.dirname(dir);
|
|
10536
|
+
const appsDir = path9.basename(dir) === MINI_APPS_DIR ? dir : path9.basename(parent) === MINI_APPS_DIR ? parent : void 0;
|
|
10537
|
+
const miniDir = appsDir !== void 0 && (await workspacePathExists(path9.join(path9.dirname(appsDir), WORKSPACE_CONTEXT_FILE)) || appsDir === parent && await workspacePathExists(path9.join(dir, "manifest.json"))) || await workspacePathExists(path9.join(dir, MINI_CONTEXT_FILE)) || await workspacePathExists(path9.join(dir, MINI_STATE_DIR, MINI_PULL_MANIFEST_FILE));
|
|
10538
|
+
insideMiniApp ||= miniDir;
|
|
10539
|
+
if (!miniDir && await workspacePathExists(path9.join(dir, WORKSPACE_CONTEXT_FILE))) {
|
|
10540
|
+
workspaceRoot = dir;
|
|
10541
|
+
break;
|
|
10542
|
+
}
|
|
10543
|
+
if (parent === dir) break;
|
|
10544
|
+
dir = parent;
|
|
10545
|
+
}
|
|
10546
|
+
if (!insideMiniApp && (!workspaceRoot || workspaceRoot === realRoot)) return;
|
|
10547
|
+
const target = workspaceRoot ? `'${workspaceRoot.replace(/'/g, "'\\''")}'` : "<workspace-root>";
|
|
10548
|
+
throw new CliError25({
|
|
10549
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10550
|
+
message: `workspace push \u5FC5\u987B\u4ECE workspace \u6839\u76EE\u5F55\u6267\u884C\uFF0C\u5F53\u524D\u76EE\u5F55 ${rootDir} \u662F${insideMiniApp ? "\u8F7B\u5E94\u7528\u76EE\u5F55\u6216\u5176\u5B50\u76EE\u5F55" : "\u5DE5\u4F5C\u533A\u5B50\u76EE\u5F55"}\uFF1B\u7EE7\u7EED\u4F1A\u8DF3\u8FC7\u8F7B\u5E94\u7528\u90E8\u7F72\u3002`,
|
|
10551
|
+
context: {
|
|
10552
|
+
nextStep: `${workspaceRoot ? `workspace \u6839\u76EE\u5F55\uFF1A${workspaceRoot}\u3002` : `\u672A\u627E\u5230\u4E0A\u5C42 ${WORKSPACE_CONTEXT_FILE}\uFF1B\u8BF7\u5148\u5B9A\u4F4D\u5305\u542B mini_apps/ \u7684 workspace \u6839\u76EE\u5F55\u3002`}\u6267\u884C hcm workspace push --dir ${target}\uFF0C\u4FDD\u7559\u539F\u6709 --env/--as \u7B49\u9009\u9879\u3002`
|
|
10553
|
+
}
|
|
10554
|
+
});
|
|
10555
|
+
}
|
|
10547
10556
|
function buildWorkspaceContext(args) {
|
|
10548
10557
|
return {
|
|
10549
10558
|
kind: WORKSPACE_CONTEXT_KIND,
|
|
@@ -11351,28 +11360,28 @@ function exitWorkspaceError(err, profile) {
|
|
|
11351
11360
|
}
|
|
11352
11361
|
exitWithError(translated);
|
|
11353
11362
|
}
|
|
11354
|
-
async function
|
|
11355
|
-
|
|
11356
|
-
|
|
11357
|
-
|
|
11358
|
-
fields: ["workspaceKey", "devModeEnabled"],
|
|
11359
|
-
limit: 1
|
|
11360
|
-
});
|
|
11361
|
-
return optionalText(result.rows[0]?.workspaceKey) ?? null;
|
|
11362
|
-
} catch {
|
|
11363
|
-
return null;
|
|
11364
|
-
}
|
|
11365
|
-
}
|
|
11366
|
-
function activationHint(activeKey, localKey) {
|
|
11367
|
-
if (localKey && activeKey === localKey) {
|
|
11368
|
-
return null;
|
|
11363
|
+
async function readWorkspaceDevModeBinding(client3) {
|
|
11364
|
+
const response = await client3.raw().get("/api/tenant-extension/dev-mode");
|
|
11365
|
+
if (response.data?.success === false) {
|
|
11366
|
+
throw new Error("\u5F00\u53D1\u6001\u72B6\u6001\u67E5\u8BE2\u5931\u8D25\uFF0C\u4E0D\u80FD\u5224\u65AD\u662F\u5426\u5DF2\u6FC0\u6D3B\uFF1B\u8BF7\u68C0\u67E5 /api/tenant-extension/dev-mode \u54CD\u5E94\u3002");
|
|
11369
11367
|
}
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11368
|
+
const binding = unwrapWorkspaceActionPayload(response.data);
|
|
11369
|
+
if (!binding || typeof binding.enabled !== "boolean" || binding.enabled && !optionalText(binding.workspaceKey)) {
|
|
11370
|
+
throw new Error("\u5F00\u53D1\u6001\u67E5\u8BE2\u8FD4\u56DE\u65E0\u6548\u6570\u636E\uFF0C\u4E0D\u80FD\u5224\u65AD\u662F\u5426\u5DF2\u6FC0\u6D3B\uFF1B\u8BF7\u68C0\u67E5 /api/tenant-extension/dev-mode \u54CD\u5E94\u3002");
|
|
11373
11371
|
}
|
|
11374
|
-
return
|
|
11375
|
-
|
|
11372
|
+
return binding;
|
|
11373
|
+
}
|
|
11374
|
+
async function probeActiveWorkspaceKey(client3) {
|
|
11375
|
+
const binding = await readWorkspaceDevModeBinding(client3);
|
|
11376
|
+
return binding.enabled ? optionalText(binding.workspaceKey) : null;
|
|
11377
|
+
}
|
|
11378
|
+
function requireWorkspaceActivation(activeKey, workspaceKey, afterPush = false) {
|
|
11379
|
+
if (activeKey === workspaceKey) return;
|
|
11380
|
+
throw new CliError25({
|
|
11381
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
11382
|
+
message: (afterPush ? "\u63A8\u9001\u540E\u7ED1\u5B9A\u5DF2\u53D8\u5316\uFF0C\u6587\u4EF6\u53EF\u80FD\u5DF2\u4FDD\u5B58\u4E3A\u8349\u7A3F\uFF1B" : "") + (activeKey ? `\u5F53\u524D\u8EAB\u4EFD\u6FC0\u6D3B\u7684\u662F "${activeKey}"\uFF0C\u4E0D\u662F\u672C\u7A7A\u95F4 "${workspaceKey}"\uFF1B\u672C\u7A7A\u95F4\u5185\u5BB9\u5C1A\u672A\u7528\u4E8E\u5F00\u53D1\u9884\u89C8\u3002` : `\u5F53\u524D\u8EAB\u4EFD\u672A\u6FC0\u6D3B\u5F00\u53D1\u7A7A\u95F4 "${workspaceKey}"\uFF1B\u672C\u7A7A\u95F4\u5185\u5BB9\u5C1A\u672A\u7528\u4E8E\u5F00\u53D1\u9884\u89C8\u3002`),
|
|
11383
|
+
context: { workspaceKey, activeWorkspaceKey: activeKey, nextStep: `hcm workspace activate ${workspaceKey}` }
|
|
11384
|
+
});
|
|
11376
11385
|
}
|
|
11377
11386
|
async function setDevModeBinding(client3, workspaceKey) {
|
|
11378
11387
|
await client3.raw().put("/api/tenant-extension/dev-mode", {
|