ai-project-manage-cli 6.0.96 → 6.0.97

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 (2) hide show
  1. package/dist/index.js +64 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3958,10 +3958,39 @@ function logPm2Ready(pm2Bin, installed2) {
3958
3958
  console.log(`[apm] \u5DF2\u68C0\u6D4B\u5230\u5168\u5C40 pm2${versionSuffix}: ${pm2Bin}`);
3959
3959
  }
3960
3960
  }
3961
- function ensureGlobalPm2() {
3961
+ function isPm2DaemonOutOfDate(output) {
3962
+ return /In-memory PM2 is out-of-date/i.test(output);
3963
+ }
3964
+ function ensurePm2DaemonUpdated(pm2Bin) {
3965
+ const probe = spawnSync2(pm2Bin, ["jlist"], {
3966
+ encoding: "utf8",
3967
+ shell: useNpmShell2,
3968
+ stdio: ["ignore", "pipe", "pipe"],
3969
+ timeout: 15e3
3970
+ });
3971
+ const combined = `${probe.stdout ?? ""}
3972
+ ${probe.stderr ?? ""}`;
3973
+ if (!isPm2DaemonOutOfDate(combined)) {
3974
+ return;
3975
+ }
3976
+ console.log("[apm] \u68C0\u6D4B\u5230 PM2 \u5185\u5B58\u7248\u672C\u4E0E\u672C\u5730\u4E0D\u4E00\u81F4\uFF0C\u6B63\u5728\u6267\u884C pm2 update \u2026");
3977
+ const update = spawnSync2(pm2Bin, ["update"], {
3978
+ encoding: "utf8",
3979
+ shell: useNpmShell2,
3980
+ stdio: "inherit",
3981
+ timeout: 6e4
3982
+ });
3983
+ if (update.error || update.status !== 0) {
3984
+ console.error("[apm] pm2 update \u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C: pm2 update");
3985
+ }
3986
+ }
3987
+ function ensureGlobalPm2(options) {
3962
3988
  const existing = findGlobalPm2();
3963
3989
  if (existing) {
3964
- logPm2Ready(existing, false);
3990
+ ensurePm2DaemonUpdated(existing);
3991
+ if (!options?.quiet) {
3992
+ logPm2Ready(existing, false);
3993
+ }
3965
3994
  return existing;
3966
3995
  }
3967
3996
  installGlobalPm2();
@@ -3972,7 +4001,10 @@ function ensureGlobalPm2() {
3972
4001
  );
3973
4002
  process.exit(1);
3974
4003
  }
3975
- logPm2Ready(installed2, true);
4004
+ ensurePm2DaemonUpdated(installed2);
4005
+ if (!options?.quiet) {
4006
+ logPm2Ready(installed2, true);
4007
+ }
3976
4008
  return installed2;
3977
4009
  }
3978
4010
  function resolveApmEntryPath(entryArg = process.argv[1]) {
@@ -4004,7 +4036,7 @@ function isRunningUnderPm2() {
4004
4036
  return process.env.name === PM2_APP_NAME && process.env.pm_id !== void 0;
4005
4037
  }
4006
4038
  function runPm2(args, options) {
4007
- const pm2Bin = ensureGlobalPm2();
4039
+ const pm2Bin = ensureGlobalPm2({ quiet: true });
4008
4040
  const spawnOptions = {
4009
4041
  encoding: "utf8",
4010
4042
  stdio: options?.inherit ? "inherit" : ["ignore", "pipe", "pipe"],
@@ -4028,6 +4060,7 @@ function runPm2Json(args) {
4028
4060
  if (!pm2Bin) {
4029
4061
  return "[]";
4030
4062
  }
4063
+ ensurePm2DaemonUpdated(pm2Bin);
4031
4064
  const result = spawnSync2(pm2Bin, args, {
4032
4065
  encoding: "utf8",
4033
4066
  stdio: ["ignore", "pipe", "pipe"],
@@ -4037,16 +4070,24 @@ function runPm2Json(args) {
4037
4070
  return result.stdout?.toString() ?? "[]";
4038
4071
  }
4039
4072
  function isPm2ConnectOnline() {
4073
+ const app = findPm2ConnectProcess();
4074
+ if (!app) return false;
4075
+ const status = app.pm2_env?.status;
4076
+ return status === "online" || status === "launching";
4077
+ }
4078
+ function findPm2ConnectProcess() {
4040
4079
  try {
4041
4080
  const raw = runPm2Json(["jlist"]);
4042
4081
  const list = JSON.parse(raw);
4043
- return list.some(
4044
- (app) => app.name === PM2_APP_NAME && (app.pm2_env?.status === "online" || app.pm2_env?.status === "launching")
4045
- );
4082
+ return list.find((app) => app.name === PM2_APP_NAME) ?? null;
4046
4083
  } catch {
4047
- return false;
4084
+ return null;
4048
4085
  }
4049
4086
  }
4087
+ function printConnectNotRunningHint() {
4088
+ console.log(`[apm] ${PM2_APP_NAME} \u672A\u5728\u8FD0\u884C`);
4089
+ console.log("[apm] \u542F\u52A8\u5B88\u62A4: apm connect --daemon");
4090
+ }
4050
4091
  function assertConnectNotRunning() {
4051
4092
  pruneStaleConnectLock();
4052
4093
  const lock = readConnectLock();
@@ -4201,14 +4242,29 @@ async function runDaemonRestart(options) {
4201
4242
  console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u91CD\u542F`);
4202
4243
  }
4203
4244
  async function runDaemonDelete() {
4245
+ ensureGlobalPm2();
4246
+ if (!findPm2ConnectProcess()) {
4247
+ console.log(`[apm] ${PM2_APP_NAME} \u672A\u5728 PM2 \u4E2D\u6CE8\u518C`);
4248
+ return;
4249
+ }
4204
4250
  runPm2(["delete", PM2_APP_NAME], { inherit: true });
4205
4251
  forceReleaseConnectLock();
4206
4252
  console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u4ECE PM2 \u79FB\u9664`);
4207
4253
  }
4208
4254
  async function runDaemonStatus() {
4255
+ ensureGlobalPm2();
4256
+ if (!findPm2ConnectProcess()) {
4257
+ printConnectNotRunningHint();
4258
+ return;
4259
+ }
4209
4260
  runPm2(["describe", PM2_APP_NAME], { inherit: true });
4210
4261
  }
4211
4262
  async function runDaemonLogs(options) {
4263
+ ensureGlobalPm2();
4264
+ if (!findPm2ConnectProcess()) {
4265
+ printConnectNotRunningHint();
4266
+ return;
4267
+ }
4212
4268
  const args = ["logs", PM2_APP_NAME, "--lines", String(options.lines ?? 100)];
4213
4269
  if (!options.follow) {
4214
4270
  args.push("--nostream");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.96",
3
+ "version": "6.0.97",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,