ai-project-manage-cli 6.0.95 → 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.
- package/dist/index.js +110 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3878,7 +3878,20 @@ function runNpm2(args, options = {}) {
|
|
|
3878
3878
|
shell: useNpmShell2
|
|
3879
3879
|
});
|
|
3880
3880
|
}
|
|
3881
|
+
function verifyPm2Bin(pm2Bin) {
|
|
3882
|
+
if (!pm2Bin.trim() || !existsSync14(pm2Bin)) {
|
|
3883
|
+
return false;
|
|
3884
|
+
}
|
|
3885
|
+
const result = spawnSync2(pm2Bin, ["--version"], {
|
|
3886
|
+
encoding: "utf8",
|
|
3887
|
+
shell: useNpmShell2,
|
|
3888
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3889
|
+
timeout: 15e3
|
|
3890
|
+
});
|
|
3891
|
+
return !result.error && result.status === 0;
|
|
3892
|
+
}
|
|
3881
3893
|
function findGlobalPm2() {
|
|
3894
|
+
const candidates = [];
|
|
3882
3895
|
const whichResult = spawnSync2(useNpmShell2 ? "where" : "which", ["pm2"], {
|
|
3883
3896
|
encoding: "utf8",
|
|
3884
3897
|
shell: useNpmShell2,
|
|
@@ -3888,8 +3901,8 @@ function findGlobalPm2() {
|
|
|
3888
3901
|
const lines = whichResult.stdout?.toString().trim().split(/\r?\n/) ?? [];
|
|
3889
3902
|
for (const line of lines) {
|
|
3890
3903
|
const candidate = line.trim();
|
|
3891
|
-
if (candidate
|
|
3892
|
-
|
|
3904
|
+
if (candidate) {
|
|
3905
|
+
candidates.push(candidate);
|
|
3893
3906
|
}
|
|
3894
3907
|
}
|
|
3895
3908
|
}
|
|
@@ -3900,10 +3913,15 @@ function findGlobalPm2() {
|
|
|
3900
3913
|
if (binResult.status === 0) {
|
|
3901
3914
|
const globalBin = binResult.stdout?.toString().trim();
|
|
3902
3915
|
if (globalBin) {
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3916
|
+
candidates.push(join15(globalBin, useNpmShell2 ? "pm2.cmd" : "pm2"));
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3920
|
+
for (const candidate of candidates) {
|
|
3921
|
+
if (seen.has(candidate)) continue;
|
|
3922
|
+
seen.add(candidate);
|
|
3923
|
+
if (verifyPm2Bin(candidate)) {
|
|
3924
|
+
return candidate;
|
|
3907
3925
|
}
|
|
3908
3926
|
}
|
|
3909
3927
|
return null;
|
|
@@ -3919,9 +3937,60 @@ function installGlobalPm2() {
|
|
|
3919
3937
|
process.exit(result.status ?? 1);
|
|
3920
3938
|
}
|
|
3921
3939
|
}
|
|
3922
|
-
function
|
|
3940
|
+
function readPm2Version(pm2Bin) {
|
|
3941
|
+
const result = spawnSync2(pm2Bin, ["--version"], {
|
|
3942
|
+
encoding: "utf8",
|
|
3943
|
+
shell: useNpmShell2,
|
|
3944
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3945
|
+
timeout: 15e3
|
|
3946
|
+
});
|
|
3947
|
+
if (result.error || result.status !== 0) {
|
|
3948
|
+
return null;
|
|
3949
|
+
}
|
|
3950
|
+
return result.stdout?.toString().trim() || null;
|
|
3951
|
+
}
|
|
3952
|
+
function logPm2Ready(pm2Bin, installed2) {
|
|
3953
|
+
const version = readPm2Version(pm2Bin);
|
|
3954
|
+
const versionSuffix = version ? ` ${version}` : "";
|
|
3955
|
+
if (installed2) {
|
|
3956
|
+
console.log(`[apm] \u5168\u5C40 pm2 \u5DF2\u5B89\u88C5${versionSuffix}: ${pm2Bin}`);
|
|
3957
|
+
} else {
|
|
3958
|
+
console.log(`[apm] \u5DF2\u68C0\u6D4B\u5230\u5168\u5C40 pm2${versionSuffix}: ${pm2Bin}`);
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
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) {
|
|
3923
3988
|
const existing = findGlobalPm2();
|
|
3924
3989
|
if (existing) {
|
|
3990
|
+
ensurePm2DaemonUpdated(existing);
|
|
3991
|
+
if (!options?.quiet) {
|
|
3992
|
+
logPm2Ready(existing, false);
|
|
3993
|
+
}
|
|
3925
3994
|
return existing;
|
|
3926
3995
|
}
|
|
3927
3996
|
installGlobalPm2();
|
|
@@ -3932,6 +4001,10 @@ function ensureGlobalPm2() {
|
|
|
3932
4001
|
);
|
|
3933
4002
|
process.exit(1);
|
|
3934
4003
|
}
|
|
4004
|
+
ensurePm2DaemonUpdated(installed2);
|
|
4005
|
+
if (!options?.quiet) {
|
|
4006
|
+
logPm2Ready(installed2, true);
|
|
4007
|
+
}
|
|
3935
4008
|
return installed2;
|
|
3936
4009
|
}
|
|
3937
4010
|
function resolveApmEntryPath(entryArg = process.argv[1]) {
|
|
@@ -3963,7 +4036,7 @@ function isRunningUnderPm2() {
|
|
|
3963
4036
|
return process.env.name === PM2_APP_NAME && process.env.pm_id !== void 0;
|
|
3964
4037
|
}
|
|
3965
4038
|
function runPm2(args, options) {
|
|
3966
|
-
const pm2Bin = ensureGlobalPm2();
|
|
4039
|
+
const pm2Bin = ensureGlobalPm2({ quiet: true });
|
|
3967
4040
|
const spawnOptions = {
|
|
3968
4041
|
encoding: "utf8",
|
|
3969
4042
|
stdio: options?.inherit ? "inherit" : ["ignore", "pipe", "pipe"],
|
|
@@ -3987,6 +4060,7 @@ function runPm2Json(args) {
|
|
|
3987
4060
|
if (!pm2Bin) {
|
|
3988
4061
|
return "[]";
|
|
3989
4062
|
}
|
|
4063
|
+
ensurePm2DaemonUpdated(pm2Bin);
|
|
3990
4064
|
const result = spawnSync2(pm2Bin, args, {
|
|
3991
4065
|
encoding: "utf8",
|
|
3992
4066
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -3996,16 +4070,24 @@ function runPm2Json(args) {
|
|
|
3996
4070
|
return result.stdout?.toString() ?? "[]";
|
|
3997
4071
|
}
|
|
3998
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() {
|
|
3999
4079
|
try {
|
|
4000
4080
|
const raw = runPm2Json(["jlist"]);
|
|
4001
4081
|
const list = JSON.parse(raw);
|
|
4002
|
-
return list.
|
|
4003
|
-
(app) => app.name === PM2_APP_NAME && (app.pm2_env?.status === "online" || app.pm2_env?.status === "launching")
|
|
4004
|
-
);
|
|
4082
|
+
return list.find((app) => app.name === PM2_APP_NAME) ?? null;
|
|
4005
4083
|
} catch {
|
|
4006
|
-
return
|
|
4084
|
+
return null;
|
|
4007
4085
|
}
|
|
4008
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
|
+
}
|
|
4009
4091
|
function assertConnectNotRunning() {
|
|
4010
4092
|
pruneStaleConnectLock();
|
|
4011
4093
|
const lock = readConnectLock();
|
|
@@ -4086,8 +4168,8 @@ async function prepareEcosystem(server) {
|
|
|
4086
4168
|
}
|
|
4087
4169
|
async function runDaemonStart(options) {
|
|
4088
4170
|
assertConnectNotRunning();
|
|
4089
|
-
ensureGlobalPm2();
|
|
4090
4171
|
await runUpdate();
|
|
4172
|
+
ensureGlobalPm2();
|
|
4091
4173
|
const cfg = await prepareEcosystem(options.server);
|
|
4092
4174
|
runPm2(["start", PM2_ECOSYSTEM_PATH, "--update-env"], { inherit: true });
|
|
4093
4175
|
console.log(
|
|
@@ -4160,14 +4242,29 @@ async function runDaemonRestart(options) {
|
|
|
4160
4242
|
console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u91CD\u542F`);
|
|
4161
4243
|
}
|
|
4162
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
|
+
}
|
|
4163
4250
|
runPm2(["delete", PM2_APP_NAME], { inherit: true });
|
|
4164
4251
|
forceReleaseConnectLock();
|
|
4165
4252
|
console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u4ECE PM2 \u79FB\u9664`);
|
|
4166
4253
|
}
|
|
4167
4254
|
async function runDaemonStatus() {
|
|
4255
|
+
ensureGlobalPm2();
|
|
4256
|
+
if (!findPm2ConnectProcess()) {
|
|
4257
|
+
printConnectNotRunningHint();
|
|
4258
|
+
return;
|
|
4259
|
+
}
|
|
4168
4260
|
runPm2(["describe", PM2_APP_NAME], { inherit: true });
|
|
4169
4261
|
}
|
|
4170
4262
|
async function runDaemonLogs(options) {
|
|
4263
|
+
ensureGlobalPm2();
|
|
4264
|
+
if (!findPm2ConnectProcess()) {
|
|
4265
|
+
printConnectNotRunningHint();
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4171
4268
|
const args = ["logs", PM2_APP_NAME, "--lines", String(options.lines ?? 100)];
|
|
4172
4269
|
if (!options.follow) {
|
|
4173
4270
|
args.push("--nostream");
|