ai-project-manage-cli 6.0.68 → 6.0.69

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 +121 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2588,7 +2588,7 @@ async function runWisdomSftpDeploy(params) {
2588
2588
  }
2589
2589
 
2590
2590
  // src/commands/deploy/internal/wisdom-backend-deploy.ts
2591
- var SPRINGBOOT_SCRIPT = "springboot.sh";
2591
+ var SPRINGBOOT_JAVA_OPTS = "-XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512M -Xmx1G";
2592
2592
  var MAVEN_MODULE = "jeecg-module-system/jeecg-system-start";
2593
2593
  var MAVEN_PROFILE = "dev";
2594
2594
  function log(message) {
@@ -2924,22 +2924,106 @@ function springbootOutputIndicatesSuccess(action, combined) {
2924
2924
  }
2925
2925
  return true;
2926
2926
  }
2927
- async function runSpringbootAction(client, config, action, ...args) {
2928
- if (action === "start" || action === "restart") {
2929
- if (args.length === 0) {
2930
- fail(`\u8FDC\u7A0B ${action} \u7F3A\u5C11 jar \u53C2\u6570`);
2931
- }
2932
- const jar = args[0].trim().split(/\r?\n/)[0].trim();
2933
- if (!jar) {
2934
- fail(`\u65E0\u6548\u7684 jar \u540D\u79F0: ${JSON.stringify(args[0])}`);
2935
- }
2927
+ function buildRemoteStatusScript(remoteAppDir, appName) {
2928
+ const dir = shellSingleQuote(remoteAppDir);
2929
+ const jar = shellSingleQuote(appName);
2930
+ return `
2931
+ set -e
2932
+ cd ${dir}
2933
+ appName=${jar}
2934
+ appIds=$(ps -ef | grep java | grep "$appName" | awk '{print $2}')
2935
+ if [ -z "$appIds" ]; then
2936
+ echo -e "\\033[31m Not running \\033[0m"
2937
+ else
2938
+ echo -e "\\033[32m Running [$appIds] \\033[0m"
2939
+ fi
2940
+ `.trim();
2941
+ }
2942
+ function buildRemoteRestartScript(remoteAppDir) {
2943
+ const dir = shellSingleQuote(remoteAppDir);
2944
+ const javaOpts = shellSingleQuote(SPRINGBOOT_JAVA_OPTS);
2945
+ return `
2946
+ set -e
2947
+ cd ${dir}
2948
+ releaseApp=$(ls -t | grep '.jar$' | head -n1)
2949
+ lastVersionApp=$(ls -t | grep '.jar$' | head -n2 | tail -n1)
2950
+ appName=$lastVersionApp
2951
+ appIds=$(ps -ef | grep java | grep "$appName" | awk '{print $2}')
2952
+ if [ -z "$appIds" ]; then
2953
+ echo "Maybe $appName not running, please check it..."
2954
+ else
2955
+ echo "The $appName is stopping..."
2956
+ echo "$appIds" | xargs kill
2957
+ fi
2958
+ for i in $(seq 15 -1 1); do
2959
+ echo -n "$i "
2960
+ sleep 1
2961
+ done
2962
+ echo 0
2963
+ if [ ! -d "backup" ]; then
2964
+ mkdir backup
2965
+ fi
2966
+ for i in $(ls | grep '.jar$' | grep -vFx "$releaseApp"); do
2967
+ echo "backup $i"
2968
+ mv "$i" backup/
2969
+ done
2970
+ appName=$releaseApp
2971
+ count=$(ps -ef | grep java | grep "$appName" | wc -l)
2972
+ if [ "$count" != "0" ]; then
2973
+ echo "Maybe $appName is running, please check it..."
2974
+ else
2975
+ echo "The $appName is starting..."
2976
+ nohup java -jar "./$appName" ${javaOpts} > nohup.out 2>&1 &
2977
+ fi
2978
+ `.trim();
2979
+ }
2980
+ function normalizeHealthContext(context) {
2981
+ let normalized = context.trim() || "/";
2982
+ if (!normalized.startsWith("/")) {
2983
+ normalized = `/${normalized}`;
2936
2984
  }
2937
- const quotedArgs = [action, ...args].map((arg) => shellSingleQuote(arg));
2938
- const command = [
2939
- `cd ${shellSingleQuote(config.remoteAppDir)}`,
2940
- `./${SPRINGBOOT_SCRIPT} ${quotedArgs.join(" ")}`
2941
- ].join(" && ");
2942
- const { exitCode, out, err } = await runRemoteCommand(client, command, {
2985
+ if (!normalized.endsWith("/")) {
2986
+ normalized = `${normalized}/`;
2987
+ }
2988
+ return normalized;
2989
+ }
2990
+ function buildRemoteHealthScript(port, context, timeoutSecs) {
2991
+ const normalizedContext = normalizeHealthContext(context);
2992
+ const portStr = String(port);
2993
+ const timeoutStr = String(timeoutSecs);
2994
+ return `
2995
+ set -e
2996
+ port=${shellSingleQuote(portStr)}
2997
+ context=${shellSingleQuote(normalizedContext)}
2998
+ timeout=${shellSingleQuote(timeoutStr)}
2999
+ check_url="http://127.0.0.1:${portStr}${normalizedContext}"
3000
+ echo "\u5065\u5EB7\u68C0\u67E5: \${check_url} (\u8D85\u65F6 \${timeout}s)"
3001
+ deadline=$(($(date +%s) + timeout))
3002
+ attempt=0
3003
+ while [ $(date +%s) -lt $deadline ]; do
3004
+ attempt=$((attempt + 1))
3005
+ code=$(curl -s -o /dev/null -w "%{http_code}" "$check_url" 2>/dev/null || echo "000")
3006
+ code=$(echo "$code" | tail -n1 | tr -d '[:space:]')
3007
+ if [ \${#code} -ge 3 ]; then
3008
+ status=\${code:0:3}
3009
+ if echo "$status" | grep -qE '^[0-9]+$' && [ "$status" -ge 200 ] && [ "$status" -lt 500 ]; then
3010
+ echo -e "\\033[32m\u5065\u5EB7\u68C0\u67E5\u901A\u8FC7 (HTTP \${status})\\033[0m"
3011
+ exit 0
3012
+ fi
3013
+ fi
3014
+ remaining=$((deadline - $(date +%s)))
3015
+ if [ $remaining -lt 0 ]; then
3016
+ remaining=0
3017
+ fi
3018
+ echo "\u7B49\u5F85\u670D\u52A1\u542F\u52A8... \u7B2C \${attempt} \u6B21\uFF0C\u5269\u4F59 \${remaining}s"
3019
+ sleep 5
3020
+ done
3021
+ echo -e "\\033[31m\u5065\u5EB7\u68C0\u67E5\u8D85\u65F6 (\${timeout}s): \${check_url}\\033[0m"
3022
+ exit 1
3023
+ `.trim();
3024
+ }
3025
+ async function runRemoteServiceScript(client, script, action) {
3026
+ const { exitCode, out, err } = await runRemoteCommand(client, script, {
2943
3027
  check: false
2944
3028
  });
2945
3029
  const combined = `${out}
@@ -2948,21 +3032,17 @@ ${err}`.trim();
2948
3032
  if (action === "health") {
2949
3033
  if (exitCode !== 0 || !outputOk) {
2950
3034
  fail(`\u5065\u5EB7\u68C0\u67E5\u5931\u8D25
2951
- \u547D\u4EE4: ${command}
2952
3035
  \u8F93\u51FA: ${combined || "(\u7A7A)"}`);
2953
3036
  }
2954
3037
  return combined;
2955
3038
  }
2956
3039
  if (exitCode !== 0 && !outputOk) {
2957
- fail(`\u8FDC\u7A0B ${action} \u5931\u8D25: ${args.join(" ")}
3040
+ fail(`\u8FDC\u7A0B ${action} \u5931\u8D25
2958
3041
  ${combined}`);
2959
3042
  }
2960
- if ((action === "start" || action === "restart") && !outputOk) {
2961
- fail(
2962
- `\u8FDC\u7A0B ${action} \u672A\u6210\u529F: ${args.join(" ")}
2963
- \u547D\u4EE4: ${command}
2964
- \u8F93\u51FA: ${combined || "(\u7A7A)"}`
2965
- );
3043
+ if (action === "restart" && !outputOk) {
3044
+ fail(`\u8FDC\u7A0B restart \u672A\u6210\u529F
3045
+ \u8F93\u51FA: ${combined || "(\u7A7A)"}`);
2966
3046
  }
2967
3047
  return combined;
2968
3048
  }
@@ -2970,12 +3050,11 @@ function stripAnsi(text) {
2970
3050
  return text.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "");
2971
3051
  }
2972
3052
  async function getRunningJar(client, config) {
2973
- const combined = await runSpringbootAction(
2974
- client,
2975
- config,
2976
- "status",
3053
+ const script = buildRemoteStatusScript(
3054
+ config.remoteAppDir,
2977
3055
  config.startupJar
2978
3056
  );
3057
+ const combined = await runRemoteServiceScript(client, script, "status");
2979
3058
  const text = stripAnsi(combined).trim().toLowerCase();
2980
3059
  if (text.includes("not running")) {
2981
3060
  return null;
@@ -2986,11 +3065,19 @@ async function getRunningJar(client, config) {
2986
3065
  return null;
2987
3066
  }
2988
3067
  async function healthCheckService(client, config) {
2989
- const port = String(config.healthCheckPort);
2990
- const context = config.healthCheckContext;
2991
- const timeout = String(config.healthCheckTimeout);
2992
- log(`\u5065\u5EB7\u68C0\u67E5: springboot.sh health ${port} ${context} ${timeout}`);
2993
- await runSpringbootAction(client, config, "health", port, context, timeout);
3068
+ log(
3069
+ `\u5065\u5EB7\u68C0\u67E5: http://127.0.0.1:${config.healthCheckPort}${normalizeHealthContext(config.healthCheckContext)} (\u8D85\u65F6 ${config.healthCheckTimeout}s)`
3070
+ );
3071
+ const script = buildRemoteHealthScript(
3072
+ config.healthCheckPort,
3073
+ config.healthCheckContext,
3074
+ config.healthCheckTimeout
3075
+ );
3076
+ await runRemoteServiceScript(client, script, "health");
3077
+ }
3078
+ async function restartRemoteService(client, config) {
3079
+ const script = buildRemoteRestartScript(config.remoteAppDir);
3080
+ await runRemoteServiceScript(client, script, "restart");
2994
3081
  }
2995
3082
  async function runWisdomBackendDeploy(options) {
2996
3083
  const projectRoot = path2.resolve(options.projectRoot ?? process.cwd());
@@ -3044,12 +3131,7 @@ async function runWisdomBackendDeploy(options) {
3044
3131
  }
3045
3132
  if (needRestart) {
3046
3133
  log("\u91CD\u542F\u670D\u52A1...");
3047
- await runSpringbootAction(
3048
- conn.client,
3049
- config,
3050
- "restart",
3051
- config.startupJar
3052
- );
3134
+ await restartRemoteService(conn.client, config);
3053
3135
  }
3054
3136
  await healthCheckService(conn.client, config);
3055
3137
  if (libUploadEntries.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.68",
3
+ "version": "6.0.69",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,