@coze-arch/cli 0.1.4-alpha.b94eab → 0.1.4-alpha.e5481b
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 +11 -3
- 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 +86 -10
- 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 +11 -3
- 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 +5 -1
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -0
- 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 +64 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +29 -7
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +4 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +9 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +8 -0
- package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +149 -0
- package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +9 -0
- package/lib/__templates__/taro/.cozeproj/scripts/validate.sh +4 -0
- package/lib/__templates__/taro/_gitignore +1 -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 +11 -3
- 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
|
@@ -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,10 +6,7 @@ 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
|
|
13
10
|
|
|
14
11
|
echo "Preparing Nuxt project..."
|
|
15
12
|
pnpm exec nuxt prepare
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@mariozechner/pi-ai": "^0.63.2",
|
|
23
23
|
"@mariozechner/pi-coding-agent": "^0.63.2",
|
|
24
24
|
"@sinclair/typebox": "^0.34.48",
|
|
25
|
-
"coze-coding-dev-sdk": "^0.7.
|
|
25
|
+
"coze-coding-dev-sdk": "^0.7.28",
|
|
26
26
|
"@radix-ui/react-select": "^2.2.6",
|
|
27
27
|
"@radix-ui/react-slot": "^1.2.4",
|
|
28
28
|
"@streamdown/code": "^1.1.1",
|
|
@@ -36,8 +36,8 @@ importers:
|
|
|
36
36
|
specifier: ^2.1.1
|
|
37
37
|
version: 2.1.1
|
|
38
38
|
coze-coding-dev-sdk:
|
|
39
|
-
specifier: ^0.7.
|
|
40
|
-
version: 0.7.
|
|
39
|
+
specifier: ^0.7.28
|
|
40
|
+
version: 0.7.28(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
|
|
41
41
|
express:
|
|
42
42
|
specifier: ^4.21.2
|
|
43
43
|
version: 4.22.1
|
|
@@ -2085,8 +2085,8 @@ packages:
|
|
|
2085
2085
|
cose-base@2.2.0:
|
|
2086
2086
|
resolution: {integrity: sha512-AzlgcsCbUMymkADOJtQm3wO9S3ltPfYOFD5033keQn9NJzIbtnZj+UdBJe7DYml/8TdbtHJW3j58SOnKhWY/5g==}
|
|
2087
2087
|
|
|
2088
|
-
coze-coding-dev-sdk@0.7.
|
|
2089
|
-
resolution: {integrity: sha512-
|
|
2088
|
+
coze-coding-dev-sdk@0.7.28:
|
|
2089
|
+
resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
|
|
2090
2090
|
engines: {node: '>=18.0.0'}
|
|
2091
2091
|
hasBin: true
|
|
2092
2092
|
|
|
@@ -6120,7 +6120,7 @@ snapshots:
|
|
|
6120
6120
|
dependencies:
|
|
6121
6121
|
layout-base: 2.0.1
|
|
6122
6122
|
|
|
6123
|
-
coze-coding-dev-sdk@0.7.
|
|
6123
|
+
coze-coding-dev-sdk@0.7.28(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0):
|
|
6124
6124
|
dependencies:
|
|
6125
6125
|
'@langchain/core': 1.1.40(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
|
|
6126
6126
|
'@langchain/openai': 1.4.3(@langchain/core@1.1.40(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0))(ws@8.20.0)
|
|
@@ -5,10 +5,14 @@ project_type = "miniprogram"
|
|
|
5
5
|
|
|
6
6
|
[dev]
|
|
7
7
|
build = ["bash", ".cozeproj/scripts/dev_build.sh"]
|
|
8
|
+
build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_build.ps1"]
|
|
8
9
|
run = ["bash", ".cozeproj/scripts/dev_run.sh"]
|
|
10
|
+
run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/dev_run.ps1"]
|
|
9
11
|
deps = ["git"] # -> apt install git
|
|
10
12
|
pack = ["bash", ".cozeproj/scripts/pack.sh"]
|
|
13
|
+
pack_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/pack.ps1"]
|
|
11
14
|
validate = ["bash", ".cozeproj/scripts/validate.sh"]
|
|
15
|
+
validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".cozeproj/scripts/validate.ps1"]
|
|
12
16
|
|
|
13
17
|
[deploy]
|
|
14
18
|
build = ["bash", ".cozeproj/scripts/deploy_build.sh"]
|
|
@@ -1,6 +1,10 @@
|
|
|
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
|
+
|
|
4
8
|
cd "${COZE_WORKSPACE_PATH}"
|
|
5
9
|
if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
|
|
6
10
|
echo "⚙️ Initializing environment..."
|
|
@@ -11,7 +15,7 @@ else
|
|
|
11
15
|
fi
|
|
12
16
|
echo "Installing dependencies..."
|
|
13
17
|
# 安装所有依赖(包含 Taro 核心和 React)
|
|
14
|
-
|
|
18
|
+
bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
|
|
15
19
|
|
|
16
20
|
echo "Building the Taro project..."
|
|
17
21
|
pnpm build
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
|
|
3
|
+
function Stop-ProcessTree([int] $processId) {
|
|
4
|
+
if ($processId -gt 0 -and (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
|
|
5
|
+
& taskkill.exe /PID $processId /T /F *> $null
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function Stop-ListeningProcess([int] $port) {
|
|
10
|
+
Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue |
|
|
11
|
+
Select-Object -ExpandProperty OwningProcess -Unique |
|
|
12
|
+
ForEach-Object { Stop-ProcessTree $_ }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Start-DevProcess([string] $workingDirectory, [string] $logFile, [hashtable] $environment) {
|
|
16
|
+
$previousEnvironment = @{}
|
|
17
|
+
foreach ($key in $environment.Keys) {
|
|
18
|
+
$previousEnvironment[$key] = [Environment]::GetEnvironmentVariable($key, 'Process')
|
|
19
|
+
[Environment]::SetEnvironmentVariable($key, $environment[$key], 'Process')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return Start-Process -FilePath "pnpm.cmd" -ArgumentList @("dev") -WorkingDirectory $workingDirectory -RedirectStandardOutput $logFile -RedirectStandardError "$logFile.error" -PassThru
|
|
24
|
+
} finally {
|
|
25
|
+
foreach ($key in $environment.Keys) {
|
|
26
|
+
[Environment]::SetEnvironmentVariable($key, $previousEnvironment[$key], 'Process')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
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
|
|
34
|
+
$port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { <%= port %> }
|
|
35
|
+
$serverPort = if ($env:SERVER_PORT) { [int] $env:SERVER_PORT } else { <%= serverPort %> }
|
|
36
|
+
$logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
|
|
37
|
+
$logFile = Join-Path $logDirectory "dev.log"
|
|
38
|
+
$pidFile = Join-Path $logDirectory "dev.pid"
|
|
39
|
+
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
40
|
+
|
|
41
|
+
if (Test-Path $pidFile) {
|
|
42
|
+
Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
|
|
43
|
+
Remove-Item $pidFile -Force
|
|
44
|
+
}
|
|
45
|
+
Stop-ListeningProcess $port
|
|
46
|
+
Stop-ListeningProcess $serverPort
|
|
47
|
+
|
|
48
|
+
$environment = @{ COZE_WORKSPACE_PATH = $workspace; PORT = "$port"; SERVER_PORT = "$serverPort" }
|
|
49
|
+
if ($env:COZE_PROJECT_DOMAIN_DEFAULT) {
|
|
50
|
+
$environment.PROJECT_DOMAIN = $env:COZE_PROJECT_DOMAIN_DEFAULT
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$process = Start-DevProcess $workspace $logFile $environment
|
|
54
|
+
$process.Id | Set-Content $pidFile
|
|
55
|
+
Start-Sleep -Seconds 1
|
|
56
|
+
if ($process.HasExited) {
|
|
57
|
+
Get-Content "$logFile.error" -Tail 20 -ErrorAction SilentlyContinue
|
|
58
|
+
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
59
|
+
exit 1
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Write-Host "Taro H5 and NestJS services started. PID: $($process.Id)"
|
|
63
|
+
Write-Host "Web port: $port; server port: $serverPort"
|
|
64
|
+
Write-Host "Log file: $logFile"
|
|
@@ -4,6 +4,7 @@ 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
|
|
7
8
|
cd "${COZE_WORKSPACE_PATH}"
|
|
8
9
|
|
|
9
10
|
# ---------------------------------------------------------
|
|
@@ -31,11 +32,15 @@ kill_process_tree() {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
# detached 出去的进程没人负责回收,超过这个时长就自己退出,避免端口与内存长期泄露。
|
|
34
|
-
MAX_RUNTIME_SECONDS=
|
|
35
|
+
MAX_RUNTIME_SECONDS=3600
|
|
36
|
+
|
|
37
|
+
timeout_watchdog_enabled() {
|
|
38
|
+
[[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]
|
|
39
|
+
}
|
|
35
40
|
|
|
36
41
|
# 真正被 detach 的是这层 bash wrapper:它是进程组 leader,组内 watchdog 到点回收整组
|
|
37
42
|
# (wrapper -> pnpm -> taro/nest);被包的进程自己先退出时也顺手清空进程组,不留残余。
|
|
38
|
-
RUN_WITH_TIMEOUT='
|
|
43
|
+
RUN_WITH_TIMEOUT="$(declare -f timeout_watchdog_enabled)"'
|
|
39
44
|
timeout_seconds=$1
|
|
40
45
|
shift
|
|
41
46
|
|
|
@@ -43,6 +48,7 @@ shift
|
|
|
43
48
|
child_pid=$!
|
|
44
49
|
|
|
45
50
|
# 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
|
|
51
|
+
if timeout_watchdog_enabled; then
|
|
46
52
|
( trap "" TERM
|
|
47
53
|
sleep "${timeout_seconds}"
|
|
48
54
|
echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
|
|
@@ -50,6 +56,7 @@ child_pid=$!
|
|
|
50
56
|
sleep 5
|
|
51
57
|
kill -KILL -- "-$$" 2>/dev/null || true
|
|
52
58
|
) &
|
|
59
|
+
fi
|
|
53
60
|
|
|
54
61
|
wait "${child_pid}"
|
|
55
62
|
kill -KILL -- "-$$" 2>/dev/null || true
|
|
@@ -155,12 +162,24 @@ list_port_pids() {
|
|
|
155
162
|
|
|
156
163
|
kill_port_if_listening() {
|
|
157
164
|
local port=$1
|
|
165
|
+
# 用于错误提示的端口环境变量名称,例如 DEPLOY_RUN_PORT 或 SERVER_PORT。
|
|
166
|
+
local port_env_name=$2
|
|
158
167
|
local pids
|
|
168
|
+
local pid
|
|
159
169
|
pids=$(list_port_pids "${port}")
|
|
160
170
|
if [[ -z "${pids}" ]]; then
|
|
161
171
|
echo "Port ${port} is free."
|
|
162
172
|
return
|
|
163
173
|
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
|
+
|
|
164
183
|
echo "Port ${port} in use by PIDs: ${pids} (SIGKILL)"
|
|
165
184
|
for pid in ${pids}; do
|
|
166
185
|
kill_process_tree "${pid}"
|
|
@@ -168,7 +187,8 @@ kill_port_if_listening() {
|
|
|
168
187
|
sleep 1
|
|
169
188
|
pids=$(list_port_pids "${port}")
|
|
170
189
|
if [[ -n "${pids}" ]]; then
|
|
171
|
-
echo "
|
|
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
|
|
172
192
|
else
|
|
173
193
|
echo "Port ${port} cleared."
|
|
174
194
|
fi
|
|
@@ -194,7 +214,7 @@ cleanup_previous_run() {
|
|
|
194
214
|
# ---------------------------------------------------------
|
|
195
215
|
echo "📦 Installing dependencies..."
|
|
196
216
|
PNPM_BIN="$(command -v pnpm)"
|
|
197
|
-
"$
|
|
217
|
+
bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
|
|
198
218
|
echo "✅ Dependencies installed successfully!"
|
|
199
219
|
|
|
200
220
|
# ---------------------------------------------------------
|
|
@@ -210,9 +230,9 @@ mkdir -p "${LOG_DIR}"
|
|
|
210
230
|
cleanup_previous_run
|
|
211
231
|
|
|
212
232
|
echo "Clearing port ${PORT} (web) before start."
|
|
213
|
-
kill_port_if_listening "${PORT}"
|
|
233
|
+
kill_port_if_listening "${PORT}" "DEPLOY_RUN_PORT"
|
|
214
234
|
echo "Clearing port ${SERVER_PORT} (server) before start."
|
|
215
|
-
kill_port_if_listening "${SERVER_PORT}"
|
|
235
|
+
kill_port_if_listening "${SERVER_PORT}" "SERVER_PORT"
|
|
216
236
|
|
|
217
237
|
# ---------------------------------------------------------
|
|
218
238
|
# 4. 启动服务
|
|
@@ -252,7 +272,9 @@ start_service() {
|
|
|
252
272
|
fi
|
|
253
273
|
|
|
254
274
|
echo "📝 Dev process started with PID: ${DEV_PID}"
|
|
255
|
-
|
|
275
|
+
if timeout_watchdog_enabled; then
|
|
276
|
+
echo "Auto stop after ${MAX_RUNTIME_SECONDS}s."
|
|
277
|
+
fi
|
|
256
278
|
echo "Log file: ${LOG_FILE}"
|
|
257
279
|
echo "PID file: ${PID_FILE}"
|
|
258
280
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
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
|
|
6
|
+
Set-Location $workspace
|
|
7
|
+
|
|
8
|
+
& pnpm build:pack
|
|
9
|
+
exit $LASTEXITCODE
|
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
|
|
1
9
|
# build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
|
|
2
10
|
PID_FILE="/tmp/coze-build_weapp.pid"
|
|
3
11
|
|
|
@@ -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"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
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
|
|
6
|
+
Set-Location $workspace
|
|
7
|
+
|
|
8
|
+
& pnpm validate
|
|
9
|
+
exit $LASTEXITCODE
|