@coze-arch/cli 0.0.37 → 0.0.39-alpha.bdff32

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 (168) hide show
  1. package/README.md +69 -104
  2. package/docs/deploy.md +181 -0
  3. package/lib/__templates__/expo/.coze +5 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +10 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +4 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +74 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +108 -19
  8. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.ps1 +15 -0
  9. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.ps1 +10 -0
  10. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
  11. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  12. package/lib/__templates__/expo/.cozeproj/scripts/validate.ps1 +7 -0
  13. package/lib/__templates__/expo/client/metro.config.js +3 -1
  14. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  15. package/lib/__templates__/expo/server/package.json +2 -2
  16. package/lib/__templates__/expo/server/src/index.ts +1 -1
  17. package/lib/__templates__/expo/template.config.js +11 -2
  18. package/lib/__templates__/native-static/.coze +4 -2
  19. package/lib/__templates__/native-static/scripts/serve.ps1 +7 -0
  20. package/lib/__templates__/nextjs/.coze +5 -0
  21. package/lib/__templates__/nextjs/package.json +7 -2
  22. package/lib/__templates__/nextjs/pnpm-lock.yaml +59 -334
  23. package/lib/__templates__/nextjs/scripts/build.ps1 +16 -0
  24. package/lib/__templates__/nextjs/scripts/dev.ps1 +63 -0
  25. package/lib/__templates__/nextjs/scripts/dev.sh +234 -7
  26. package/lib/__templates__/nextjs/scripts/prepare.ps1 +18 -0
  27. package/lib/__templates__/nextjs/scripts/start.ps1 +11 -0
  28. package/lib/__templates__/nextjs/scripts/validate.ps1 +8 -0
  29. package/lib/__templates__/nextjs/template.config.js +4 -2
  30. package/lib/__templates__/nuxt-vue/.coze +5 -0
  31. package/lib/__templates__/nuxt-vue/package.json +1 -1
  32. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  33. package/lib/__templates__/nuxt-vue/scripts/build.ps1 +12 -0
  34. package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +63 -0
  35. package/lib/__templates__/nuxt-vue/scripts/dev.sh +232 -3
  36. package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +12 -0
  37. package/lib/__templates__/nuxt-vue/scripts/start.ps1 +11 -0
  38. package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +8 -0
  39. package/lib/__templates__/phaser/.coze +18 -0
  40. package/lib/__templates__/phaser/README.md +45 -0
  41. package/lib/__templates__/phaser/_gitignore +23 -0
  42. package/lib/__templates__/phaser/_npmrc +14 -0
  43. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  44. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  45. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  46. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  47. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  48. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  49. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  50. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  51. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  52. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  53. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  54. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  55. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  56. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  57. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  58. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  59. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  60. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  61. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  62. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  63. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  64. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  65. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  66. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  67. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +11 -0
  68. package/lib/__templates__/phaser/debug-runtime/flow-graph.json +20 -0
  69. package/lib/__templates__/phaser/index.html +12 -0
  70. package/lib/__templates__/phaser/package.json +31 -0
  71. package/lib/__templates__/phaser/pnpm-lock.yaml +661 -0
  72. package/lib/__templates__/phaser/scripts/build.ps1 +12 -0
  73. package/lib/__templates__/phaser/scripts/build.sh +8 -0
  74. package/lib/__templates__/phaser/scripts/dev.ps1 +49 -0
  75. package/lib/__templates__/phaser/scripts/dev.sh +82 -0
  76. package/lib/__templates__/phaser/scripts/prepare.ps1 +8 -0
  77. package/lib/__templates__/phaser/scripts/prepare.sh +7 -0
  78. package/lib/__templates__/phaser/scripts/spawn-detached.cjs +29 -0
  79. package/lib/__templates__/phaser/scripts/start.ps1 +49 -0
  80. package/lib/__templates__/phaser/scripts/start.sh +82 -0
  81. package/lib/__templates__/phaser/scripts/validate.ps1 +7 -0
  82. package/lib/__templates__/phaser/scripts/validate.sh +7 -0
  83. package/lib/__templates__/phaser/src/assets.ts +15 -0
  84. package/lib/__templates__/phaser/src/global.d.ts +39 -0
  85. package/lib/__templates__/phaser/src/main.ts +28 -0
  86. package/lib/__templates__/phaser/src/scene/BootScene.ts +213 -0
  87. package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +69 -0
  88. package/lib/__templates__/phaser/src/style.css +28 -0
  89. package/lib/__templates__/phaser/src/types.ts +32 -0
  90. package/lib/__templates__/phaser/src/utils/asset-loader.ts +319 -0
  91. package/lib/__templates__/phaser/src/utils/index.ts +2 -0
  92. package/lib/__templates__/phaser/src/utils/mark-editable.ts +13 -0
  93. package/lib/__templates__/phaser/template.config.js +43 -0
  94. package/lib/__templates__/phaser/tsconfig.json +23 -0
  95. package/lib/__templates__/phaser/vite.config.ts +96 -0
  96. package/lib/__templates__/phaser-static/.coze +15 -0
  97. package/lib/__templates__/phaser-static/README.md +40 -0
  98. package/lib/__templates__/phaser-static/_gitignore +6 -0
  99. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  100. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  101. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  102. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  103. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  104. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  105. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  106. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  107. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  108. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  109. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  110. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  111. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  112. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  113. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  114. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  115. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  116. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  117. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  118. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  119. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  120. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  121. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  122. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  123. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +11 -0
  124. package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +20 -0
  125. package/lib/__templates__/phaser-static/index.html +17 -0
  126. package/lib/__templates__/phaser-static/scripts/serve.ps1 +7 -0
  127. package/lib/__templates__/phaser-static/src/assets.js +15 -0
  128. package/lib/__templates__/phaser-static/src/main.js +26 -0
  129. package/lib/__templates__/phaser-static/src/phaser.js +7 -0
  130. package/lib/__templates__/phaser-static/src/scene/BootScene.js +205 -0
  131. package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +67 -0
  132. package/lib/__templates__/phaser-static/src/style.css +28 -0
  133. package/lib/__templates__/phaser-static/src/utils/asset-loader.js +267 -0
  134. package/lib/__templates__/phaser-static/src/utils/index.js +2 -0
  135. package/lib/__templates__/phaser-static/src/utils/mark-editable.js +3 -0
  136. package/lib/__templates__/phaser-static/template.config.js +35 -0
  137. package/lib/__templates__/pi-agent/package.json +1 -1
  138. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  139. package/lib/__templates__/taro/.coze +6 -0
  140. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.ps1 +10 -0
  141. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.ps1 +8 -0
  142. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
  143. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.ps1 +3 -0
  144. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +62 -0
  145. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +178 -68
  146. package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +7 -0
  147. package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +7 -0
  148. package/lib/__templates__/taro/AGENTS.md +11 -7
  149. package/lib/__templates__/taro/README.md +4 -4
  150. package/lib/__templates__/taro/config/index.ts +10 -2
  151. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  152. package/lib/__templates__/taro/server/package.json +1 -1
  153. package/lib/__templates__/taro/server/src/main.ts +8 -2
  154. package/lib/__templates__/templates.json +51 -1
  155. package/lib/__templates__/vite/.coze +5 -0
  156. package/lib/__templates__/vite/package.json +1 -1
  157. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  158. package/lib/__templates__/vite/scripts/build.ps1 +16 -0
  159. package/lib/__templates__/vite/scripts/dev.ps1 +63 -0
  160. package/lib/__templates__/vite/scripts/dev.sh +110 -1
  161. package/lib/__templates__/vite/scripts/prepare.ps1 +18 -0
  162. package/lib/__templates__/vite/scripts/start.ps1 +11 -0
  163. package/lib/__templates__/vite/scripts/validate.ps1 +8 -0
  164. package/lib/__templates__/vite/template.config.js +4 -2
  165. package/lib/cli.js +3719 -211
  166. package/lib/deploy/package-project.js +244 -0
  167. package/lib/deploy/package-project.py +183 -0
  168. package/package.json +5 -2
@@ -1,18 +1,27 @@
1
+ #!/usr/bin/env bash
2
+
1
3
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
2
4
  PREVIEW_DIR="/source/preview"
3
5
  LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
4
6
  LOG_CLIENT_FILE="$LOG_DIR/client.log"
7
+ LOG_SERVER_FILE="$LOG_DIR/server.log"
5
8
  mkdir -p "$LOG_DIR"
6
9
 
7
10
  # ==================== 配置项 ====================
8
11
  # Server 服务配置
9
12
  SERVER_HOST="0.0.0.0"
10
- SERVER_PORT="9091"
13
+ SERVER_PORT="${SERVER_PORT:-<%= serverPort %>}"
11
14
  # Expo 项目配置
12
15
  EXPO_HOST="0.0.0.0"
13
16
  EXPO_DIR="expo"
14
- EXPO_PORT="5000"
15
- WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
17
+ # DEPLOY_RUN_PORT 是平台注入的对外端口,EXPO_PORT 保留为本地覆盖项。
18
+ EXPO_PORT="${DEPLOY_RUN_PORT:-${EXPO_PORT:-<%= port %>}}"
19
+ COZE_HARDWARE_DID="${COZE_HARDWARE_DID:-}"
20
+ if [ -n "${EXPO_PORT:-}" ] && [ -n "${COZE_HARDWARE_DID}" ]; then
21
+ WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-https://preview-${COZE_HARDWARE_DID}-${EXPO_PORT}.dev.coze.site}"
22
+ else
23
+ WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
24
+ fi
16
25
  ASSUME_YES="1"
17
26
  EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$WEB_URL}"
18
27
  EXPO_PUBLIC_COZE_PROJECT_ID="${COZE_PROJECT_ID:-}"
@@ -22,6 +31,7 @@ export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL EXPO_PUBLIC_COZE_PRO
22
31
  # 运行时变量(为避免 set -u 的未绑定错误,预置为空)
23
32
  SERVER_PID=""
24
33
  EXPO_PID=""
34
+ PNPM_BIN=""
25
35
 
26
36
  # ==================== 工具函数 ====================
27
37
  check_command() {
@@ -112,22 +122,94 @@ wait_port_connectable() {
112
122
  return 1
113
123
  }
114
124
 
115
- start_expo() {
116
- local offline="${1:-0}"
125
+ # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
126
+ MAX_RUNTIME_SECONDS=1200
127
+
128
+ # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
129
+ # (wrapper -> pnpm -> expo/node);被包的进程自己先退出时也顺手清空进程组,不留残余。
130
+ RUN_WITH_TIMEOUT='
131
+ timeout_seconds=$1
132
+ shift
133
+
134
+ "$@" &
135
+ child_pid=$!
136
+
137
+ # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
138
+ ( trap "" TERM
139
+ sleep "${timeout_seconds}"
140
+ echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
141
+ kill -TERM -- "-$$" 2>/dev/null || true
142
+ sleep 5
143
+ kill -KILL -- "-$$" 2>/dev/null || true
144
+ ) &
145
+
146
+ wait "${child_pid}"
147
+ kill -KILL -- "-$$" 2>/dev/null || true
148
+ '
149
+
150
+ # coze-daemon 会在 runtime shell 退出时清理原进程组。
151
+ # 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
152
+ # 返回的 PID 是 wrapper 的,同时也是整个进程组的 PGID,后续按组回收。
153
+ spawn_detached() {
154
+ local cwd="$1"
155
+ local log_file="$2"
156
+ shift 2
157
+
158
+ node - "$cwd" "$log_file" \
159
+ /bin/bash -c "${RUN_WITH_TIMEOUT}" detached-runner "${MAX_RUNTIME_SECONDS}" "$@" <<'NODE'
160
+ const fs = require('node:fs');
161
+ const { spawn } = require('node:child_process');
117
162
 
118
- pushd "$ROOT_DIR/client"
163
+ const [cwd, logFile, command, ...args] = process.argv.slice(2);
164
+ if (!cwd || !logFile || !command) {
165
+ throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
166
+ }
167
+
168
+ const logFd = fs.openSync(logFile, 'a');
169
+ try {
170
+ const child = spawn(command, args, {
171
+ cwd,
172
+ detached: true,
173
+ env: process.env,
174
+ stdio: ['ignore', logFd, logFd],
175
+ });
176
+ child.unref();
177
+ process.stdout.write(String(child.pid));
178
+ } finally {
179
+ fs.closeSync(logFd);
180
+ }
181
+ NODE
182
+ }
183
+
184
+ stop_detached() {
185
+ local pid="${1:-}"
186
+ if [ -z "$pid" ]; then
187
+ return
188
+ fi
119
189
 
190
+ kill -TERM -- "-$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || true
191
+ sleep 1
192
+ kill -KILL -- "-$pid" 2>/dev/null || true
193
+ }
194
+
195
+ start_expo() {
196
+ local offline="${1:-0}"
197
+ local -a expo_env
198
+ expo_env=(
199
+ "EXPO_NO_DEPENDENCY_VALIDATION=1"
200
+ "EXPO_PUBLIC_BACKEND_BASE_URL=$EXPO_PUBLIC_BACKEND_BASE_URL"
201
+ "EXPO_PACKAGER_PROXY_URL=$EXPO_PACKAGER_PROXY_URL"
202
+ "EXPO_PUBLIC_COZE_PROJECT_ID=$EXPO_PUBLIC_COZE_PROJECT_ID"
203
+ )
120
204
  if [ "$offline" = "1" ]; then
121
- ( EXPO_OFFLINE=1 EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
122
- nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
123
- else
124
- ( EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
125
- nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
205
+ expo_env+=("EXPO_OFFLINE=1")
126
206
  fi
127
- EXPO_PID=$!
128
- disown $EXPO_PID 2>/dev/null || true
129
207
 
130
- popd
208
+ EXPO_PID="$(spawn_detached \
209
+ "$ROOT_DIR/client" \
210
+ "$LOG_CLIENT_FILE" \
211
+ /usr/bin/env "${expo_env[@]}" \
212
+ "$PNPM_BIN" exec expo start --clear --port "$EXPO_PORT")"
131
213
  }
132
214
 
133
215
  detect_expo_fetch_failed() {
@@ -168,6 +250,8 @@ check_command "npm"
168
250
  check_command "pnpm"
169
251
  check_command "lsof"
170
252
  check_command "bash"
253
+ check_command "node"
254
+ PNPM_BIN="$(command -v pnpm)"
171
255
 
172
256
  # 端口占用预检查与处理
173
257
  ensure_port SERVER_PORT "$SERVER_PORT"
@@ -175,9 +259,12 @@ ensure_port EXPO_PORT "$EXPO_PORT"
175
259
 
176
260
  echo "==================== 启动 server 服务 ===================="
177
261
  echo "正在执行:pnpm run dev (server)"
178
- ( pushd "$ROOT_DIR/server" > /dev/null && SERVER_PORT="$SERVER_PORT" nohup pnpm run dev; popd > /dev/null ) &
179
- SERVER_PID=$!
180
- disown $SERVER_PID 2>/dev/null || true
262
+ : > "$LOG_SERVER_FILE"
263
+ export SERVER_PORT
264
+ SERVER_PID="$(spawn_detached \
265
+ "$ROOT_DIR/server" \
266
+ /dev/null \
267
+ "$PNPM_BIN" run dev)"
181
268
  if [ -z "${SERVER_PID}" ]; then
182
269
  echo "无法获取 server 后台进程 PID"
183
270
  fi
@@ -185,11 +272,12 @@ echo "server 服务已启动,进程 ID:${SERVER_PID:-unknown}"
185
272
 
186
273
  echo "==================== 启动 Expo 项目 ===================="
187
274
  echo "开始启动 Expo 服务,端口 ${EXPO_PORT}"
275
+ : > "$LOG_CLIENT_FILE"
188
276
  start_expo 0
189
277
  if detect_expo_fetch_failed 8; then
190
278
  echo "Expo 启动检测到网络错误:TypeError: fetch failed,启用离线模式重试"
191
- if [ -n "${EXPO_PID}" ]; then kill -9 "$EXPO_PID" 2>/dev/null || true; fi
192
- : > "$ROOT_DIR/logs/client.log"
279
+ stop_detached "$EXPO_PID"
280
+ : > "$LOG_CLIENT_FILE"
193
281
  start_expo 1
194
282
  fi
195
283
  # 输出以下环境变量,确保 Expo 项目能正确连接到 Server 服务
@@ -202,6 +290,7 @@ if [ -z "${EXPO_PID}" ]; then
202
290
  fi
203
291
 
204
292
  echo "所有服务已启动。Server PID: ${SERVER_PID}, Expo PID: ${EXPO_PID}"
293
+ echo "两个服务均在 ${MAX_RUNTIME_SECONDS}s 后自动退出。"
205
294
 
206
295
  echo "检查 Server 服务端口:$SERVER_HOST:$SERVER_PORT"
207
296
  if wait_port_connectable "$SERVER_HOST" "$SERVER_PORT" 10 2; then
@@ -0,0 +1,15 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ Set-Location $workspace
5
+
6
+ & pnpm install --registry=https://registry.npmmirror.com
7
+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
8
+
9
+ Push-Location (Join-Path $workspace "server")
10
+ try {
11
+ & pnpm run build
12
+ exit $LASTEXITCODE
13
+ } finally {
14
+ Pop-Location
15
+ }
@@ -0,0 +1,10 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ $port = if ($env:DEPLOY_RUN_PORT) { $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { $env:PORT } else { <%= port %> }
5
+
6
+ Set-Location (Join-Path $workspace "server")
7
+ $env:NODE_ENV = "production"
8
+ $env:PORT = "$port"
9
+ & node dist/index.js
10
+ exit $LASTEXITCODE
@@ -5,7 +5,7 @@ set -euo pipefail
5
5
  ROOT_DIR="$(pwd)"
6
6
 
7
7
  HOST="${HOST:-0.0.0.0}"
8
- PORT="${PORT:-5000}"
8
+ PORT="${DEPLOY_RUN_PORT:-${PORT:-<%= port %>}}"
9
9
 
10
10
  # ==================== 工具函数 ====================
11
11
  info() {
@@ -4,7 +4,7 @@ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
4
  SERVER_DIR="$ROOT_DIR/server"
5
5
  LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
6
6
  LOG_SERVER_FILE="$LOG_DIR/server.log"
7
- SERVER_PORT="${SERVER_PORT:-9091}"
7
+ SERVER_PORT="${SERVER_PORT:-<%= serverPort %>}"
8
8
 
9
9
  mkdir -p "$LOG_DIR"
10
10
 
@@ -0,0 +1,7 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ Set-Location $workspace
5
+
6
+ & pnpm validate
7
+ exit $LASTEXITCODE
@@ -32,7 +32,9 @@ config.resolver.blockList = [
32
32
  /.*node_modules\/\.pnpm\/.*_tmp_\d+.*/,
33
33
  ];
34
34
 
35
- const BACKEND_TARGET = 'http://localhost:9091';
35
+ const DEFAULT_BACKEND_PORT = '<%= serverPort %>';
36
+ const BACKEND_PORT = process.env.SERVER_PORT || DEFAULT_BACKEND_PORT;
37
+ const BACKEND_TARGET = `http://localhost:${BACKEND_PORT}`;
36
38
 
37
39
  const apiProxy = createProxyMiddleware({
38
40
  target: BACKEND_TARGET,
@@ -269,8 +269,8 @@ importers:
269
269
  specifier: ^2.8.5
270
270
  version: 2.8.6
271
271
  coze-coding-dev-sdk:
272
- specifier: ^0.7.24
273
- version: 0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
272
+ specifier: ^0.7.25
273
+ version: 0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
274
274
  dayjs:
275
275
  specifier: ^1.11.20
276
276
  version: 1.11.20
@@ -2643,8 +2643,8 @@ packages:
2643
2643
  resolution: {integrity: sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==}
2644
2644
  engines: {node: '>=10'}
2645
2645
 
2646
- coze-coding-dev-sdk@0.7.24:
2647
- resolution: {integrity: sha512-oL9Tg5PwxP6iMixonzzMO4aBjOKWcFUMVM+iz5dPyaqQkG84HP1y9DqK5DJVmtdfJuYdAW7pzOatDqLvgvZiXg==}
2646
+ coze-coding-dev-sdk@0.7.25:
2647
+ resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
2648
2648
  engines: {node: '>=18.0.0'}
2649
2649
  hasBin: true
2650
2650
 
@@ -9088,7 +9088,7 @@ snapshots:
9088
9088
  path-type: 4.0.0
9089
9089
  yaml: 1.10.2
9090
9090
 
9091
- coze-coding-dev-sdk@0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9091
+ coze-coding-dev-sdk@0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9092
9092
  dependencies:
9093
9093
  '@langchain/core': 1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6))
9094
9094
  '@langchain/openai': 1.2.3(@langchain/core@1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6)))(ws@8.19.0)
@@ -6,13 +6,13 @@
6
6
  "build": "node build.js",
7
7
  "dev": "bash ../.cozeproj/scripts/server_dev_run.sh",
8
8
  "preinstall": "npx only-allow pnpm",
9
- "start": "NODE_ENV=production PORT=${PORT:-5000} node dist/index.js",
9
+ "start": "NODE_ENV=production PORT=${PORT:-<%= port %>} node dist/index.js",
10
10
  "lint": "tsc --noEmit"
11
11
  },
12
12
  "dependencies": {
13
13
  "@supabase/supabase-js": "2.95.3",
14
14
  "cors": "^2.8.5",
15
- "coze-coding-dev-sdk": "^0.7.24",
15
+ "coze-coding-dev-sdk": "^0.7.25",
16
16
  "dayjs": "^1.11.20",
17
17
  "dotenv": "^17.2.3",
18
18
  "drizzle-orm": "^0.45.1",
@@ -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 || <%= serverPort %>;
6
6
 
7
7
  // Middleware
8
8
  app.use(cors());
@@ -6,6 +6,7 @@
6
6
 
7
7
 
8
8
 
9
+
9
10
  export const paramsSchema = {
10
11
  type: 'object',
11
12
  properties: {
@@ -18,11 +19,18 @@ export const paramsSchema = {
18
19
  },
19
20
  port: {
20
21
  type: 'number',
21
- default: 8081,
22
+ default: 5000,
22
23
  minimum: 1024,
23
24
  maximum: 65535,
24
25
  description: 'Metro bundler port',
25
26
  },
27
+ serverPort: {
28
+ type: 'number',
29
+ default: 9091,
30
+ minimum: 1024,
31
+ maximum: 65535,
32
+ description: 'Express backend server port',
33
+ },
26
34
  },
27
35
  required: [],
28
36
  additionalProperties: false,
@@ -32,7 +40,8 @@ const config = {
32
40
  description: 'Expo template for React Native applications',
33
41
  paramsSchema,
34
42
  defaultParams: {
35
- port: 9090,
43
+ port: 5000,
44
+ serverPort: 9091,
36
45
  appName: 'my-expo-app',
37
46
  },
38
47
  onBeforeRender: async context => {
@@ -5,8 +5,10 @@ project_type = "web"
5
5
 
6
6
  [dev]
7
7
  build = []
8
- run = [ "sh", "-c", "python -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
8
+ run = ["python3", "-m", "http.server", "${DEPLOY_RUN_PORT}", "--bind", "0.0.0.0"]
9
+ run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
9
10
 
10
11
  [deploy]
11
12
  build = []
12
- run = [ "sh", "-c", "python -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
13
+ run = ["python3", "-m", "http.server", "${DEPLOY_RUN_PORT}", "--bind", "0.0.0.0"]
14
+ run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
@@ -0,0 +1,7 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $port = if ($env:DEPLOY_RUN_PORT) { $env:DEPLOY_RUN_PORT } else { "8000" }
4
+
5
+ Write-Host "Starting static server on port $port..."
6
+ & python -m http.server $port --bind 0.0.0.0
7
+ exit $LASTEXITCODE
@@ -4,11 +4,16 @@ project_type = "web"
4
4
 
5
5
  [dev]
6
6
  build = ["bash", "./scripts/prepare.sh"]
7
+ build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/prepare.ps1"]
7
8
  run = ["bash", "./scripts/dev.sh"]
9
+ run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/dev.ps1"]
8
10
  validate = ["bash", "./scripts/validate.sh"]
11
+ validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/validate.ps1"]
9
12
  deps = ["git"] # -> apt install git
10
13
 
11
14
  [deploy]
12
15
  build = ["bash","./scripts/build.sh"]
16
+ build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/build.ps1"]
13
17
  run = ["bash","./scripts/start.sh"]
18
+ run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/start.ps1"]
14
19
  deps = ["git"] # -> apt install git
@@ -47,7 +47,7 @@
47
47
  "class-variance-authority": "^0.7.1",
48
48
  "clsx": "^2.1.1",
49
49
  "cmdk": "^1.1.1",
50
- "coze-coding-dev-sdk": "^0.7.16",
50
+ "coze-coding-dev-sdk": "^0.7.25",
51
51
  "date-fns": "^4.1.0",
52
52
  "dotenv": "^17.2.3",
53
53
  "drizzle-kit": "^0.31.8",
@@ -56,7 +56,7 @@
56
56
  "embla-carousel-react": "^8.6.0",
57
57
  "input-otp": "^1.4.2",
58
58
  "lucide-react": "^0.468.0",
59
- "next": "16.1.1",
59
+ "next": "16.3.3",
60
60
  "next-themes": "^0.4.6",
61
61
  "pg": "^8.16.3",
62
62
  "react": "19.2.3",
@@ -95,5 +95,10 @@
95
95
  "packageManager": "pnpm@9.0.0",
96
96
  "engines": {
97
97
  "pnpm": ">=9.0.0"
98
+ },
99
+ "pnpm": {
100
+ "overrides": {
101
+ "sharp": "0.35.3"
102
+ }
98
103
  }
99
104
  }