@coze-arch/cli 0.1.5-alpha.581217 → 0.1.5

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 (43) hide show
  1. package/docs/deploy.md +1 -12
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +3 -11
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  5. package/lib/__templates__/expo/client/components/Screen.tsx +25 -65
  6. package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +2 -6
  7. package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
  8. package/lib/__templates__/nextjs/.babelrc +15 -0
  9. package/lib/__templates__/nextjs/eslint.config.mjs +5 -11
  10. package/lib/__templates__/nextjs/next.config.ts +0 -10
  11. package/lib/__templates__/nextjs/package.json +6 -3
  12. package/lib/__templates__/nextjs/pnpm-lock.yaml +1071 -136
  13. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  14. package/lib/__templates__/nextjs/scripts/build.sh +2 -2
  15. package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
  16. package/lib/__templates__/nextjs/scripts/dev.sh +10 -86
  17. package/lib/__templates__/nextjs/scripts/prepare.sh +4 -1
  18. package/lib/__templates__/nextjs/src/app/layout.tsx +4 -0
  19. package/lib/__templates__/nextjs/src/server.ts +1 -1
  20. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  21. package/lib/__templates__/nuxt-vue/scripts/dev.sh +3 -11
  22. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +4 -1
  23. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +1 -5
  24. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +0 -4
  25. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -3
  26. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +2 -4
  27. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +7 -29
  28. package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +0 -4
  29. package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +1 -3
  30. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +0 -8
  31. package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +1 -3
  32. package/lib/__templates__/taro/.cozeproj/scripts/validate.sh +0 -4
  33. package/lib/__templates__/taro/_gitignore +0 -1
  34. package/lib/__templates__/vite/scripts/build.sh +1 -1
  35. package/lib/__templates__/vite/scripts/dev.sh +3 -11
  36. package/lib/__templates__/vite/scripts/prepare.sh +4 -1
  37. package/lib/cli.js +16 -147
  38. package/package.json +2 -2
  39. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +0 -212
  40. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +0 -212
  41. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +0 -212
  42. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +0 -212
  43. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +0 -212
@@ -8,7 +8,7 @@ Write-Host "Installing dependencies..."
8
8
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
9
9
 
10
10
  Write-Host "Building the Next.js project..."
11
- & pnpm next build --webpack
11
+ & pnpm next build
12
12
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
13
13
 
14
14
  Write-Host "Bundling server with tsup..."
@@ -6,10 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Next.js project..."
12
- pnpm next build --webpack
12
+ pnpm next build
13
13
 
14
14
  echo "Bundling server with tsup..."
15
15
  pnpm tsup src/server.ts --format cjs --platform node --target node20 --outDir dist --no-splitting --no-minify
@@ -28,7 +28,7 @@ Stop-ListeningProcess $port
28
28
 
29
29
  <% if (process.env.NODE_ENV === 'test') { %>
30
30
  $env:PORT = "$port"
31
- & pnpm next dev --webpack --hostname 0.0.0.0 --port $port
31
+ & pnpm tsx watch src/server.ts
32
32
  exit $LASTEXITCODE
33
33
  <% } else { %>
34
34
  $logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
@@ -45,7 +45,7 @@ if (Test-Path $pidFile) {
45
45
  $previousPort = $env:PORT
46
46
  $env:PORT = "$port"
47
47
  try {
48
- $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm next dev --webpack --hostname 0.0.0.0 --port $port") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
48
+ $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm tsx watch src/server.ts") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
49
49
  } finally {
50
50
  if ($null -eq $previousPort) { Remove-Item Env:PORT -ErrorAction SilentlyContinue } else { $env:PORT = $previousPort }
51
51
  }
@@ -52,77 +52,24 @@ kill_port_if_listening() {
52
52
  echo "Port ${DEPLOY_RUN_PORT} cleared."
53
53
  }
54
54
 
55
- # Next 的路由清单由 watchpack 每次启动重新扫 src 下的 app/pages 目录现算,而 watchpack
56
- # 不会进入软链目录,软链子树里的 page/route 会被静默跳过:既不注册路由,也不打任何日志,
57
- # 表现为该路由一直 404 而 .next 里没有它的产物。这里只做提示,不改动源码。
58
- warn_source_symlinks() {
59
- local source_dir="${COZE_WORKSPACE_PATH}/src"
60
- local links link
61
- if [[ ! -e "${source_dir}" ]]; then
62
- return
63
- fi
64
- links=$(find "${source_dir}" -type l 2>/dev/null || true)
65
- if [[ -z "${links}" ]]; then
66
- return
67
- fi
68
- echo "Warning: 以下路径是软链,Next 不会进入其中,里面的 page/route 不会被编译:" >&2
69
- while IFS= read -r link; do
70
- echo " ${link}" >&2
71
- done <<< "${links}"
72
- }
73
-
74
- # 云盘挂载偶尔会把新建文件的 mtime 设为 Unix epoch。Watchpack 会因此把路由文件当作
75
- # 启动前的旧状态,导致 Next 的首轮扫描漏掉 route/page。只在云盘项目启动前刷新 app/pages
76
- # 的目录和普通文件时间戳;不跟随软链、不改文件内容。
77
- refresh_drive_route_mtimes() {
78
- local drive_root="${COZE_DRIVE_ROOT:-/Coze/Drive}"
79
- local project_root route_dir
80
- project_root="$(pwd -P)"
81
- if [[ -d "${drive_root}" ]]; then
82
- drive_root="$(cd "${drive_root}" && pwd -P)"
83
- else
84
- drive_root="${drive_root%/}"
85
- fi
86
-
87
- case "${project_root}" in
88
- "${drive_root}"|"${drive_root}"/*) ;;
89
- *) return ;;
90
- esac
91
-
92
- for route_dir in "${COZE_WORKSPACE_PATH}/src/app" "${COZE_WORKSPACE_PATH}/src/pages"; do
93
- [[ -d "${route_dir}" ]] || continue
94
- if ! find -P "${route_dir}" \( -type f -o -type d \) -exec touch {} + 2>/dev/null; then
95
- echo "Warning: failed to refresh Next route timestamps in ${route_dir}." >&2
96
- fi
97
- done
98
- }
99
-
100
55
  <% if (process.env.NODE_ENV === 'test') { %>
101
56
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
102
57
  kill_port_if_listening
103
- bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
104
- warn_source_symlinks
105
- refresh_drive_route_mtimes
106
58
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
107
59
 
108
60
  # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
109
- # 开发环境直接使用 Next dev CLI,避免云盘文件事件在 custom server 链路中丢失。
110
- exec pnpm next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}"
61
+ exec env PORT="${DEPLOY_RUN_PORT}" pnpm tsx watch src/server.ts
111
62
  <% } else { %>
112
63
  LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
113
64
  LOG_FILE="${LOG_DIR}/app.log"
114
65
  PID_FILE="${LOG_DIR}/server.pid"
115
66
 
116
67
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
117
- MAX_RUNTIME_SECONDS=3600
118
-
119
- timeout_watchdog_enabled() {
120
- [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
121
- }
68
+ MAX_RUNTIME_SECONDS=1200
122
69
 
123
70
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
124
- # (wrapper -> pnpm -> next -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
125
- RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
71
+ # (wrapper -> pnpm -> tsx -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
72
+ RUN_WITH_TIMEOUT='
126
73
  timeout_seconds=$1
127
74
  shift
128
75
 
@@ -130,7 +77,6 @@ shift
130
77
  child_pid=$!
131
78
 
132
79
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
133
- if timeout_watchdog_enabled; then
134
80
  ( trap "" TERM
135
81
  sleep "${timeout_seconds}"
136
82
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -138,7 +84,6 @@ if timeout_watchdog_enabled; then
138
84
  sleep 5
139
85
  kill -KILL -- "-$$" 2>/dev/null || true
140
86
  ) &
141
- fi
142
87
 
143
88
  wait "${child_pid}"
144
89
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -187,7 +132,7 @@ stop_detached() {
187
132
  kill -KILL -- "-${pid}" 2>/dev/null || true
188
133
  }
189
134
 
190
- READY_RETRIES=30
135
+ READY_RETRIES=10
191
136
  READY_PROBE_HOSTS=("127.0.0.1" "::1")
192
137
  LOG_TAIL_LINES=40
193
138
 
@@ -197,21 +142,6 @@ dump_log() {
197
142
  echo "---- end of ${LOG_FILE} ----" >&2
198
143
  }
199
144
 
200
- # 服务刚就绪时 app-paths-manifest.json 还是空的(dev 按需编译,没请求就没产物),
201
- # 但 .next/dev/types/routes.d.ts 已经写出了本次启动发现到的全部路由。把它落进日志,
202
- # 排查时才能区分“路由没被发现”和“路由发现了但还没编译”。
203
- dump_discovered_routes() {
204
- local route_types="${COZE_WORKSPACE_PATH}/.next/dev/types/routes.d.ts"
205
- if [[ ! -f "${route_types}" ]]; then
206
- return
207
- fi
208
- {
209
- echo "---- discovered routes (${route_types}) ----"
210
- grep -E '^type (AppRoutes|AppRouteHandlerRoutes|PageRoutes) ' "${route_types}" || true
211
- echo "---- end of discovered routes ----"
212
- } >> "${LOG_FILE}"
213
- }
214
-
215
145
  # 仅用于无 ss/lsof 时的兜底探测。服务可能只 bind IPv4 loopback、只 bind IPv6 loopback
216
146
  # (server.listen(port, 'localhost') 会变成 ::1 独占),或 bind 双栈通配地址,
217
147
  port_connectable() {
@@ -285,7 +215,7 @@ wait_for_ready() {
285
215
  return 2
286
216
  }
287
217
 
288
- # 监听端口的是孙进程(pnpm -> next -> node),只清端口会漏掉上层 pnpm/next
218
+ # 监听端口的是孙进程(pnpm -> tsx -> node),只清端口会漏掉上层 pnpm/tsx
289
219
  # 所以先按上次记录的 PID 把整个进程组回收掉。
290
220
  if [[ -f "${PID_FILE}" ]]; then
291
221
  stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
@@ -294,9 +224,6 @@ fi
294
224
 
295
225
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
296
226
  kill_port_if_listening
297
- bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
298
- warn_source_symlinks
299
- refresh_drive_route_mtimes
300
227
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
301
228
 
302
229
  mkdir -p "${LOG_DIR}"
@@ -304,7 +231,7 @@ mkdir -p "${LOG_DIR}"
304
231
 
305
232
  export PORT="${DEPLOY_RUN_PORT}"
306
233
  server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
307
- "$(command -v pnpm)" next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}")"
234
+ "$(command -v pnpm)" tsx watch src/server.ts)"
308
235
  if [[ -z "${server_pid}" ]]; then
309
236
  echo "Dev server failed to start: 未获取到后台进程 PID。" >&2
310
237
  dump_log
@@ -320,7 +247,8 @@ fi
320
247
 
321
248
  if [[ "${ready_status}" -ne 0 ]]; then
322
249
  if [[ "${ready_status}" -eq 2 ]]; then
323
- echo "Dev server did not listen on port ${DEPLOY_RUN_PORT} after ${READY_RETRIES} attempts; stopping PID ${server_pid}." >&2
250
+ # 进程还活着但迟迟没监听端口:多半是编译/运行时报错后 tsx watch 驻留,日志里有真正原因。
251
+ echo "Dev server 在 ${READY_RETRIES} 次探测(每次 1s)内未就绪于端口 ${DEPLOY_RUN_PORT}(进程 ${server_pid} 仍在运行,已回收)。" >&2
324
252
  else
325
253
  echo "Dev server failed to start. See ${LOG_FILE}." >&2
326
254
  fi
@@ -331,12 +259,8 @@ if [[ "${ready_status}" -ne 0 ]]; then
331
259
  exit 1
332
260
  fi
333
261
 
334
- dump_discovered_routes
335
-
336
262
  echo "Dev server started (PID: ${server_pid}), listening on port ${DEPLOY_RUN_PORT}."
337
- if timeout_watchdog_enabled; then
338
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
339
- fi
263
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
340
264
  echo "Log file: ${LOG_FILE}"
341
265
  echo "PID file: ${PID_FILE}"
342
266
  <% } %>
@@ -6,4 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
+ if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
+ coze-dev check-bins --fix
12
+ fi
@@ -1,4 +1,5 @@
1
1
  import type { Metadata } from 'next';
2
+ import { Inspector } from 'react-dev-inspector';
2
3
  import './globals.css';
3
4
 
4
5
  export const metadata: Metadata = {
@@ -60,9 +61,12 @@ export default function RootLayout({
60
61
  }: Readonly<{
61
62
  children: React.ReactNode;
62
63
  }>) {
64
+ const isDev = process.env.COZE_PROJECT_ENV === 'DEV';
65
+
63
66
  return (
64
67
  <html lang="en">
65
68
  <body className={`antialiased`}>
69
+ {isDev && <Inspector />}
66
70
  {children}
67
71
  </body>
68
72
  </html>
@@ -7,7 +7,7 @@ const hostname = process.env.HOSTNAME || 'localhost';
7
7
  const port = parseInt(process.env.PORT || '<%= port %>', 10);
8
8
 
9
9
  // Create Next.js app
10
- const app = next({ dev, hostname, port, webpack: true });
10
+ const app = next({ dev, hostname, port });
11
11
  const handle = app.getRequestHandler();
12
12
 
13
13
  app.prepare().then(() => {
@@ -6,7 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Nuxt.js project..."
12
12
  pnpm nuxt build
@@ -65,15 +65,11 @@ LOG_FILE="${LOG_DIR}/server.log"
65
65
  PID_FILE="${LOG_DIR}/server.pid"
66
66
 
67
67
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
68
- MAX_RUNTIME_SECONDS=3600
69
-
70
- timeout_watchdog_enabled() {
71
- [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
72
- }
68
+ MAX_RUNTIME_SECONDS=1200
73
69
 
74
70
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
75
71
  # (wrapper -> pnpm -> nuxt -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
76
- RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
72
+ RUN_WITH_TIMEOUT='
77
73
  timeout_seconds=$1
78
74
  shift
79
75
 
@@ -81,7 +77,6 @@ shift
81
77
  child_pid=$!
82
78
 
83
79
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
84
- if timeout_watchdog_enabled; then
85
80
  ( trap "" TERM
86
81
  sleep "${timeout_seconds}"
87
82
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -89,7 +84,6 @@ if timeout_watchdog_enabled; then
89
84
  sleep 5
90
85
  kill -KILL -- "-$$" 2>/dev/null || true
91
86
  ) &
92
- fi
93
87
 
94
88
  wait "${child_pid}"
95
89
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -268,9 +262,7 @@ if [[ "${ready_status}" -ne 0 ]]; then
268
262
  fi
269
263
 
270
264
  echo "Dev server started (PID: ${server_pid}), listening on port ${DEPLOY_RUN_PORT}."
271
- if timeout_watchdog_enabled; then
272
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
273
- fi
265
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
274
266
  echo "Log file: ${LOG_FILE}"
275
267
  echo "PID file: ${PID_FILE}"
276
268
  <% } %>
@@ -6,7 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline
10
+ if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
+ coze-dev check-bins --fix
12
+ fi
10
13
 
11
14
  echo "Preparing Nuxt project..."
12
15
  pnpm exec nuxt prepare
@@ -1,10 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
6
- export COZE_WORKSPACE_PATH
7
-
8
4
  cd "${COZE_WORKSPACE_PATH}"
9
5
  if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
10
6
  echo "⚙️ Initializing environment..."
@@ -15,7 +11,7 @@ else
15
11
  fi
16
12
  echo "Installing dependencies..."
17
13
  # 安装所有依赖(包含 Taro 核心和 React)
18
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
14
+ pnpm install
19
15
 
20
16
  echo "Building the Taro project..."
21
17
  pnpm build
@@ -1,10 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
6
- export COZE_WORKSPACE_PATH
7
-
8
4
  start_service() {
9
5
  cd "${COZE_WORKSPACE_PATH}/server/dist"
10
6
 
@@ -1,5 +1,2 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
-
4
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
@@ -28,9 +28,7 @@ function Start-DevProcess([string] $workingDirectory, [string] $logFile, [hashta
28
28
  }
29
29
  }
30
30
 
31
- $projectRoot = (Resolve-Path (Join-Path $PSScriptRoot "../..")).Path
32
- $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { $projectRoot }
33
- $env:COZE_WORKSPACE_PATH = $workspace
31
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
34
32
  $port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { <%= port %> }
35
33
  $serverPort = if ($env:SERVER_PORT) { [int] $env:SERVER_PORT } else { <%= serverPort %> }
36
34
  $logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
@@ -45,7 +43,7 @@ if (Test-Path $pidFile) {
45
43
  Stop-ListeningProcess $port
46
44
  Stop-ListeningProcess $serverPort
47
45
 
48
- $environment = @{ COZE_WORKSPACE_PATH = $workspace; PORT = "$port"; SERVER_PORT = "$serverPort" }
46
+ $environment = @{ PORT = "$port"; SERVER_PORT = "$serverPort" }
49
47
  if ($env:COZE_PROJECT_DOMAIN_DEFAULT) {
50
48
  $environment.PROJECT_DOMAIN = $env:COZE_PROJECT_DOMAIN_DEFAULT
51
49
  }
@@ -4,7 +4,6 @@ set -Eeuo pipefail
4
4
 
5
5
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
6
6
  COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
7
- export COZE_WORKSPACE_PATH
8
7
  cd "${COZE_WORKSPACE_PATH}"
9
8
 
10
9
  # ---------------------------------------------------------
@@ -32,15 +31,11 @@ kill_process_tree() {
32
31
  }
33
32
 
34
33
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
35
- MAX_RUNTIME_SECONDS=3600
36
-
37
- timeout_watchdog_enabled() {
38
- [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
39
- }
34
+ MAX_RUNTIME_SECONDS=1200
40
35
 
41
36
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
42
37
  # (wrapper -> pnpm -> taro/nest);被包的进程自己先退出时也顺手清空进程组,不留残余。
43
- RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
38
+ RUN_WITH_TIMEOUT='
44
39
  timeout_seconds=$1
45
40
  shift
46
41
 
@@ -48,7 +43,6 @@ shift
48
43
  child_pid=$!
49
44
 
50
45
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
51
- if timeout_watchdog_enabled; then
52
46
  ( trap "" TERM
53
47
  sleep "${timeout_seconds}"
54
48
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -56,7 +50,6 @@ if timeout_watchdog_enabled; then
56
50
  sleep 5
57
51
  kill -KILL -- "-$$" 2>/dev/null || true
58
52
  ) &
59
- fi
60
53
 
61
54
  wait "${child_pid}"
62
55
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -162,24 +155,12 @@ list_port_pids() {
162
155
 
163
156
  kill_port_if_listening() {
164
157
  local port=$1
165
- # 用于错误提示的端口环境变量名称,例如 DEPLOY_RUN_PORT 或 SERVER_PORT。
166
- local port_env_name=$2
167
158
  local pids
168
- local pid
169
159
  pids=$(list_port_pids "${port}")
170
160
  if [[ -z "${pids}" ]]; then
171
161
  echo "Port ${port} is free."
172
162
  return
173
163
  fi
174
-
175
- # 端口可能由另一个项目占用。必须在杀进程前校验全部 PID,避免清理到一半才发现外部进程。
176
- for pid in ${pids}; do
177
- if ! process_belongs_to_workspace "${pid}"; then
178
- echo "Error: port ${port} is occupied by PID ${pid}, which does not belong to workspace ${COZE_WORKSPACE_PATH}. Refusing to kill it. Set ${port_env_name} to another port and retry." >&2
179
- return 1
180
- fi
181
- done
182
-
183
164
  echo "Port ${port} in use by PIDs: ${pids} (SIGKILL)"
184
165
  for pid in ${pids}; do
185
166
  kill_process_tree "${pid}"
@@ -187,8 +168,7 @@ kill_port_if_listening() {
187
168
  sleep 1
188
169
  pids=$(list_port_pids "${port}")
189
170
  if [[ -n "${pids}" ]]; then
190
- echo "Error: port ${port} is still occupied after cleaning up this project's processes, PIDs: ${pids}. Check the remaining processes manually or set ${port_env_name} to another port and retry." >&2
191
- return 1
171
+ echo "Warning: port ${port} still busy after SIGKILL, PIDs: ${pids}"
192
172
  else
193
173
  echo "Port ${port} cleared."
194
174
  fi
@@ -214,7 +194,7 @@ cleanup_previous_run() {
214
194
  # ---------------------------------------------------------
215
195
  echo "📦 Installing dependencies..."
216
196
  PNPM_BIN="$(command -v pnpm)"
217
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
197
+ "${PNPM_BIN}" install
218
198
  echo "✅ Dependencies installed successfully!"
219
199
 
220
200
  # ---------------------------------------------------------
@@ -230,9 +210,9 @@ mkdir -p "${LOG_DIR}"
230
210
  cleanup_previous_run
231
211
 
232
212
  echo "Clearing port ${PORT} (web) before start."
233
- kill_port_if_listening "${PORT}" "DEPLOY_RUN_PORT"
213
+ kill_port_if_listening "${PORT}"
234
214
  echo "Clearing port ${SERVER_PORT} (server) before start."
235
- kill_port_if_listening "${SERVER_PORT}" "SERVER_PORT"
215
+ kill_port_if_listening "${SERVER_PORT}"
236
216
 
237
217
  # ---------------------------------------------------------
238
218
  # 4. 启动服务
@@ -272,9 +252,7 @@ start_service() {
272
252
  fi
273
253
 
274
254
  echo "📝 Dev process started with PID: ${DEV_PID}"
275
- if timeout_watchdog_enabled; then
276
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
277
- fi
255
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
278
256
  echo "Log file: ${LOG_FILE}"
279
257
  echo "PID file: ${PID_FILE}"
280
258
  }
@@ -1,9 +1,5 @@
1
1
  #!/bin/bash
2
2
 
3
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
5
- export COZE_WORKSPACE_PATH
6
-
7
3
  cd "${COZE_WORKSPACE_PATH}"
8
4
 
9
5
  echo "✅ 初始化完成"
@@ -1,8 +1,6 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
- $projectRoot = (Resolve-Path (Join-Path $PSScriptRoot "../..")).Path
4
- $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { $projectRoot }
5
- $env:COZE_WORKSPACE_PATH = $workspace
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
6
4
  Set-Location $workspace
7
5
 
8
6
  & pnpm build:pack
@@ -1,11 +1,3 @@
1
- #!/bin/bash
2
-
3
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
5
- export COZE_WORKSPACE_PATH
6
-
7
- cd "${COZE_WORKSPACE_PATH}"
8
-
9
1
  # build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
10
2
  PID_FILE="/tmp/coze-build_weapp.pid"
11
3
 
@@ -1,8 +1,6 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
- $projectRoot = (Resolve-Path (Join-Path $PSScriptRoot "../..")).Path
4
- $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { $projectRoot }
5
- $env:COZE_WORKSPACE_PATH = $workspace
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
6
4
  Set-Location $workspace
7
5
 
8
6
  & pnpm validate
@@ -1,10 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
- COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
6
- export COZE_WORKSPACE_PATH
7
-
8
4
  cd "${COZE_WORKSPACE_PATH}"
9
5
 
10
6
  echo "🔍 Running validate..."
@@ -17,7 +17,6 @@ dist-*/
17
17
  .env.production.local
18
18
 
19
19
  # Logs
20
- /logs
21
20
  npm-debug.log*
22
21
  yarn-debug.log*
23
22
  yarn-error.log*
@@ -6,7 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building frontend with Vite..."
12
12
  pnpm vite build
@@ -45,15 +45,11 @@ LOG_FILE="${LOG_DIR}/server.log"
45
45
  PID_FILE="${LOG_DIR}/server.pid"
46
46
 
47
47
  # detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
48
- MAX_RUNTIME_SECONDS=3600
49
-
50
- timeout_watchdog_enabled() {
51
- [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
52
- }
48
+ MAX_RUNTIME_SECONDS=1200
53
49
 
54
50
  # 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
55
51
  # (wrapper -> pnpm -> tsx -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
56
- RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
52
+ RUN_WITH_TIMEOUT='
57
53
  timeout_seconds=$1
58
54
  shift
59
55
 
@@ -61,7 +57,6 @@ shift
61
57
  child_pid=$!
62
58
 
63
59
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
64
- if timeout_watchdog_enabled; then
65
60
  ( trap "" TERM
66
61
  sleep "${timeout_seconds}"
67
62
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -69,7 +64,6 @@ if timeout_watchdog_enabled; then
69
64
  sleep 5
70
65
  kill -KILL -- "-$$" 2>/dev/null || true
71
66
  ) &
72
- fi
73
67
 
74
68
  wait "${child_pid}"
75
69
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -148,9 +142,7 @@ if [[ -z "${server_pid}" ]] || ! kill -0 "${server_pid}" 2>/dev/null; then
148
142
  fi
149
143
 
150
144
  echo "Dev server started (PID: ${server_pid})."
151
- if timeout_watchdog_enabled; then
152
- echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
153
- fi
145
+ echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
154
146
  echo "Log file: ${LOG_FILE}"
155
147
  echo "PID file: ${PID_FILE}"
156
148
  <% } %>
@@ -6,4 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
+ if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
+ coze-dev check-bins --fix
12
+ fi