@coze-arch/cli 0.1.4-alpha.b94eab → 0.1.4-alpha.d384e3
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/lib/__templates__/expo/.coze +3 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +10 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +74 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +2 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
- package/lib/__templates__/expo/.cozeproj/scripts/validate.ps1 +7 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +65 -25
- package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +6 -2
- package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +1 -1
- package/lib/__templates__/nextjs/eslint.config.mjs +11 -5
- package/lib/__templates__/nextjs/next.config.ts +10 -0
- package/lib/__templates__/nextjs/package.json +3 -6
- package/lib/__templates__/nextjs/pnpm-lock.yaml +19 -950
- package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
- package/lib/__templates__/nextjs/scripts/build.sh +2 -2
- package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
- package/lib/__templates__/nextjs/scripts/dev.sh +77 -7
- package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/nextjs/scripts/prepare.sh +1 -4
- package/lib/__templates__/nextjs/src/app/layout.tsx +0 -4
- package/lib/__templates__/nextjs/src/server.ts +1 -1
- package/lib/__templates__/nextjs/template.config.js +0 -59
- package/lib/__templates__/nuxt-vue/package.json +1 -1
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +2 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +1 -4
- package/lib/__templates__/pi-agent/package.json +1 -1
- package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/.coze +4 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +3 -2
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.ps1 +3 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +3 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +62 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +3 -1
- package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +7 -0
- package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +7 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/vite/package.json +1 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
- package/lib/__templates__/vite/scripts/build.sh +1 -1
- package/lib/__templates__/vite/scripts/dev.sh +2 -0
- package/lib/__templates__/vite/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/vite/scripts/prepare.sh +1 -4
- package/lib/__templates__/vite/template.config.js +0 -59
- package/lib/cli.js +35 -12
- package/package.json +1 -1
- package/lib/__templates__/nextjs/.babelrc +0 -15
|
@@ -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
|
|
11
|
+
& pnpm next build --webpack
|
|
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
|
-
|
|
9
|
+
bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
10
10
|
|
|
11
11
|
echo "Building the Next.js project..."
|
|
12
|
-
pnpm next build
|
|
12
|
+
pnpm next build --webpack
|
|
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
|
|
31
|
+
& pnpm next dev --webpack --hostname 0.0.0.0 --port $port
|
|
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
|
|
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
|
|
49
49
|
} finally {
|
|
50
50
|
if ($null -eq $previousPort) { Remove-Item Env:PORT -ErrorAction SilentlyContinue } else { $env:PORT = $previousPort }
|
|
51
51
|
}
|
|
@@ -52,13 +52,62 @@ 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
|
+
|
|
55
100
|
<% if (process.env.NODE_ENV === 'test') { %>
|
|
56
101
|
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
57
102
|
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
|
|
58
106
|
echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
|
|
59
107
|
|
|
60
108
|
# 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
|
|
61
|
-
|
|
109
|
+
# 开发环境直接使用 Next 的 dev CLI,避免云盘文件事件在 custom server 链路中丢失。
|
|
110
|
+
exec pnpm next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}"
|
|
62
111
|
<% } else { %>
|
|
63
112
|
LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
|
|
64
113
|
LOG_FILE="${LOG_DIR}/app.log"
|
|
@@ -68,7 +117,7 @@ PID_FILE="${LOG_DIR}/server.pid"
|
|
|
68
117
|
MAX_RUNTIME_SECONDS=1200
|
|
69
118
|
|
|
70
119
|
# 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
|
|
71
|
-
# (wrapper -> pnpm ->
|
|
120
|
+
# (wrapper -> pnpm -> next -> node);被包的进程自己先退出时也顺手清空进程组,不留残余。
|
|
72
121
|
RUN_WITH_TIMEOUT='
|
|
73
122
|
timeout_seconds=$1
|
|
74
123
|
shift
|
|
@@ -77,6 +126,7 @@ shift
|
|
|
77
126
|
child_pid=$!
|
|
78
127
|
|
|
79
128
|
# 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
|
|
129
|
+
if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
|
|
80
130
|
( trap "" TERM
|
|
81
131
|
sleep "${timeout_seconds}"
|
|
82
132
|
echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
|
|
@@ -84,6 +134,7 @@ child_pid=$!
|
|
|
84
134
|
sleep 5
|
|
85
135
|
kill -KILL -- "-$$" 2>/dev/null || true
|
|
86
136
|
) &
|
|
137
|
+
fi
|
|
87
138
|
|
|
88
139
|
wait "${child_pid}"
|
|
89
140
|
kill -KILL -- "-$$" 2>/dev/null || true
|
|
@@ -132,7 +183,7 @@ stop_detached() {
|
|
|
132
183
|
kill -KILL -- "-${pid}" 2>/dev/null || true
|
|
133
184
|
}
|
|
134
185
|
|
|
135
|
-
READY_RETRIES=
|
|
186
|
+
READY_RETRIES=30
|
|
136
187
|
READY_PROBE_HOSTS=("127.0.0.1" "::1")
|
|
137
188
|
LOG_TAIL_LINES=40
|
|
138
189
|
|
|
@@ -142,6 +193,21 @@ dump_log() {
|
|
|
142
193
|
echo "---- end of ${LOG_FILE} ----" >&2
|
|
143
194
|
}
|
|
144
195
|
|
|
196
|
+
# 服务刚就绪时 app-paths-manifest.json 还是空的(dev 按需编译,没请求就没产物),
|
|
197
|
+
# 但 .next/dev/types/routes.d.ts 已经写出了本次启动发现到的全部路由。把它落进日志,
|
|
198
|
+
# 排查时才能区分“路由没被发现”和“路由发现了但还没编译”。
|
|
199
|
+
dump_discovered_routes() {
|
|
200
|
+
local route_types="${COZE_WORKSPACE_PATH}/.next/dev/types/routes.d.ts"
|
|
201
|
+
if [[ ! -f "${route_types}" ]]; then
|
|
202
|
+
return
|
|
203
|
+
fi
|
|
204
|
+
{
|
|
205
|
+
echo "---- discovered routes (${route_types}) ----"
|
|
206
|
+
grep -E '^type (AppRoutes|AppRouteHandlerRoutes|PageRoutes) ' "${route_types}" || true
|
|
207
|
+
echo "---- end of discovered routes ----"
|
|
208
|
+
} >> "${LOG_FILE}"
|
|
209
|
+
}
|
|
210
|
+
|
|
145
211
|
# 仅用于无 ss/lsof 时的兜底探测。服务可能只 bind IPv4 loopback、只 bind IPv6 loopback
|
|
146
212
|
# (server.listen(port, 'localhost') 会变成 ::1 独占),或 bind 双栈通配地址,
|
|
147
213
|
port_connectable() {
|
|
@@ -215,7 +281,7 @@ wait_for_ready() {
|
|
|
215
281
|
return 2
|
|
216
282
|
}
|
|
217
283
|
|
|
218
|
-
# 监听端口的是孙进程(pnpm ->
|
|
284
|
+
# 监听端口的是孙进程(pnpm -> next -> node),只清端口会漏掉上层 pnpm/next,
|
|
219
285
|
# 所以先按上次记录的 PID 把整个进程组回收掉。
|
|
220
286
|
if [[ -f "${PID_FILE}" ]]; then
|
|
221
287
|
stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
|
|
@@ -224,6 +290,9 @@ fi
|
|
|
224
290
|
|
|
225
291
|
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
226
292
|
kill_port_if_listening
|
|
293
|
+
bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
294
|
+
warn_source_symlinks
|
|
295
|
+
refresh_drive_route_mtimes
|
|
227
296
|
echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
|
|
228
297
|
|
|
229
298
|
mkdir -p "${LOG_DIR}"
|
|
@@ -231,7 +300,7 @@ mkdir -p "${LOG_DIR}"
|
|
|
231
300
|
|
|
232
301
|
export PORT="${DEPLOY_RUN_PORT}"
|
|
233
302
|
server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
|
|
234
|
-
"$(command -v pnpm)"
|
|
303
|
+
"$(command -v pnpm)" next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}")"
|
|
235
304
|
if [[ -z "${server_pid}" ]]; then
|
|
236
305
|
echo "Dev server failed to start: 未获取到后台进程 PID。" >&2
|
|
237
306
|
dump_log
|
|
@@ -247,8 +316,7 @@ fi
|
|
|
247
316
|
|
|
248
317
|
if [[ "${ready_status}" -ne 0 ]]; then
|
|
249
318
|
if [[ "${ready_status}" -eq 2 ]]; then
|
|
250
|
-
|
|
251
|
-
echo "Dev server 在 ${READY_RETRIES} 次探测(每次 1s)内未就绪于端口 ${DEPLOY_RUN_PORT}(进程 ${server_pid} 仍在运行,已回收)。" >&2
|
|
319
|
+
echo "Dev server did not listen on port ${DEPLOY_RUN_PORT} after ${READY_RETRIES} attempts; stopping PID ${server_pid}." >&2
|
|
252
320
|
else
|
|
253
321
|
echo "Dev server failed to start. See ${LOG_FILE}." >&2
|
|
254
322
|
fi
|
|
@@ -259,6 +327,8 @@ if [[ "${ready_status}" -ne 0 ]]; then
|
|
|
259
327
|
exit 1
|
|
260
328
|
fi
|
|
261
329
|
|
|
330
|
+
dump_discovered_routes
|
|
331
|
+
|
|
262
332
|
echo "Dev server started (PID: ${server_pid}), listening on port ${DEPLOY_RUN_PORT}."
|
|
263
333
|
echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
|
|
264
334
|
echo "Log file: ${LOG_FILE}"
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install dependencies on local disk and expose them to the source tree by symlink.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
6
|
+
if [ "$(basename "$(dirname "$SCRIPT_DIR")")" = ".cozeproj" ]; then
|
|
7
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
|
|
8
|
+
else
|
|
9
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
command -v pnpm >/dev/null 2>&1 || {
|
|
13
|
+
echo "[node_modules] pnpm is required" >&2
|
|
14
|
+
exit 1
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
|
|
18
|
+
if [ -d "$DRIVE_ROOT" ]; then
|
|
19
|
+
DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
|
|
20
|
+
else
|
|
21
|
+
DRIVE_ROOT="${DRIVE_ROOT%/}"
|
|
22
|
+
fi
|
|
23
|
+
case "$PROJECT_ROOT" in
|
|
24
|
+
"$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
|
|
25
|
+
*)
|
|
26
|
+
(cd "$PROJECT_ROOT" && pnpm install "$@")
|
|
27
|
+
exit 0
|
|
28
|
+
;;
|
|
29
|
+
esac
|
|
30
|
+
|
|
31
|
+
NM_ROOT="/tmp/nm"
|
|
32
|
+
PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
|
|
33
|
+
mkdir -p "$NM_ROOT"
|
|
34
|
+
WORK_DIR="$NM_ROOT/$PROJECT_ID"
|
|
35
|
+
case "$WORK_DIR" in
|
|
36
|
+
"$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
|
|
37
|
+
echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
|
|
38
|
+
exit 1
|
|
39
|
+
;;
|
|
40
|
+
esac
|
|
41
|
+
|
|
42
|
+
LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
|
|
43
|
+
while ! mkdir "$LOCK_DIR" 2>/dev/null; do
|
|
44
|
+
echo "[node_modules] Waiting for another dependency preparation for this project..."
|
|
45
|
+
sleep 1
|
|
46
|
+
done
|
|
47
|
+
trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
|
|
48
|
+
|
|
49
|
+
mkdir -p "$WORK_DIR"
|
|
50
|
+
|
|
51
|
+
# Previous versions mirrored the whole project into WORK_DIR. That gives pnpm
|
|
52
|
+
# and framework dev servers two paths for the same source tree, which breaks
|
|
53
|
+
# file watching and on-demand compilation. Keep only managed local outputs.
|
|
54
|
+
cleanup_legacy_workspace() {
|
|
55
|
+
local workspace_dir="$1" entry name
|
|
56
|
+
if [ -L "$workspace_dir" ] || { [ -e "$workspace_dir" ] && [ ! -d "$workspace_dir" ]; }; then
|
|
57
|
+
rm -rf "$workspace_dir"
|
|
58
|
+
return
|
|
59
|
+
fi
|
|
60
|
+
if [ ! -d "$workspace_dir" ]; then
|
|
61
|
+
return 0
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
while IFS= read -r -d '' entry; do
|
|
65
|
+
name="$(basename "$entry")"
|
|
66
|
+
[ "$name" = "node_modules" ] || rm -rf "$entry"
|
|
67
|
+
done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
cleanup_legacy_shadow_project() {
|
|
71
|
+
local entry name
|
|
72
|
+
while IFS= read -r -d '' entry; do
|
|
73
|
+
name="$(basename "$entry")"
|
|
74
|
+
case "$name" in
|
|
75
|
+
node_modules|client|server) continue ;;
|
|
76
|
+
esac
|
|
77
|
+
rm -rf "$entry"
|
|
78
|
+
done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
|
|
79
|
+
|
|
80
|
+
for workspace in client server; do
|
|
81
|
+
cleanup_legacy_workspace "$WORK_DIR/$workspace"
|
|
82
|
+
done
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
copy_install_metadata() {
|
|
86
|
+
local filename source_file target_file workspace
|
|
87
|
+
for filename in package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc; do
|
|
88
|
+
source_file="$PROJECT_ROOT/$filename"
|
|
89
|
+
target_file="$WORK_DIR/$filename"
|
|
90
|
+
rm -f "$target_file"
|
|
91
|
+
if [ -f "$source_file" ]; then
|
|
92
|
+
cp "$source_file" "$target_file"
|
|
93
|
+
fi
|
|
94
|
+
done
|
|
95
|
+
|
|
96
|
+
for workspace in client server; do
|
|
97
|
+
if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
|
|
98
|
+
mkdir -p "$WORK_DIR/$workspace"
|
|
99
|
+
rm -f "$WORK_DIR/$workspace/package.json"
|
|
100
|
+
cp "$PROJECT_ROOT/$workspace/package.json" "$WORK_DIR/$workspace/package.json"
|
|
101
|
+
else
|
|
102
|
+
rm -rf "$WORK_DIR/$workspace"
|
|
103
|
+
fi
|
|
104
|
+
done
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
link_node_modules() {
|
|
108
|
+
local source_dir="$1" target_dir="$2"
|
|
109
|
+
local current=""
|
|
110
|
+
mkdir -p "$target_dir"
|
|
111
|
+
if [ -L "$source_dir/node_modules" ]; then
|
|
112
|
+
current="$(readlink "$source_dir/node_modules")"
|
|
113
|
+
case "$current" in
|
|
114
|
+
"$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
|
|
115
|
+
*)
|
|
116
|
+
echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
|
|
117
|
+
exit 1
|
|
118
|
+
;;
|
|
119
|
+
esac
|
|
120
|
+
rm "$source_dir/node_modules"
|
|
121
|
+
elif [ -e "$source_dir/node_modules" ]; then
|
|
122
|
+
rm -rf "$source_dir/node_modules"
|
|
123
|
+
fi
|
|
124
|
+
ln -s "$target_dir" "$source_dir/node_modules"
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
cleanup_legacy_shadow_project
|
|
128
|
+
copy_install_metadata
|
|
129
|
+
|
|
130
|
+
echo "[node_modules] Installing dependencies in $WORK_DIR"
|
|
131
|
+
if ! (cd "$WORK_DIR" && pnpm install "$@"); then
|
|
132
|
+
exit 1
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
|
|
136
|
+
temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
|
|
137
|
+
cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
|
|
138
|
+
chmod 0644 "$temporary_lockfile"
|
|
139
|
+
mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
|
|
143
|
+
for workspace in client server; do
|
|
144
|
+
if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
|
|
145
|
+
link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
|
|
146
|
+
fi
|
|
147
|
+
done
|
|
148
|
+
|
|
149
|
+
echo "[node_modules] Dependencies ready"
|
|
@@ -6,7 +6,4 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
|
6
6
|
cd "${COZE_WORKSPACE_PATH}"
|
|
7
7
|
|
|
8
8
|
echo "Installing dependencies..."
|
|
9
|
-
|
|
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
|
|
9
|
+
bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Metadata } from 'next';
|
|
2
|
-
import { Inspector } from 'react-dev-inspector';
|
|
3
2
|
import './globals.css';
|
|
4
3
|
|
|
5
4
|
export const metadata: Metadata = {
|
|
@@ -61,12 +60,9 @@ export default function RootLayout({
|
|
|
61
60
|
}: Readonly<{
|
|
62
61
|
children: React.ReactNode;
|
|
63
62
|
}>) {
|
|
64
|
-
const isDev = process.env.COZE_PROJECT_ENV === 'DEV';
|
|
65
|
-
|
|
66
63
|
return (
|
|
67
64
|
<html lang="en">
|
|
68
65
|
<body className={`antialiased`}>
|
|
69
|
-
{isDev && <Inspector />}
|
|
70
66
|
{children}
|
|
71
67
|
</body>
|
|
72
68
|
</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 });
|
|
10
|
+
const app = next({ dev, hostname, port, webpack: true });
|
|
11
11
|
const handle = app.getRequestHandler();
|
|
12
12
|
|
|
13
13
|
app.prepare().then(() => {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { spawn } from 'child_process';
|
|
4
|
-
import { resolve, join, basename } from 'path';
|
|
5
|
-
import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
|
|
6
|
-
import { homedir } from 'os';
|
|
7
3
|
|
|
8
4
|
|
|
9
5
|
|
|
@@ -57,61 +53,6 @@ const config = {
|
|
|
57
53
|
onAfterRender: async (_context, _outputPath) => {
|
|
58
54
|
// 输出由 init 命令统一处理
|
|
59
55
|
},
|
|
60
|
-
|
|
61
|
-
onComplete: async (_context, outputPath) => {
|
|
62
|
-
// Skip pnpm update in test environment to avoid monorepo workspace issues
|
|
63
|
-
if (process.env.NODE_ENV === 'test') {
|
|
64
|
-
console.log('⊘ Skipping dependency update in test environment');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const cmd = 'pnpm';
|
|
69
|
-
const args = ['update', 'coze-coding-dev-sdk@^0.7.25'];
|
|
70
|
-
console.log(
|
|
71
|
-
`\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const projectRoot = resolve(outputPath);
|
|
76
|
-
|
|
77
|
-
// Determine log directory
|
|
78
|
-
const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
|
|
79
|
-
const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
|
|
80
|
-
mkdirSync(logDir, { recursive: true });
|
|
81
|
-
|
|
82
|
-
// Use project name in log file to avoid conflicts
|
|
83
|
-
const projectName = basename(projectRoot);
|
|
84
|
-
const logFile = join(logDir, `${projectName}-init.log`);
|
|
85
|
-
|
|
86
|
-
// Write log header
|
|
87
|
-
const timestamp = new Date().toISOString();
|
|
88
|
-
appendFileSync(
|
|
89
|
-
logFile,
|
|
90
|
-
`\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
// Open log file for appending
|
|
94
|
-
const logFd = openSync(logFile, 'a');
|
|
95
|
-
|
|
96
|
-
// Spawn in detached mode
|
|
97
|
-
const child = spawn(cmd, args, {
|
|
98
|
-
cwd: projectRoot,
|
|
99
|
-
detached: true,
|
|
100
|
-
stdio: ['ignore', logFd, logFd],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
child.unref();
|
|
104
|
-
closeSync(logFd);
|
|
105
|
-
|
|
106
|
-
console.log(
|
|
107
|
-
'✓ coze-coding-dev-sdk update triggered (running in background)',
|
|
108
|
-
);
|
|
109
|
-
console.log(` Log file: ${logFile}`);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
|
|
112
|
-
console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
56
|
};
|
|
116
57
|
|
|
117
58
|
export default config;
|
|
@@ -34,8 +34,8 @@ importers:
|
|
|
34
34
|
specifier: ^10.4.20
|
|
35
35
|
version: 10.4.27(postcss@8.5.8)
|
|
36
36
|
coze-coding-dev-sdk:
|
|
37
|
-
specifier: ^0.7.
|
|
38
|
-
version: 0.7.
|
|
37
|
+
specifier: ^0.7.28
|
|
38
|
+
version: 0.7.28(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3)
|
|
39
39
|
eslint:
|
|
40
40
|
specifier: ^9
|
|
41
41
|
version: 9.39.4(jiti@2.7.0)
|
|
@@ -2498,8 +2498,8 @@ packages:
|
|
|
2498
2498
|
typescript:
|
|
2499
2499
|
optional: true
|
|
2500
2500
|
|
|
2501
|
-
coze-coding-dev-sdk@0.7.
|
|
2502
|
-
resolution: {integrity: sha512-
|
|
2501
|
+
coze-coding-dev-sdk@0.7.28:
|
|
2502
|
+
resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
|
|
2503
2503
|
engines: {node: '>=18.0.0'}
|
|
2504
2504
|
hasBin: true
|
|
2505
2505
|
|
|
@@ -8526,7 +8526,7 @@ snapshots:
|
|
|
8526
8526
|
optionalDependencies:
|
|
8527
8527
|
typescript: 5.9.3
|
|
8528
8528
|
|
|
8529
|
-
coze-coding-dev-sdk@0.7.
|
|
8529
|
+
coze-coding-dev-sdk@0.7.28(openai@6.27.0(ws@8.21.3)(zod@4.3.6))(ws@8.21.3):
|
|
8530
8530
|
dependencies:
|
|
8531
8531
|
'@langchain/core': 1.1.31(openai@6.27.0(ws@8.21.3)(zod@4.3.6))
|
|
8532
8532
|
'@langchain/openai': 1.2.12(@langchain/core@1.1.31(openai@6.27.0(ws@8.21.3)(zod@4.3.6)))(ws@8.21.3)
|
|
@@ -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
|
-
|
|
9
|
+
bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --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
|
|
@@ -77,6 +77,7 @@ shift
|
|
|
77
77
|
child_pid=$!
|
|
78
78
|
|
|
79
79
|
# 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
|
|
80
|
+
if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
|
|
80
81
|
( trap "" TERM
|
|
81
82
|
sleep "${timeout_seconds}"
|
|
82
83
|
echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
|
|
@@ -84,6 +85,7 @@ child_pid=$!
|
|
|
84
85
|
sleep 5
|
|
85
86
|
kill -KILL -- "-$$" 2>/dev/null || true
|
|
86
87
|
) &
|
|
88
|
+
fi
|
|
87
89
|
|
|
88
90
|
wait "${child_pid}"
|
|
89
91
|
kill -KILL -- "-$$" 2>/dev/null || true
|