@coze-arch/cli 0.1.8-alpha.735a86 → 0.1.8-alpha.7f9604

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 (41) hide show
  1. package/README.md +0 -18
  2. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +10 -178
  3. package/lib/__templates__/nextjs/.coze +1 -1
  4. package/lib/__templates__/nextjs/README.md +0 -18
  5. package/lib/__templates__/nextjs/eslint.config.mjs +1 -1
  6. package/lib/__templates__/nextjs/next.config.ts +9 -0
  7. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  8. package/lib/__templates__/nextjs/scripts/build.sh +2 -2
  9. package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
  10. package/lib/__templates__/nextjs/scripts/dev.sh +55 -16
  11. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +212 -0
  12. package/lib/__templates__/nextjs/scripts/prepare.sh +2 -10
  13. package/lib/__templates__/nextjs/scripts/validate.sh +1 -11
  14. package/lib/__templates__/nextjs/src/server.ts +1 -1
  15. package/lib/__templates__/nextjs/template.config.js +6 -20
  16. package/lib/__templates__/nextjs/tsconfig.json +1 -0
  17. package/lib/__templates__/nuxt-vue/.coze +1 -1
  18. package/lib/__templates__/nuxt-vue/README.md +2 -20
  19. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  20. package/lib/__templates__/nuxt-vue/scripts/dev.sh +4 -10
  21. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +212 -0
  22. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +2 -10
  23. package/lib/__templates__/nuxt-vue/scripts/validate.sh +1 -11
  24. package/lib/__templates__/taro/.cozeproj/scripts/build-on-local-disk.sh +194 -0
  25. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +1 -4
  26. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +54 -3
  27. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +40 -1
  28. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +10 -178
  29. package/lib/__templates__/vite/.coze +1 -1
  30. package/lib/__templates__/vite/README.md +0 -20
  31. package/lib/__templates__/vite/scripts/build.sh +1 -1
  32. package/lib/__templates__/vite/scripts/dev.sh +4 -10
  33. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +212 -0
  34. package/lib/__templates__/vite/scripts/prepare.sh +2 -10
  35. package/lib/__templates__/vite/scripts/validate.sh +1 -7
  36. package/lib/__templates__/vite/template.config.js +6 -20
  37. package/lib/cli.js +184 -367
  38. package/package.json +1 -2
  39. package/lib/__templates__/nextjs/scripts/local-workspace.cjs +0 -302
  40. package/lib/__templates__/nuxt-vue/scripts/local-workspace.cjs +0 -302
  41. package/lib/__templates__/vite/scripts/local-workspace.cjs +0 -302
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env bash
2
+ # Run one-shot Taro builds from a local shadow workspace when the project lives
3
+ # on Coze Drive. This avoids repeated compiler stat/read traffic against the
4
+ # network filesystem while keeping final artifacts in the project directory.
5
+ set -Eeuo pipefail
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
8
+ ROOT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
9
+ PROJECT_ROOT="$(cd "${COZE_WORKSPACE_PATH:-$ROOT_DIR}" && pwd -P)"
10
+
11
+ if [ "$#" -eq 0 ]; then
12
+ set -- pnpm build
13
+ fi
14
+
15
+ is_under_root() {
16
+ local path="$1"
17
+ local root="$2"
18
+ [ -n "$root" ] || return 1
19
+ case "$path" in
20
+ "$root"|"$root"/*) return 0 ;;
21
+ *) return 1 ;;
22
+ esac
23
+ }
24
+
25
+ is_coze_drive_workspace() {
26
+ local path="$1"
27
+ local root
28
+ local candidates=()
29
+
30
+ if [ -n "${COZE_DRIVE_ROOT:-}" ]; then
31
+ candidates+=("$COZE_DRIVE_ROOT")
32
+ fi
33
+ candidates+=("/Coze/Drive")
34
+
35
+ for root in "${candidates[@]}"; do
36
+ if [ -d "$root" ]; then
37
+ root="$(cd "$root" && pwd -P)"
38
+ else
39
+ root="${root%/}"
40
+ fi
41
+ if is_under_root "$path" "$root"; then
42
+ return 0
43
+ fi
44
+ done
45
+
46
+ return 1
47
+ }
48
+
49
+ prepare_dependencies() {
50
+ if [ "${COZE_SKIP_PREPARE_NODE_MODULES:-0}" = "1" ]; then
51
+ return
52
+ fi
53
+ echo "[local-build] Preparing dependencies..."
54
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
55
+ }
56
+
57
+ if ! is_coze_drive_workspace "$PROJECT_ROOT"; then
58
+ prepare_dependencies
59
+ cd "$PROJECT_ROOT"
60
+ "$@"
61
+ exit $?
62
+ fi
63
+
64
+ command -v rsync >/dev/null 2>&1 || {
65
+ echo "[local-build] rsync is required for Coze Drive local builds" >&2
66
+ exit 1
67
+ }
68
+
69
+ prepare_dependencies
70
+
71
+ BUILD_ROOT="${COZE_LOCAL_BUILD_ROOT:-/tmp/coze-taro-build}"
72
+ PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
73
+ WORK_DIR="$BUILD_ROOT/$PROJECT_ID"
74
+ LOCAL_WORKSPACE="$WORK_DIR/workspace"
75
+ LOCK_DIR="$WORK_DIR.lock"
76
+
77
+ mkdir -p "$BUILD_ROOT"
78
+ if is_coze_drive_workspace "$(cd "$BUILD_ROOT" && pwd -P)"; then
79
+ echo "[local-build] COZE_LOCAL_BUILD_ROOT must not be on Coze Drive: $BUILD_ROOT" >&2
80
+ exit 1
81
+ fi
82
+
83
+ while ! mkdir "$LOCK_DIR" 2>/dev/null; do
84
+ echo "[local-build] Waiting for another local build for this project..."
85
+ sleep 1
86
+ done
87
+
88
+ cleanup() {
89
+ if [ -n "${SOURCE_SYNC_PID:-}" ]; then
90
+ kill "$SOURCE_SYNC_PID" 2>/dev/null || true
91
+ fi
92
+ rm -rf "$LOCAL_WORKSPACE"
93
+ rmdir "$WORK_DIR" 2>/dev/null || true
94
+ rmdir "$LOCK_DIR" 2>/dev/null || true
95
+ }
96
+ trap cleanup EXIT
97
+
98
+ mkdir -p "$LOCAL_WORKSPACE"
99
+
100
+ sync_source_to_local() {
101
+ rsync -a --delete \
102
+ --exclude '/.git/' \
103
+ --exclude '/node_modules/' \
104
+ --exclude '/server/node_modules/' \
105
+ --exclude '/logs/' \
106
+ --exclude '/dist/' \
107
+ --exclude '/dist-web/' \
108
+ --exclude '/dist-tt/' \
109
+ --exclude '/server/dist/' \
110
+ --exclude '/.next/' \
111
+ --exclude '/.nuxt/' \
112
+ --exclude '/.output/' \
113
+ --exclude '/coverage/' \
114
+ "$PROJECT_ROOT/" "$LOCAL_WORKSPACE/"
115
+ }
116
+
117
+ echo "[local-build] Syncing source to $LOCAL_WORKSPACE"
118
+ sync_source_to_local
119
+
120
+ link_node_modules() {
121
+ local source_node_modules="$1"
122
+ local shadow_parent="$2"
123
+ local shadow_node_modules="$shadow_parent/node_modules"
124
+ local target
125
+
126
+ if [ ! -e "$source_node_modules" ] && [ ! -L "$source_node_modules" ]; then
127
+ return
128
+ fi
129
+
130
+ if [ -L "$source_node_modules" ]; then
131
+ target="$(readlink "$source_node_modules")"
132
+ else
133
+ target="$source_node_modules"
134
+ fi
135
+
136
+ mkdir -p "$shadow_parent"
137
+ rm -rf "$shadow_node_modules"
138
+ ln -s "$target" "$shadow_node_modules"
139
+ }
140
+
141
+ link_node_modules "$PROJECT_ROOT/node_modules" "$LOCAL_WORKSPACE"
142
+ for workspace in server; do
143
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
144
+ link_node_modules "$PROJECT_ROOT/$workspace/node_modules" "$LOCAL_WORKSPACE/$workspace"
145
+ fi
146
+ done
147
+
148
+ SOURCE_SYNC_PID=""
149
+ if [ "${COZE_SYNC_SOURCE_TO_LOCAL:-0}" = "1" ]; then
150
+ (
151
+ while true; do
152
+ sleep "${COZE_SYNC_INTERVAL_SECONDS:-1}"
153
+ sync_source_to_local
154
+ done
155
+ ) &
156
+ SOURCE_SYNC_PID=$!
157
+ fi
158
+
159
+ rm -rf \
160
+ "$LOCAL_WORKSPACE/dist" \
161
+ "$LOCAL_WORKSPACE/dist-web" \
162
+ "$LOCAL_WORKSPACE/dist-tt" \
163
+ "$LOCAL_WORKSPACE/server/dist"
164
+
165
+ echo "[local-build] Building on local disk..."
166
+ (
167
+ cd "$LOCAL_WORKSPACE"
168
+ export COZE_WORKSPACE_PATH="$LOCAL_WORKSPACE"
169
+ "$@"
170
+ )
171
+
172
+ sync_output_back() {
173
+ local output_name="$1"
174
+ local local_output="$LOCAL_WORKSPACE/$output_name"
175
+ local project_output="$PROJECT_ROOT/$output_name"
176
+
177
+ if [ ! -e "$local_output" ]; then
178
+ return
179
+ fi
180
+
181
+ if [ -L "$project_output" ] || [ -e "$project_output" ]; then
182
+ rm -rf "$project_output"
183
+ fi
184
+
185
+ mkdir -p "$(dirname "$project_output")"
186
+ rsync -a --delete "$local_output/" "$project_output/"
187
+ }
188
+
189
+ echo "[local-build] Syncing build artifacts back to $PROJECT_ROOT"
190
+ sync_output_back dist
191
+ sync_output_back dist-web
192
+ sync_output_back dist-tt
193
+ sync_output_back server/dist
194
+ echo "[local-build] Build artifacts are ready in the project directory"
@@ -14,10 +14,7 @@ else
14
14
  echo "⚠️ Warning: init_env.sh not found, skipping environment init."
15
15
  fi
16
16
  echo "Installing dependencies..."
17
- # 安装所有依赖(包含 Taro 核心和 React)
18
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
19
-
20
17
  echo "Building the Taro project..."
21
- pnpm build
18
+ bash "$ROOT_DIR/.cozeproj/scripts/build-on-local-disk.sh" pnpm build
22
19
 
23
20
  echo "Build completed successfully! Assets are in /dist"
@@ -119,8 +119,15 @@ process_belongs_to_workspace() {
119
119
 
120
120
  case "${cwd}" in
121
121
  "${COZE_WORKSPACE_PATH}"|"${COZE_WORKSPACE_PATH}"/*) return 0 ;;
122
- *) return 1 ;;
123
122
  esac
123
+
124
+ if [[ -n "${COZE_LOCAL_WORKSPACE_PATH:-}" ]]; then
125
+ case "${cwd}" in
126
+ "${COZE_LOCAL_WORKSPACE_PATH}"|"${COZE_LOCAL_WORKSPACE_PATH}"/*) return 0 ;;
127
+ esac
128
+ fi
129
+
130
+ return 1
124
131
  }
125
132
 
126
133
  process_group_belongs_to_workspace() {
@@ -217,6 +224,51 @@ PNPM_BIN="$(command -v pnpm)"
217
224
  bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
218
225
  echo "✅ Dependencies installed successfully!"
219
226
 
227
+ is_under_root() {
228
+ local path="$1"
229
+ local root="$2"
230
+ [ -n "$root" ] || return 1
231
+ case "$path" in
232
+ "$root"|"$root"/*) return 0 ;;
233
+ *) return 1 ;;
234
+ esac
235
+ }
236
+
237
+ is_coze_drive_workspace() {
238
+ local path="$1"
239
+ local root
240
+ local candidates=()
241
+
242
+ if [ -n "${COZE_DRIVE_ROOT:-}" ]; then
243
+ candidates+=("$COZE_DRIVE_ROOT")
244
+ fi
245
+ candidates+=("/Coze/Drive")
246
+
247
+ for root in "${candidates[@]}"; do
248
+ if [ -d "$root" ]; then
249
+ root="$(cd "$root" && pwd -P)"
250
+ else
251
+ root="${root%/}"
252
+ fi
253
+ if is_under_root "$path" "$root"; then
254
+ return 0
255
+ fi
256
+ done
257
+
258
+ return 1
259
+ }
260
+
261
+ if is_coze_drive_workspace "${COZE_WORKSPACE_PATH}"; then
262
+ COZE_LOCAL_BUILD_ROOT="${COZE_LOCAL_BUILD_ROOT:-/tmp/coze-taro-build}"
263
+ COZE_LOCAL_WORKSPACE_PATH="${COZE_LOCAL_BUILD_ROOT}/$(basename "$COZE_WORKSPACE_PATH")-$(printf '%s' "$COZE_WORKSPACE_PATH" | cksum | awk '{print $1}')/workspace"
264
+ export COZE_LOCAL_BUILD_ROOT
265
+ export COZE_LOCAL_WORKSPACE_PATH
266
+ DEV_COMMAND=(env COZE_SKIP_PREPARE_NODE_MODULES=1 COZE_SYNC_SOURCE_TO_LOCAL=1 bash "$ROOT_DIR/.cozeproj/scripts/build-on-local-disk.sh" "${PNPM_BIN}" dev)
267
+ echo "📁 Taro dev will run from a local disk workspace."
268
+ else
269
+ DEV_COMMAND=("${PNPM_BIN}" dev)
270
+ fi
271
+
220
272
  # ---------------------------------------------------------
221
273
  # 3. 清理旧进程 + 端口
222
274
  # ---------------------------------------------------------
@@ -248,7 +300,6 @@ start_service() {
248
300
  echo "⚠️ 警告: COZE_PROJECT_DOMAIN_DEFAULT 未设置,使用 .env.local 中的配置"
249
301
  fi
250
302
 
251
- # 启动 Taro H5 和 NestJS Server
252
303
  echo "Starting Taro H5 Dev Server and NestJS Server..."
253
304
 
254
305
  : > "${LOG_FILE}"
@@ -256,7 +307,7 @@ start_service() {
256
307
  DEV_PID="$(spawn_detached \
257
308
  "${COZE_WORKSPACE_PATH}" \
258
309
  "${LOG_FILE}" \
259
- "${PNPM_BIN}" dev)"
310
+ "${DEV_COMMAND[@]}")"
260
311
  if [[ -z "${DEV_PID}" ]]; then
261
312
  echo "❌ 无法获取 dev 后台进程 PID"
262
313
  return 1
@@ -1,4 +1,5 @@
1
1
  #!/bin/bash
2
+ set -Eeuo pipefail
2
3
 
3
4
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
5
  COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
@@ -6,6 +7,40 @@ export COZE_WORKSPACE_PATH
6
7
 
7
8
  cd "${COZE_WORKSPACE_PATH}"
8
9
 
10
+ is_under_root() {
11
+ local path="$1"
12
+ local root="$2"
13
+ [ -n "$root" ] || return 1
14
+ case "$path" in
15
+ "$root"|"$root"/*) return 0 ;;
16
+ *) return 1 ;;
17
+ esac
18
+ }
19
+
20
+ is_coze_drive_workspace() {
21
+ local path="$1"
22
+ local root
23
+ local candidates=()
24
+
25
+ if [ -n "${COZE_DRIVE_ROOT:-}" ]; then
26
+ candidates+=("$COZE_DRIVE_ROOT")
27
+ fi
28
+ candidates+=("/Coze/Drive")
29
+
30
+ for root in "${candidates[@]}"; do
31
+ if [ -d "$root" ]; then
32
+ root="$(cd "$root" && pwd -P)"
33
+ else
34
+ root="${root%/}"
35
+ fi
36
+ if is_under_root "$path" "$root"; then
37
+ return 0
38
+ fi
39
+ done
40
+
41
+ return 1
42
+ }
43
+
9
44
  # build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
10
45
  PID_FILE="/tmp/coze-build_weapp.pid"
11
46
 
@@ -22,7 +57,11 @@ if [ -f "$PID_FILE" ]; then
22
57
  fi
23
58
 
24
59
  # 用 setsid 创建新的进程组,方便下次整组杀掉
25
- setsid pnpm build:pack &
60
+ if is_coze_drive_workspace "${COZE_WORKSPACE_PATH}"; then
61
+ setsid bash "$ROOT_DIR/.cozeproj/scripts/build-on-local-disk.sh" pnpm build:pack &
62
+ else
63
+ setsid pnpm build:pack &
64
+ fi
26
65
  echo $! > "$PID_FILE"
27
66
 
28
67
  echo "构建已启动 (PID: $(cat $PID_FILE))"
@@ -98,7 +98,6 @@ printf '%s\n' "$$" > "$LOCK_DIR/pid"
98
98
  trap release_lock EXIT
99
99
 
100
100
  mkdir -p "$WORK_DIR"
101
- INSTALL_STATE_FILE="$WORK_DIR/.install-state"
102
101
 
103
102
  # Previous versions mirrored the whole project into WORK_DIR. That gives pnpm
104
103
  # and framework dev servers two paths for the same source tree, which breaks
@@ -119,13 +118,12 @@ cleanup_legacy_workspace() {
119
118
  done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
120
119
  }
121
120
 
122
- # Preserve existing project caches during dependency preparation.
123
121
  cleanup_legacy_shadow_project() {
124
122
  local entry name
125
123
  while IFS= read -r -d '' entry; do
126
124
  name="$(basename "$entry")"
127
125
  case "$name" in
128
- node_modules|client|server|caches|.install-state) continue ;;
126
+ node_modules|client|server) continue ;;
129
127
  esac
130
128
  rm -rf "$entry"
131
129
  done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
@@ -143,162 +141,6 @@ link_install_entry() {
143
141
  fi
144
142
  }
145
143
 
146
- hash_install_input() {
147
- if command -v sha256sum >/dev/null 2>&1; then
148
- sha256sum | awk '{print $1}'
149
- elif command -v shasum >/dev/null 2>&1; then
150
- shasum -a 256 | awk '{print $1}'
151
- else
152
- cksum | awk '{print $1 "-" $2}'
153
- fi
154
- }
155
-
156
- append_file_to_install_fingerprint() {
157
- local relative_path="$1"
158
- local source_path="$PROJECT_ROOT/$relative_path"
159
- printf 'path=%s\n' "$relative_path"
160
- if [ -f "$source_path" ]; then
161
- cat "$source_path"
162
- else
163
- printf '<missing>\n'
164
- fi
165
- }
166
-
167
- append_directory_to_install_fingerprint() {
168
- local relative_path="$1"
169
- local source_path="$PROJECT_ROOT/$relative_path"
170
- local file
171
- printf 'path=%s\n' "$relative_path"
172
- if [ ! -d "$source_path" ]; then
173
- printf '<missing>\n'
174
- return
175
- fi
176
-
177
- while IFS= read -r file; do
178
- printf 'file=%s\n' "${file#"${PROJECT_ROOT}/"}"
179
- cat "$file"
180
- done < <(find -P "$source_path" -type f -print | LC_ALL=C sort)
181
- }
182
-
183
- # Everything that can change the resolved dependency tree. The leading version marker
184
- # invalidates every stored state when this scheme itself changes.
185
- calculate_install_fingerprint() {
186
- local filename workspace argument
187
- {
188
- printf 'prepare-node-modules-install-state=1\n'
189
- printf 'node-version=%s\n' "$(node --version)"
190
- printf 'pnpm-version=%s\n' "$(pnpm --version)"
191
- printf 'node-env=%s\n' "${NODE_ENV:-}"
192
- printf 'npm-config-production=%s\n' "${npm_config_production:-}"
193
- printf 'npm-config-production-upper=%s\n' "${NPM_CONFIG_PRODUCTION:-}"
194
- printf 'pnpm-config-production=%s\n' "${PNPM_CONFIG_PRODUCTION:-}"
195
- for argument in "$@"; do
196
- printf 'install-argument=%s\n' "$argument"
197
- done
198
- for filename in package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc; do
199
- append_file_to_install_fingerprint "$filename"
200
- done
201
- for workspace in client server; do
202
- append_file_to_install_fingerprint "$workspace/package.json"
203
- done
204
- append_directory_to_install_fingerprint patches
205
- } | hash_install_input
206
- }
207
-
208
- install_requires_refresh() {
209
- local argument
210
- for argument in "$@"; do
211
- case "$argument" in
212
- --force|-f|--lockfile-only|--fix-lockfile) return 0 ;;
213
- esac
214
- done
215
- return 1
216
- }
217
-
218
- # Reuse skips pnpm install entirely, so it must not skip side effects that live outside
219
- # node_modules. preinstall is exempt: it only guards which package manager may run, and
220
- # there is no install to guard when the tree is already in place.
221
- package_has_install_lifecycle() {
222
- local package_path="$1"
223
- node - "$package_path" <<'NODE'
224
- const fs = require('node:fs');
225
- const [packagePath] = process.argv.slice(2);
226
-
227
- try {
228
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
229
- const scripts = packageJson && typeof packageJson.scripts === 'object' && packageJson.scripts
230
- ? packageJson.scripts
231
- : {};
232
- const hasLifecycle = ['install', 'postinstall', 'prepare'].some(
233
- name => typeof scripts[name] === 'string' && scripts[name].trim() !== '',
234
- );
235
-
236
- process.exit(hasLifecycle ? 0 : 1);
237
- } catch {
238
- process.exit(0);
239
- }
240
- NODE
241
- }
242
-
243
- install_reuse_is_safe() {
244
- local workspace package_path
245
- for package_path in "$PROJECT_ROOT/.pnpmfile.cjs" "$PROJECT_ROOT/.pnpmfile.js"; do
246
- if [ -e "$package_path" ]; then
247
- echo "[node_modules] Reinstalling because pnpm hooks are present: $package_path"
248
- return 1
249
- fi
250
- done
251
-
252
- if [ -f "$PROJECT_ROOT/.npmrc" ] && grep -Eq '^[[:space:]]*pnpmfile[[:space:]]*=' "$PROJECT_ROOT/.npmrc"; then
253
- echo "[node_modules] Reinstalling because .npmrc configures a pnpm hook."
254
- return 1
255
- fi
256
-
257
- for workspace in . client server; do
258
- package_path="$PROJECT_ROOT/$workspace/package.json"
259
- [ -f "$package_path" ] || continue
260
- if package_has_install_lifecycle "$package_path"; then
261
- echo "[node_modules] Reinstalling because $package_path has an install lifecycle script."
262
- return 1
263
- fi
264
- done
265
- return 0
266
- }
267
-
268
- dependencies_are_ready() {
269
- local workspace
270
- [ -f "$WORK_DIR/node_modules/.modules.yaml" ] || return 1
271
- for workspace in client server; do
272
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ] &&
273
- [ ! -f "$WORK_DIR/$workspace/node_modules/.modules.yaml" ]; then
274
- return 1
275
- fi
276
- done
277
- return 0
278
- }
279
-
280
- # 判断顺序按代价从小到大排。指纹要读云盘上的 lockfile 和整个 patches/,所以放最后:只有其余
281
- # 条件都满足、确实可能复用时才付这份开销。build.sh 和 prepare.sh 不设开关,第一行就返回了。
282
- install_can_be_reused() {
283
- local installed_fingerprint=""
284
-
285
- [ "${COZE_REUSE_NODE_MODULES:-}" = "1" ] || return 1
286
- install_requires_refresh "$@" && return 1
287
- [ -f "$INSTALL_STATE_FILE" ] || return 1
288
- IFS= read -r installed_fingerprint < "$INSTALL_STATE_FILE" || return 1
289
- dependencies_are_ready || return 1
290
- install_reuse_is_safe || return 1
291
- [ "$installed_fingerprint" = "$(calculate_install_fingerprint "$@")" ] || return 1
292
- return 0
293
- }
294
-
295
- write_install_state() {
296
- local fingerprint="$1" temporary_state
297
- temporary_state="$(mktemp "$WORK_DIR/.install-state.XXXXXX")"
298
- printf '%s\n' "$fingerprint" > "$temporary_state"
299
- mv -f "$temporary_state" "$INSTALL_STATE_FILE"
300
- }
301
-
302
144
  copy_install_metadata() {
303
145
  local filename source_file target_file workspace
304
146
  for filename in pnpm-lock.yaml pnpm-workspace.yaml .npmrc; do
@@ -348,26 +190,16 @@ link_node_modules() {
348
190
  cleanup_legacy_shadow_project
349
191
  copy_install_metadata
350
192
 
351
- if install_can_be_reused "$@"; then
352
- echo "[node_modules] Reusing unchanged dependencies in $WORK_DIR"
353
- else
354
- # A stale state file must not survive a failed install.
355
- rm -f "$INSTALL_STATE_FILE"
356
- echo "[node_modules] Installing dependencies in $WORK_DIR"
357
- if ! (cd "$WORK_DIR" && pnpm install "$@"); then
358
- exit 1
359
- fi
360
-
361
- if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
362
- temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
363
- cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
364
- chmod 0644 "$temporary_lockfile"
365
- mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
366
- fi
193
+ echo "[node_modules] Installing dependencies in $WORK_DIR"
194
+ if ! (cd "$WORK_DIR" && pnpm install "$@"); then
195
+ exit 1
196
+ fi
367
197
 
368
- # pnpm may have rewritten the lockfile, so record the fingerprint of the tree as it
369
- # now stands. Otherwise the next run would see a changed input and reinstall.
370
- write_install_state "$(calculate_install_fingerprint "$@")"
198
+ if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
199
+ temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
200
+ cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
201
+ chmod 0644 "$temporary_lockfile"
202
+ mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
371
203
  fi
372
204
 
373
205
  link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
@@ -9,7 +9,7 @@ run = ["bash", "./scripts/dev.sh"]
9
9
  run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/dev.ps1"]
10
10
  validate = ["bash", "./scripts/validate.sh"]
11
11
  validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/validate.ps1"]
12
- deps = ["git", "rsync"] # -> apt install git rsync
12
+ deps = ["git"] # -> apt install git
13
13
 
14
14
  [deploy]
15
15
  build = ["bash","./scripts/build.sh"]
@@ -228,8 +228,6 @@ app.innerHTML = `
228
228
 
229
229
  **必须使用 pnpm 管理依赖**
230
230
 
231
- 云盘开发先修改源码 `package.json`,再执行 `bash ./scripts/prepare.sh`;以下安装命令仅适用于普通本地项目。
232
-
233
231
  ```bash
234
232
  # ✅ 安装依赖
235
233
  pnpm install
@@ -418,21 +416,3 @@ const pool = new Pool({ connectionString: process.env.DATABASE_URL });
418
416
  2. 将整个项目上传到服务器
419
417
  3. 运行 `pnpm install --prod`
420
418
  4. 运行 `coze-dev start` 启动服务
421
-
422
- ## 云盘源码与本地开发
423
-
424
- Vite、Next.js、Nuxt 的 Unix 开发脚本在 `COZE_DRIVE_ROOT`(默认 `/Coze/Drive`)内通过
425
- `scripts/local-workspace.cjs` 将源码用 `rsync` 同步到本机临时目录。系统需提供 Node.js、pnpm、bash 和 rsync。
426
- 所有开发与修复仍在云盘源码目录完成,从该目录执行 `.coze` 的 `[dev]` 命令。
427
-
428
- - `prepare.sh` 同步并在本地安装依赖;安装成功且云盘依赖输入未变化时,仅将更新的锁文件回写云盘。
429
- - `dev.sh` 在本地镜像运行开发服务,每轮 rsync 结束后等待一秒再同步,框架监听本地文件进行热更新。
430
- 同步失败或依赖输入变化时停止服务;修复后重新运行 `prepare.sh` / `dev.sh`。
431
- - `validate.sh` 使用独立的本地 `check` 目录,避免类型生成影响正在运行的 `dev` 服务。
432
- - 同步排除 `.git`、`node_modules`、日志和框架输出;不要在镜像修复源码或将依赖、编译产物回传云盘。
433
- 日志和 PID 默认保留在源码目录的 `logs/`,实际镜像路径见脚本输出。
434
-
435
- 本地镜像仅用于 `[dev].build/run/validate`。部署配置、`build.sh`、`start.sh` 保持原流程;
436
- 普通本地目录和 Windows PowerShell 入口也保持原流程。
437
- 存量项目通过新版 CLI 的 `coze-dev patch --dry-run` / `coze-dev patch` 升级,沿用 patch 总开关。
438
- 仅升级完整匹配旧模板的三个 Unix 开发脚本并保留端口;自定义开发脚本、命令或同名 helper 会跳过。
@@ -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
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
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 frontend with Vite..."
12
12
  pnpm vite build
@@ -1,20 +1,14 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- # Resolve the source project from this script, then let the Web runner choose its local mirror.
5
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
6
- PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd -P)"
7
- if [[ "${COZE_WEB_LOCAL_ACTIVE:-}" != "${PROJECT_ROOT}" ]]; then
8
- exec node "${SCRIPT_DIR}/local-workspace.cjs" dev "$@"
9
- fi
10
- COZE_WORKSPACE_PATH="${PROJECT_ROOT}"
11
-
12
4
  <% if (process.env.NODE_ENV === 'test') { %>
13
5
  # 测试环境:支持环境变量覆盖端口
14
6
  PORT="${PORT:-<%= port %>}"
7
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
15
8
  DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
16
9
  <% } else { %>
17
10
  PORT=<%= port %>
11
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
18
12
  DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
19
13
  <% } %>
20
14
 
@@ -44,7 +38,7 @@ kill_port_if_listening
44
38
  echo "Starting express + Vite dev server on port ${DEPLOY_RUN_PORT}..."
45
39
 
46
40
  # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
47
- exec env PORT="${DEPLOY_RUN_PORT}" node "${SCRIPT_DIR}/local-workspace.cjs" watch pnpm tsx watch server/server.ts
41
+ exec env PORT="${DEPLOY_RUN_PORT}" pnpm tsx watch server/server.ts
48
42
  <% } else { %>
49
43
  LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
50
44
  LOG_FILE="${LOG_DIR}/server.log"
@@ -142,7 +136,7 @@ mkdir -p "${LOG_DIR}"
142
136
 
143
137
  export PORT="${DEPLOY_RUN_PORT}"
144
138
  server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
145
- "$(command -v node)" "${SCRIPT_DIR}/local-workspace.cjs" watch "$(command -v pnpm)" tsx watch server/server.ts)"
139
+ "$(command -v pnpm)" tsx watch server/server.ts)"
146
140
  echo "${server_pid}" > "${PID_FILE}"
147
141
 
148
142
  sleep 1