@kmlckj/licos-ai-cli 0.0.22 → 0.0.23

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.
@@ -7,18 +7,14 @@ mkdir -p "$LOG_DIR"
7
7
  # ==================== 配置项 ====================
8
8
  # Server 服务配置
9
9
  SERVER_HOST="0.0.0.0"
10
- SERVER_PORT="9091"
10
+ SERVER_PORT="${LICOS_BACKEND_PORT:-${SERVER_PORT:-5001}}"
11
11
  # Expo 项目配置
12
12
  EXPO_HOST="0.0.0.0"
13
13
  EXPO_DIR="expo"
14
- EXPO_PORT="5000"
15
- WEB_URL="${LICOS_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
14
+ EXPO_PORT="${LICOS_RUN_PORT:-${PORT:-5000}}"
16
15
  ASSUME_YES="1"
17
- EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$WEB_URL}"
18
- EXPO_PUBLIC_LICOS_PROJECT_ID="${LICOS_PROJECT_ID:-}"
16
+ PROTECTED_PORTS="${LICOS_DEV_PROTECTED_PORTS:-8080 8081 9091}"
19
17
 
20
- EXPO_PACKAGER_PROXY_URL="${EXPO_PUBLIC_BACKEND_BASE_URL}"
21
- export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL EXPO_PUBLIC_LICOS_PROJECT_ID
22
18
  # 运行时变量(为避免 set -u 的未绑定错误,预置为空)
23
19
  SERVER_PID=""
24
20
  EXPO_PID=""
@@ -51,6 +47,15 @@ choose_next_free_port() {
51
47
  done
52
48
  echo "$p"
53
49
  }
50
+ is_protected_port() {
51
+ local port_val=$1
52
+ for protected in $PROTECTED_PORTS; do
53
+ if [ "$protected" = "$port_val" ]; then
54
+ return 0
55
+ fi
56
+ done
57
+ return 1
58
+ }
54
59
  ensure_port() {
55
60
  local var_name=$1
56
61
  local port_val=$2
@@ -59,6 +64,13 @@ ensure_port() {
59
64
  eval "$var_name=$port_val"
60
65
  else
61
66
  echo "端口已占用:$port_val"
67
+ if is_protected_port "$port_val"; then
68
+ local new_port
69
+ new_port=$(choose_next_free_port "$((port_val+1))")
70
+ echo "端口 $port_val 是平台保护端口,改用新的端口:$new_port"
71
+ eval "$var_name=$new_port"
72
+ return 0
73
+ fi
62
74
  local choice
63
75
  if [ "$ASSUME_YES" = "1" ]; then choice="Y"; else read -r -p "是否关闭该端口的进程?[Y/n] " choice || choice="Y"; fi
64
76
  if [ -z "$choice" ] || [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
@@ -85,6 +97,13 @@ ensure_port() {
85
97
  fi
86
98
  fi
87
99
  }
100
+ configure_expo_env() {
101
+ local web_url="${LICOS_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
102
+ EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$web_url}"
103
+ EXPO_PUBLIC_LICOS_PROJECT_ID="${LICOS_PROJECT_ID:-}"
104
+ EXPO_PACKAGER_PROXY_URL="${EXPO_PACKAGER_PROXY_URL:-$EXPO_PUBLIC_BACKEND_BASE_URL}"
105
+ export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL EXPO_PUBLIC_LICOS_PROJECT_ID
106
+ }
88
107
 
89
108
  pipe_to_log() {
90
109
  local source="${1:-CLIENT}"
@@ -172,6 +191,7 @@ check_command "bash"
172
191
  # 端口占用预检查与处理
173
192
  ensure_port SERVER_PORT "$SERVER_PORT"
174
193
  ensure_port EXPO_PORT "$EXPO_PORT"
194
+ configure_expo_env
175
195
 
176
196
  echo "==================== 启动 server 服务 ===================="
177
197
  echo "正在执行:pnpm run dev (server)"
@@ -4,7 +4,8 @@ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
4
  SERVER_DIR="$ROOT_DIR/server"
5
5
  LOG_DIR="${LICOS_LOG_DIR:-$ROOT_DIR/logs}"
6
6
  LOG_SERVER_FILE="$LOG_DIR/server.log"
7
- SERVER_PORT="${SERVER_PORT:-9091}"
7
+ SERVER_PORT="${LICOS_BACKEND_PORT:-${SERVER_PORT:-5001}}"
8
+ PROTECTED_PORTS="${LICOS_DEV_PROTECTED_PORTS:-8080 8081 9091}"
8
9
 
9
10
  mkdir -p "$LOG_DIR"
10
11
 
@@ -27,6 +28,12 @@ kill_old_server() {
27
28
  local pids
28
29
  pids=$(lsof -t -i tcp:"$SERVER_PORT" -sTCP:LISTEN 2>/dev/null || true)
29
30
  if [ -n "$pids" ]; then
31
+ for protected in $PROTECTED_PORTS; do
32
+ if [ "$protected" = "$SERVER_PORT" ]; then
33
+ echo "端口 $SERVER_PORT 是平台保护端口,不会关闭占用进程"
34
+ return 0
35
+ fi
36
+ done
30
37
  echo "正在关闭旧的 server 进程:$pids"
31
38
  kill -9 $pids 2>/dev/null || echo "关闭进程失败:$pids"
32
39
  sleep 1
@@ -32,7 +32,7 @@ config.resolver.blockList = [
32
32
  /.*node_modules\/\.pnpm\/.*_tmp_\d+.*/,
33
33
  ];
34
34
 
35
- const BACKEND_TARGET = 'http://localhost:9091';
35
+ const BACKEND_TARGET = process.env.EXPO_PUBLIC_BACKEND_BASE_URL || 'http://localhost:5001';
36
36
 
37
37
  const apiProxy = createProxyMiddleware({
38
38
  target: BACKEND_TARGET,
@@ -2,7 +2,7 @@ import express from "express";
2
2
  import cors from "cors";
3
3
 
4
4
  const app = express();
5
- const port = process.env.PORT || 9091;
5
+ const port = process.env.PORT || 5001;
6
6
 
7
7
  // Middleware
8
8
  app.use(cors());
package/lib/cli.js CHANGED
@@ -2107,7 +2107,7 @@ const EventBuilder = {
2107
2107
  };
2108
2108
 
2109
2109
  var name = "@kmlckj/licos-ai-cli";
2110
- var version = "0.0.22";
2110
+ var version = "0.0.23";
2111
2111
  var description = "LICOS AI coding workspace CLI - project template engine and dev tools";
2112
2112
  var license = "MIT";
2113
2113
  var author = "kmlckj";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-ai-cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "LICOS AI coding workspace CLI - project template engine and dev tools",
5
5
  "license": "MIT",
6
6
  "author": "kmlckj",