@coze-arch/cli 0.0.36-alpha.b293fc → 0.0.36-alpha.e6ca88
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/README.md +66 -104
- package/docs/deploy.md +172 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +73 -18
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +1 -1
- package/lib/__templates__/native-static/.coze +2 -0
- package/lib/__templates__/native-static/scripts/serve.ps1 +7 -0
- package/lib/__templates__/nextjs/.coze +5 -0
- package/lib/__templates__/nextjs/scripts/build.ps1 +16 -0
- package/lib/__templates__/nextjs/scripts/dev.ps1 +63 -0
- package/lib/__templates__/nextjs/scripts/dev.sh +82 -1
- package/lib/__templates__/nextjs/scripts/prepare.ps1 +18 -0
- package/lib/__templates__/nextjs/scripts/start.ps1 +11 -0
- package/lib/__templates__/nextjs/scripts/validate.ps1 +8 -0
- package/lib/__templates__/nextjs/template.config.js +3 -1
- package/lib/__templates__/nuxt-vue/.coze +5 -0
- package/lib/__templates__/nuxt-vue/scripts/build.ps1 +12 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +63 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +82 -1
- package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +12 -0
- package/lib/__templates__/nuxt-vue/scripts/start.ps1 +11 -0
- package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +8 -0
- package/lib/__templates__/phaser/.coze +5 -0
- package/lib/__templates__/phaser/README.md +8 -0
- package/lib/__templates__/phaser/_gitignore +1 -0
- package/lib/__templates__/phaser/package.json +1 -1
- package/lib/__templates__/phaser/scripts/build.ps1 +12 -0
- package/lib/__templates__/phaser/scripts/dev.ps1 +49 -0
- package/lib/__templates__/phaser/scripts/dev.sh +74 -3
- package/lib/__templates__/phaser/scripts/prepare.ps1 +8 -0
- package/lib/__templates__/phaser/scripts/spawn-detached.cjs +29 -0
- package/lib/__templates__/phaser/scripts/start.ps1 +49 -0
- package/lib/__templates__/phaser/scripts/start.sh +74 -3
- package/lib/__templates__/phaser/scripts/validate.ps1 +7 -0
- package/lib/__templates__/phaser/src/global.d.ts +3 -0
- package/lib/__templates__/phaser/src/scene/BootScene.ts +4 -0
- package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +3 -0
- package/lib/__templates__/phaser/src/utils/mark-editable.ts +8 -1
- package/lib/__templates__/phaser/vite.config.ts +1 -1
- package/lib/__templates__/phaser-static/.coze +15 -0
- package/lib/__templates__/phaser-static/README.md +40 -0
- package/lib/__templates__/phaser-static/_gitignore +6 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +11 -0
- package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +20 -0
- package/lib/__templates__/phaser-static/index.html +17 -0
- package/lib/__templates__/phaser-static/scripts/serve.ps1 +7 -0
- package/lib/__templates__/phaser-static/src/assets.js +15 -0
- package/lib/__templates__/phaser-static/src/main.js +26 -0
- package/lib/__templates__/phaser-static/src/phaser.js +7 -0
- package/lib/__templates__/phaser-static/src/scene/BootScene.js +205 -0
- package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +67 -0
- package/lib/__templates__/phaser-static/src/style.css +28 -0
- package/lib/__templates__/phaser-static/src/utils/asset-loader.js +267 -0
- package/lib/__templates__/phaser-static/src/utils/index.js +2 -0
- package/lib/__templates__/phaser-static/src/utils/mark-editable.js +3 -0
- package/lib/__templates__/phaser-static/template.config.js +35 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +63 -26
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/templates.json +18 -0
- package/lib/__templates__/vite/.coze +5 -0
- package/lib/__templates__/vite/scripts/build.ps1 +16 -0
- package/lib/__templates__/vite/scripts/dev.ps1 +63 -0
- package/lib/__templates__/vite/scripts/dev.sh +82 -1
- package/lib/__templates__/vite/scripts/prepare.ps1 +18 -0
- package/lib/__templates__/vite/scripts/start.ps1 +11 -0
- package/lib/__templates__/vite/scripts/validate.ps1 +8 -0
- package/lib/__templates__/vite/template.config.js +3 -1
- package/lib/cli.js +3491 -214
- package/lib/deploy/package-project.js +244 -0
- package/lib/deploy/package-project.py +183 -0
- package/package.json +5 -4
|
@@ -8,6 +8,9 @@ cd "${COZE_WORKSPACE_PATH}"
|
|
|
8
8
|
# PID 文件,用于追踪上一次启动的进程树
|
|
9
9
|
# ---------------------------------------------------------
|
|
10
10
|
PID_FILE="/tmp/coze-dev-run.pid"
|
|
11
|
+
LOG_DIR="/tmp/coze-logs"
|
|
12
|
+
LOG_FILE="${LOG_DIR}/dev.log"
|
|
13
|
+
DEV_PID=""
|
|
11
14
|
|
|
12
15
|
# ---------------------------------------------------------
|
|
13
16
|
# 工具函数
|
|
@@ -25,6 +28,49 @@ kill_process_tree() {
|
|
|
25
28
|
fi
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
# coze-daemon 会在 runtime shell 退出时清理原进程组。
|
|
32
|
+
# 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
|
|
33
|
+
spawn_detached() {
|
|
34
|
+
local cwd="$1"
|
|
35
|
+
local log_file="$2"
|
|
36
|
+
shift 2
|
|
37
|
+
|
|
38
|
+
node - "$cwd" "$log_file" "$@" <<'NODE'
|
|
39
|
+
const fs = require('node:fs');
|
|
40
|
+
const { spawn } = require('node:child_process');
|
|
41
|
+
|
|
42
|
+
const [cwd, logFile, command, ...args] = process.argv.slice(2);
|
|
43
|
+
if (!cwd || !logFile || !command) {
|
|
44
|
+
throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const logFd = fs.openSync(logFile, 'a');
|
|
48
|
+
try {
|
|
49
|
+
const child = spawn(command, args, {
|
|
50
|
+
cwd,
|
|
51
|
+
detached: true,
|
|
52
|
+
env: process.env,
|
|
53
|
+
stdio: ['ignore', logFd, logFd],
|
|
54
|
+
});
|
|
55
|
+
child.unref();
|
|
56
|
+
process.stdout.write(String(child.pid));
|
|
57
|
+
} finally {
|
|
58
|
+
fs.closeSync(logFd);
|
|
59
|
+
}
|
|
60
|
+
NODE
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
stop_detached() {
|
|
64
|
+
local pid="${1:-}"
|
|
65
|
+
if [[ -z "${pid}" ]]; then
|
|
66
|
+
return
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
kill -TERM -- "-${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null || true
|
|
70
|
+
sleep 1
|
|
71
|
+
kill -KILL -- "-${pid}" 2>/dev/null || true
|
|
72
|
+
}
|
|
73
|
+
|
|
28
74
|
kill_port_if_listening() {
|
|
29
75
|
local port=$1
|
|
30
76
|
local pids
|
|
@@ -56,7 +102,7 @@ cleanup_previous_run() {
|
|
|
56
102
|
old_pid=$(cat "${PID_FILE}" 2>/dev/null || true)
|
|
57
103
|
if [[ -n "${old_pid}" ]] && kill -0 "${old_pid}" 2>/dev/null; then
|
|
58
104
|
echo "🧹 Killing previous dev process tree (root PID: ${old_pid})..."
|
|
59
|
-
|
|
105
|
+
stop_detached "${old_pid}"
|
|
60
106
|
fi
|
|
61
107
|
rm -f "${PID_FILE}"
|
|
62
108
|
fi
|
|
@@ -89,7 +135,8 @@ cleanup_previous_run() {
|
|
|
89
135
|
# 2. 安装依赖
|
|
90
136
|
# ---------------------------------------------------------
|
|
91
137
|
echo "📦 Installing dependencies..."
|
|
92
|
-
pnpm
|
|
138
|
+
PNPM_BIN="$(command -v pnpm)"
|
|
139
|
+
"${PNPM_BIN}" install
|
|
93
140
|
echo "✅ Dependencies installed successfully!"
|
|
94
141
|
|
|
95
142
|
# ---------------------------------------------------------
|
|
@@ -105,19 +152,7 @@ echo "Clearing port ${SERVER_PORT} (server) before start."
|
|
|
105
152
|
kill_port_if_listening "${SERVER_PORT}"
|
|
106
153
|
|
|
107
154
|
# ---------------------------------------------------------
|
|
108
|
-
# 4.
|
|
109
|
-
# ---------------------------------------------------------
|
|
110
|
-
cleanup_on_exit() {
|
|
111
|
-
echo "🛑 dev_run.sh exiting, cleaning up child processes..."
|
|
112
|
-
# 杀掉当前脚本的所有子进程
|
|
113
|
-
kill -- -$$ 2>/dev/null || true
|
|
114
|
-
rm -f "${PID_FILE}"
|
|
115
|
-
exit 0
|
|
116
|
-
}
|
|
117
|
-
trap cleanup_on_exit EXIT INT TERM HUP
|
|
118
|
-
|
|
119
|
-
# ---------------------------------------------------------
|
|
120
|
-
# 5. 启动服务
|
|
155
|
+
# 4. 启动服务
|
|
121
156
|
# ---------------------------------------------------------
|
|
122
157
|
start_service() {
|
|
123
158
|
cd "${COZE_WORKSPACE_PATH}"
|
|
@@ -134,17 +169,19 @@ start_service() {
|
|
|
134
169
|
echo "Starting Taro H5 Dev Server and NestJS Server..."
|
|
135
170
|
|
|
136
171
|
export PORT=${DEPLOY_RUN_PORT}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
mkdir -p "${LOG_DIR}"
|
|
173
|
+
: > "${LOG_FILE}"
|
|
174
|
+
|
|
175
|
+
DEV_PID="$(spawn_detached \
|
|
176
|
+
"${COZE_WORKSPACE_PATH}" \
|
|
177
|
+
"${LOG_FILE}" \
|
|
178
|
+
"${PNPM_BIN}" dev)"
|
|
179
|
+
if [[ -z "${DEV_PID}" ]]; then
|
|
180
|
+
echo "❌ 无法获取 dev 后台进程 PID"
|
|
181
|
+
return 1
|
|
182
|
+
fi
|
|
183
|
+
echo "${DEV_PID}" > "${PID_FILE}"
|
|
184
|
+
echo "📝 Dev process started with PID: ${DEV_PID} (saved to ${PID_FILE})"
|
|
148
185
|
}
|
|
149
186
|
|
|
150
187
|
echo "Starting HTTP services on port ${DEPLOY_RUN_PORT} (web) and ${SERVER_PORT} (server)..."
|
|
@@ -204,8 +204,8 @@ importers:
|
|
|
204
204
|
specifier: 2.95.3
|
|
205
205
|
version: 2.95.3
|
|
206
206
|
coze-coding-dev-sdk:
|
|
207
|
-
specifier: ^0.7.
|
|
208
|
-
version: 0.7.
|
|
207
|
+
specifier: ^0.7.25-beta.4
|
|
208
|
+
version: 0.7.25-beta.4(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
|
|
209
209
|
dotenv:
|
|
210
210
|
specifier: ^17.2.3
|
|
211
211
|
version: 17.2.3
|
|
@@ -5416,8 +5416,8 @@ packages:
|
|
|
5416
5416
|
typescript:
|
|
5417
5417
|
optional: true
|
|
5418
5418
|
|
|
5419
|
-
coze-coding-dev-sdk@0.7.
|
|
5420
|
-
resolution: {integrity: sha512
|
|
5419
|
+
coze-coding-dev-sdk@0.7.25-beta.4:
|
|
5420
|
+
resolution: {integrity: sha512-+PCoJ8yhsAIlx3YT898bCkB2gx5EMBunJMP7/kI/Jq/8dj7SDU9EUBZ2Z8ZJocSaPBT9T6dVvFHBsDLZh4FN/Q==}
|
|
5421
5421
|
engines: {node: '>=18.0.0'}
|
|
5422
5422
|
hasBin: true
|
|
5423
5423
|
|
|
@@ -17159,7 +17159,7 @@ snapshots:
|
|
|
17159
17159
|
optionalDependencies:
|
|
17160
17160
|
typescript: 5.9.3
|
|
17161
17161
|
|
|
17162
|
-
coze-coding-dev-sdk@0.7.
|
|
17162
|
+
coze-coding-dev-sdk@0.7.25-beta.4(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
|
|
17163
17163
|
dependencies:
|
|
17164
17164
|
'@langchain/core': 1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5))
|
|
17165
17165
|
'@langchain/openai': 1.2.3(@langchain/core@1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5)))(ws@8.19.0)
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@nestjs/core": "^10.4.15",
|
|
18
18
|
"@nestjs/platform-express": "^10.4.15",
|
|
19
19
|
"@supabase/supabase-js": "2.95.3",
|
|
20
|
-
"coze-coding-dev-sdk": "^0.7.
|
|
20
|
+
"coze-coding-dev-sdk": "^0.7.25-beta.4",
|
|
21
21
|
"dotenv": "^17.2.3",
|
|
22
22
|
"drizzle-kit": "^0.31.8",
|
|
23
23
|
"drizzle-orm": "^0.45.1",
|
|
@@ -119,6 +119,24 @@
|
|
|
119
119
|
"additionalProperties": false
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
|
+
{
|
|
123
|
+
"name": "phaser-static",
|
|
124
|
+
"description": "Phaser Static(纯静态 2D 游戏):coze-dev init ${COZE_WORKSPACE_PATH} --template phaser-static\n- 适用:浏览器原生 JavaScript ESM 的 Phaser 3 游戏。\n- Phaser 与 Phaser Bridge 从 CDN 加载;无需 npm、Vite 或 TypeScript。",
|
|
125
|
+
"location": "./phaser-static",
|
|
126
|
+
"paramsSchema": {
|
|
127
|
+
"type": "object",
|
|
128
|
+
"properties": {
|
|
129
|
+
"appName": {
|
|
130
|
+
"type": "string",
|
|
131
|
+
"minLength": 1,
|
|
132
|
+
"pattern": "^[a-z0-9-]+$",
|
|
133
|
+
"description": "Application name (lowercase, alphanumeric and hyphens only)"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"required": [],
|
|
137
|
+
"additionalProperties": false
|
|
138
|
+
}
|
|
139
|
+
},
|
|
122
140
|
{
|
|
123
141
|
"name": "pi-agent",
|
|
124
142
|
"description": "Pi Agent:`coze-dev init ${COZE_WORKSPACE_PATH} --template pi-agent`\n- 适用:基于 pi-agent-core 的 AI Agent 应用\n- 支持飞书、微信等多渠道接入\n- 内置 Dashboard 管理面板\n- 使用 TypeScript + Express + Vite",
|
|
@@ -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
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
Write-Host "Installing dependencies..."
|
|
7
|
+
& pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
8
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
9
|
+
|
|
10
|
+
Write-Host "Building frontend with Vite..."
|
|
11
|
+
& pnpm vite build
|
|
12
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
13
|
+
|
|
14
|
+
Write-Host "Bundling server with tsup..."
|
|
15
|
+
& pnpm tsup server/server.ts --format cjs --platform node --target node20 --outDir dist-server --no-splitting --no-minify --external vite
|
|
16
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
|
|
3
|
+
function Get-WorkspacePath {
|
|
4
|
+
if ($env:COZE_WORKSPACE_PATH) {
|
|
5
|
+
return $env:COZE_WORKSPACE_PATH
|
|
6
|
+
}
|
|
7
|
+
return (Get-Location).Path
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function Stop-ProcessTree([int] $processId) {
|
|
11
|
+
if ($processId -gt 0 -and (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
|
|
12
|
+
& taskkill.exe /PID $processId /T /F *> $null
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function Stop-ListeningProcess([int] $port) {
|
|
17
|
+
$connections = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
|
|
18
|
+
$connections | Select-Object -ExpandProperty OwningProcess -Unique | ForEach-Object {
|
|
19
|
+
Stop-ProcessTree $_
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
$workspace = Get-WorkspacePath
|
|
24
|
+
$defaultPort = <%= port %>
|
|
25
|
+
$port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { $defaultPort }
|
|
26
|
+
Set-Location $workspace
|
|
27
|
+
Stop-ListeningProcess $port
|
|
28
|
+
|
|
29
|
+
<% if (process.env.NODE_ENV === 'test') { %>
|
|
30
|
+
$env:PORT = "$port"
|
|
31
|
+
& pnpm tsx watch server/server.ts
|
|
32
|
+
exit $LASTEXITCODE
|
|
33
|
+
<% } else { %>
|
|
34
|
+
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
35
|
+
$logFile = Join-Path $logDirectory "server.log"
|
|
36
|
+
$errorLogFile = Join-Path $logDirectory "server-error.log"
|
|
37
|
+
$pidFile = Join-Path $logDirectory "server.pid"
|
|
38
|
+
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
39
|
+
|
|
40
|
+
if (Test-Path $pidFile) {
|
|
41
|
+
Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
|
|
42
|
+
Remove-Item $pidFile -Force
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
$previousPort = $env:PORT
|
|
46
|
+
$env:PORT = "$port"
|
|
47
|
+
try {
|
|
48
|
+
$process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm tsx watch server/server.ts") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
|
|
49
|
+
} finally {
|
|
50
|
+
if ($null -eq $previousPort) { Remove-Item Env:PORT -ErrorAction SilentlyContinue } else { $env:PORT = $previousPort }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$process.Id | Set-Content $pidFile
|
|
54
|
+
Start-Sleep -Seconds 1
|
|
55
|
+
if ($process.HasExited) {
|
|
56
|
+
Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
|
|
57
|
+
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
58
|
+
exit 1
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Write-Host "Dev server started (PID: $($process.Id))."
|
|
62
|
+
Write-Host "Log file: $logFile"
|
|
63
|
+
<% } %>
|
|
@@ -32,8 +32,89 @@ kill_port_if_listening() {
|
|
|
32
32
|
fi
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
<% if (process.env.NODE_ENV === 'test') { %>
|
|
36
|
+
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
37
|
+
kill_port_if_listening
|
|
38
|
+
echo "Starting express + Vite dev server on port ${DEPLOY_RUN_PORT}..."
|
|
39
|
+
|
|
40
|
+
# 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
|
|
41
|
+
exec env PORT="${DEPLOY_RUN_PORT}" pnpm tsx watch server/server.ts
|
|
42
|
+
<% } else { %>
|
|
43
|
+
LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
|
|
44
|
+
LOG_FILE="${LOG_DIR}/server.log"
|
|
45
|
+
PID_FILE="${LOG_DIR}/server.pid"
|
|
46
|
+
|
|
47
|
+
# coze-daemon 会在 runtime shell 退出时清理原进程组。
|
|
48
|
+
# 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
|
|
49
|
+
spawn_detached() {
|
|
50
|
+
local cwd="$1"
|
|
51
|
+
local log_file="$2"
|
|
52
|
+
shift 2
|
|
53
|
+
|
|
54
|
+
node - "$cwd" "$log_file" "$@" <<'NODE'
|
|
55
|
+
const fs = require('node:fs');
|
|
56
|
+
const { spawn } = require('node:child_process');
|
|
57
|
+
|
|
58
|
+
const [cwd, logFile, command, ...args] = process.argv.slice(2);
|
|
59
|
+
if (!cwd || !logFile || !command) {
|
|
60
|
+
throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const logFd = fs.openSync(logFile, 'a');
|
|
64
|
+
try {
|
|
65
|
+
const child = spawn(command, args, {
|
|
66
|
+
cwd,
|
|
67
|
+
detached: true,
|
|
68
|
+
env: process.env,
|
|
69
|
+
stdio: ['ignore', logFd, logFd],
|
|
70
|
+
});
|
|
71
|
+
child.unref();
|
|
72
|
+
process.stdout.write(String(child.pid));
|
|
73
|
+
} finally {
|
|
74
|
+
fs.closeSync(logFd);
|
|
75
|
+
}
|
|
76
|
+
NODE
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
stop_detached() {
|
|
80
|
+
local pid="${1:-}"
|
|
81
|
+
if [[ -z "${pid}" ]]; then
|
|
82
|
+
return
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
kill -TERM -- "-${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null || true
|
|
86
|
+
sleep 1
|
|
87
|
+
kill -KILL -- "-${pid}" 2>/dev/null || true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# 监听端口的是孙进程(pnpm -> tsx -> node),只清端口会漏掉上层 pnpm/tsx,
|
|
91
|
+
# 所以先按上次记录的 PID 把整个进程组回收掉。
|
|
92
|
+
if [[ -f "${PID_FILE}" ]]; then
|
|
93
|
+
stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
|
|
94
|
+
rm -f "${PID_FILE}"
|
|
95
|
+
fi
|
|
96
|
+
|
|
35
97
|
echo "Clearing port ${DEPLOY_RUN_PORT} before start."
|
|
36
98
|
kill_port_if_listening
|
|
37
99
|
echo "Starting express + Vite dev server on port ${DEPLOY_RUN_PORT}..."
|
|
38
100
|
|
|
39
|
-
|
|
101
|
+
mkdir -p "${LOG_DIR}"
|
|
102
|
+
: > "${LOG_FILE}"
|
|
103
|
+
|
|
104
|
+
export PORT="${DEPLOY_RUN_PORT}"
|
|
105
|
+
server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
|
|
106
|
+
"$(command -v pnpm)" tsx watch server/server.ts)"
|
|
107
|
+
echo "${server_pid}" > "${PID_FILE}"
|
|
108
|
+
|
|
109
|
+
sleep 1
|
|
110
|
+
if [[ -z "${server_pid}" ]] || ! kill -0 "${server_pid}" 2>/dev/null; then
|
|
111
|
+
echo "Dev server failed to start. See ${LOG_FILE}." >&2
|
|
112
|
+
tail -n 20 "${LOG_FILE}" >&2 || true
|
|
113
|
+
rm -f "${PID_FILE}"
|
|
114
|
+
exit 1
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
echo "Dev server started (PID: ${server_pid})."
|
|
118
|
+
echo "Log file: ${LOG_FILE}"
|
|
119
|
+
echo "PID file: ${PID_FILE}"
|
|
120
|
+
<% } %>
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Write-Host "Installing dependencies..."
|
|
7
|
+
& pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
8
|
+
if ($LASTEXITCODE -ne 0) {
|
|
9
|
+
exit $LASTEXITCODE
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Get-Command coze-dev -ErrorAction SilentlyContinue) {
|
|
13
|
+
& coze-dev check-bins --help *> $null
|
|
14
|
+
if ($LASTEXITCODE -eq 0) {
|
|
15
|
+
& coze-dev check-bins --fix
|
|
16
|
+
exit $LASTEXITCODE
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
|
|
3
|
+
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
4
|
+
$defaultPort = <%= port %>
|
|
5
|
+
$port = if ($env:DEPLOY_RUN_PORT) { $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { $env:PORT } else { $defaultPort }
|
|
6
|
+
Set-Location $workspace
|
|
7
|
+
|
|
8
|
+
Write-Host "Starting express production server on port $port..."
|
|
9
|
+
$env:PORT = "$port"
|
|
10
|
+
& node dist-server/server.js
|
|
11
|
+
exit $LASTEXITCODE
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { spawn } from 'child_process';
|
|
3
3
|
import { resolve, join, basename } from 'path';
|
|
4
4
|
import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
|
|
5
|
+
import { homedir } from 'os';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
@@ -81,7 +82,8 @@ const config = {
|
|
|
81
82
|
const projectRoot = resolve(outputPath);
|
|
82
83
|
|
|
83
84
|
// Determine log directory
|
|
84
|
-
const
|
|
85
|
+
const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
|
|
86
|
+
const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
|
|
85
87
|
mkdirSync(logDir, { recursive: true });
|
|
86
88
|
|
|
87
89
|
// Use project name in log file to avoid conflicts
|