ai-project-manage-cli 6.0.58 → 6.0.59

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 CHANGED
@@ -149,13 +149,11 @@ var CLI_TEMPLATE_DIR = resolve2(__dirname, "../template");
149
149
  function workspaceApmDir(cwd = resolveWorkdirPath()) {
150
150
  return resolve2(resolve2(cwd), ".apm");
151
151
  }
152
- function assertWorkspaceApmDirExists(workdir) {
152
+ function isWorkspaceApmInitialized(workdir) {
153
153
  const apmDir = workspaceApmDir(workdir);
154
154
  const fsApmDir = toFsPath(apmDir);
155
155
  if (!existsSync(fsApmDir)) {
156
- throw new Error(
157
- `\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u4E0B\u672A\u68C0\u6D4B\u5230 .apm \u76EE\u5F55\uFF0C\u8BF7\u5728\u8BE5\u4ED3\u5E93\u6839\u76EE\u5F55\u6267\u884C apm init \u5B8C\u6210\u63A5\u5165\u3002`
158
- );
156
+ return false;
159
157
  }
160
158
  const st = statSync(fsApmDir);
161
159
  if (!st.isDirectory()) {
@@ -163,6 +161,7 @@ function assertWorkspaceApmDirExists(workdir) {
163
161
  `\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u4E0B\u7684 .apm \u4E0D\u662F\u76EE\u5F55\uFF0C\u8BF7\u68C0\u67E5\u672C\u5730\u63A5\u5165\u72B6\u6001\u3002`
164
162
  );
165
163
  }
164
+ return readdirSync(fsApmDir).length > 0;
166
165
  }
167
166
  var APM_GITIGNORE_PATTERNS = [
168
167
  /^\.apm\/?$/,
@@ -652,8 +651,13 @@ async function commitAndPushGitignore(workdir) {
652
651
  }
653
652
 
654
653
  // src/commands/init.ts
655
- async function runInit(name) {
656
- const workdir = resolveWorkdirPath();
654
+ async function ensureWorkspaceInitialized(workdir, options) {
655
+ if (isWorkspaceApmInitialized(workdir)) {
656
+ return { didInit: false };
657
+ }
658
+ console.log(
659
+ `[apm] \u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u672A\u68C0\u6D4B\u5230\u5DF2\u521D\u59CB\u5316\u7684 .apm\uFF0C\u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316\u2026`
660
+ );
657
661
  await ensureWorkspaceApmDirForInit(workdir);
658
662
  if (ensureApmGitignoredInRepo(workdir)) {
659
663
  console.log("[apm] \u5DF2\u5728 .gitignore \u4E2D\u6DFB\u52A0 **/.apm/**");
@@ -662,7 +666,7 @@ async function runInit(name) {
662
666
  const apmDir = workspaceApmDir(workdir);
663
667
  await copyTemplateFiles(apmDir, workdir);
664
668
  const syncResult = await syncRemoteDeploymentConfig(workdir, apmDir);
665
- const trimmedName = name?.trim();
669
+ const trimmedName = options?.name?.trim();
666
670
  if (trimmedName) {
667
671
  const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
668
672
  const config = readFileSync3(apmConfigPath, "utf8");
@@ -676,8 +680,21 @@ async function runInit(name) {
676
680
  );
677
681
  }
678
682
  console.log(`[apm] \u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A\uFF1A${apmDir}`);
683
+ return { didInit: true, syncResult };
684
+ }
685
+ async function runInit(name) {
686
+ const workdir = resolveWorkdirPath();
687
+ await ensureWorkspaceApmDirForInit(workdir);
688
+ const { didInit, syncResult } = await ensureWorkspaceInitialized(workdir, {
689
+ name
690
+ });
691
+ if (!didInit) {
692
+ throw new Error(
693
+ "[apm] .apm \u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u975E\u7A7A\uFF0C\u8BF7\u5148\u5907\u4EFD\u3001\u6E05\u7A7A\u6216\u5220\u9664\u540E\u518D\u6267\u884C init"
694
+ );
695
+ }
679
696
  console.log(`[apm] \u5DE5\u4F5C\u76EE\u5F55\u8DEF\u5F84\uFF1A${workdir}`);
680
- if (!syncResult.synced) {
697
+ if (syncResult && !syncResult.synced) {
681
698
  console.log(
682
699
  "[apm] \u5F53\u524D .apm/apm.config.json \u4E0E .apm/deploy/README.md \u4E3A\u6A21\u677F\u9ED8\u8BA4\u503C\uFF1B\u5B8C\u6210\u5E73\u53F0\u767B\u8BB0\u540E\u6267\u884C apm sync-deploy-config"
683
700
  );
@@ -2961,8 +2978,13 @@ async function handleInboundMessage(cfg, msg, signal, ctx) {
2961
2978
  };
2962
2979
  try {
2963
2980
  if (signal.aborted) return;
2964
- assertWorkspaceApmDirExists(workdir);
2965
- assertApmGitignoredInRepo(workdir);
2981
+ const { didInit } = await runStep(
2982
+ "workspace-init",
2983
+ () => ensureWorkspaceInitialized(workdir)
2984
+ );
2985
+ if (!didInit) {
2986
+ assertApmGitignoredInRepo(workdir);
2987
+ }
2966
2988
  await runStep(
2967
2989
  "status-typing",
2968
2990
  () => updateMessageStatus(cfg, messageId, "TYPING")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.58",
3
+ "version": "6.0.59",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,
File without changes