@coze-arch/cli 0.1.4-alpha.b94eab → 0.1.4-alpha.f69bb1

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 (56) hide show
  1. package/lib/__templates__/expo/.coze +3 -0
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +10 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +74 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +2 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +114 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  8. package/lib/__templates__/expo/.cozeproj/scripts/validate.ps1 +7 -0
  9. package/lib/__templates__/expo/client/components/Screen.tsx +65 -25
  10. package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +6 -2
  11. package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
  12. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  13. package/lib/__templates__/expo/server/package.json +1 -1
  14. package/lib/__templates__/nextjs/eslint.config.mjs +11 -5
  15. package/lib/__templates__/nextjs/next.config.ts +10 -0
  16. package/lib/__templates__/nextjs/package.json +3 -6
  17. package/lib/__templates__/nextjs/pnpm-lock.yaml +19 -950
  18. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  19. package/lib/__templates__/nextjs/scripts/build.sh +3 -2
  20. package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
  21. package/lib/__templates__/nextjs/scripts/dev.sh +10 -5
  22. package/lib/__templates__/nextjs/scripts/prepare-next-output.sh +62 -0
  23. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +114 -0
  24. package/lib/__templates__/nextjs/scripts/prepare.sh +1 -4
  25. package/lib/__templates__/nextjs/src/app/layout.tsx +0 -4
  26. package/lib/__templates__/nextjs/src/server.ts +1 -1
  27. package/lib/__templates__/nextjs/template.config.js +0 -59
  28. package/lib/__templates__/nuxt-vue/package.json +1 -1
  29. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  30. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  31. package/lib/__templates__/nuxt-vue/scripts/dev.sh +2 -0
  32. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +114 -0
  33. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +1 -4
  34. package/lib/__templates__/pi-agent/package.json +1 -1
  35. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  36. package/lib/__templates__/taro/.coze +4 -0
  37. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +3 -2
  38. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.ps1 +3 -0
  39. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +3 -0
  40. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.ps1 +62 -0
  41. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +3 -1
  42. package/lib/__templates__/taro/.cozeproj/scripts/pack.ps1 +7 -0
  43. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +114 -0
  44. package/lib/__templates__/taro/.cozeproj/scripts/validate.ps1 +7 -0
  45. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  46. package/lib/__templates__/taro/server/package.json +1 -1
  47. package/lib/__templates__/vite/package.json +1 -1
  48. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  49. package/lib/__templates__/vite/scripts/build.sh +1 -1
  50. package/lib/__templates__/vite/scripts/dev.sh +2 -0
  51. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +114 -0
  52. package/lib/__templates__/vite/scripts/prepare.sh +1 -4
  53. package/lib/__templates__/vite/template.config.js +0 -59
  54. package/lib/cli.js +35 -12
  55. package/package.json +1 -1
  56. package/lib/__templates__/nextjs/.babelrc +0 -15
@@ -1,7 +1,8 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- cd "${COZE_WORKSPACE_PATH}"
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ cd "$ROOT_DIR"
5
6
  if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
6
7
  echo "⚙️ Initializing environment..."
7
8
  # 使用 bash 执行,确保即使没有 x 权限也能跑
@@ -11,7 +12,7 @@ else
11
12
  fi
12
13
  echo "Installing dependencies..."
13
14
  # 安装所有依赖(包含 Taro 核心和 React)
14
- pnpm install
15
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
15
16
 
16
17
  echo "Building the Taro project..."
17
18
  pnpm build
@@ -0,0 +1,3 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ Write-Host "Taro development build does not require a separate step."
@@ -1,2 +1,5 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
@@ -0,0 +1,62 @@
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
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
32
+ $port = if ($env:DEPLOY_RUN_PORT) { [int] $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { [int] $env:PORT } else { <%= port %> }
33
+ $serverPort = if ($env:SERVER_PORT) { [int] $env:SERVER_PORT } else { <%= serverPort %> }
34
+ $logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
35
+ $logFile = Join-Path $logDirectory "dev.log"
36
+ $pidFile = Join-Path $logDirectory "dev.pid"
37
+ New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
38
+
39
+ if (Test-Path $pidFile) {
40
+ Stop-ProcessTree ([int] (Get-Content $pidFile -Raw))
41
+ Remove-Item $pidFile -Force
42
+ }
43
+ Stop-ListeningProcess $port
44
+ Stop-ListeningProcess $serverPort
45
+
46
+ $environment = @{ PORT = "$port"; SERVER_PORT = "$serverPort" }
47
+ if ($env:COZE_PROJECT_DOMAIN_DEFAULT) {
48
+ $environment.PROJECT_DOMAIN = $env:COZE_PROJECT_DOMAIN_DEFAULT
49
+ }
50
+
51
+ $process = Start-DevProcess $workspace $logFile $environment
52
+ $process.Id | Set-Content $pidFile
53
+ Start-Sleep -Seconds 1
54
+ if ($process.HasExited) {
55
+ Get-Content "$logFile.error" -Tail 20 -ErrorAction SilentlyContinue
56
+ Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
57
+ exit 1
58
+ }
59
+
60
+ Write-Host "Taro H5 and NestJS services started. PID: $($process.Id)"
61
+ Write-Host "Web port: $port; server port: $serverPort"
62
+ Write-Host "Log file: $logFile"
@@ -43,6 +43,7 @@ shift
43
43
  child_pid=$!
44
44
 
45
45
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
46
+ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
46
47
  ( trap "" TERM
47
48
  sleep "${timeout_seconds}"
48
49
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -50,6 +51,7 @@ child_pid=$!
50
51
  sleep 5
51
52
  kill -KILL -- "-$$" 2>/dev/null || true
52
53
  ) &
54
+ fi
53
55
 
54
56
  wait "${child_pid}"
55
57
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -194,7 +196,7 @@ cleanup_previous_run() {
194
196
  # ---------------------------------------------------------
195
197
  echo "📦 Installing dependencies..."
196
198
  PNPM_BIN="$(command -v pnpm)"
197
- "${PNPM_BIN}" install
199
+ bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
198
200
  echo "✅ Dependencies installed successfully!"
199
201
 
200
202
  # ---------------------------------------------------------
@@ -0,0 +1,7 @@
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
+ & pnpm build:pack
7
+ exit $LASTEXITCODE
@@ -0,0 +1,114 @@
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
+ [ -d "$workspace_dir" ] || return
61
+
62
+ while IFS= read -r -d '' entry; do
63
+ name="$(basename "$entry")"
64
+ [ "$name" = "node_modules" ] || rm -rf "$entry"
65
+ done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
66
+ }
67
+
68
+ cleanup_legacy_shadow_project() {
69
+ local entry name
70
+ while IFS= read -r -d '' entry; do
71
+ name="$(basename "$entry")"
72
+ case "$name" in
73
+ node_modules|.next|client|server) continue ;;
74
+ esac
75
+ rm -rf "$entry"
76
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
77
+
78
+ for workspace in client server; do
79
+ cleanup_legacy_workspace "$WORK_DIR/$workspace"
80
+ done
81
+ }
82
+
83
+ link_node_modules() {
84
+ local source_dir="$1" target_dir="$2"
85
+ local current=""
86
+ mkdir -p "$target_dir"
87
+ if [ -L "$source_dir/node_modules" ]; then
88
+ current="$(readlink "$source_dir/node_modules")"
89
+ case "$current" in
90
+ "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
91
+ *)
92
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
93
+ exit 1
94
+ ;;
95
+ esac
96
+ rm "$source_dir/node_modules"
97
+ elif [ -e "$source_dir/node_modules" ]; then
98
+ rm -rf "$source_dir/node_modules"
99
+ fi
100
+ ln -s "$target_dir" "$source_dir/node_modules"
101
+ }
102
+
103
+ cleanup_legacy_shadow_project
104
+ link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
105
+ for workspace in client server; do
106
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
107
+ link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
108
+ fi
109
+ done
110
+
111
+ echo "[node_modules] Installing dependencies for $PROJECT_ROOT with node_modules at $WORK_DIR"
112
+ (cd "$PROJECT_ROOT" && pnpm install "$@")
113
+
114
+ echo "[node_modules] Dependencies ready"
@@ -0,0 +1,7 @@
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
+ & pnpm validate
7
+ exit $LASTEXITCODE
@@ -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.25
208
- version: 0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
207
+ specifier: ^0.7.28
208
+ version: 0.7.28(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.25:
5420
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
5419
+ coze-coding-dev-sdk@0.7.28:
5420
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
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.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
17162
+ coze-coding-dev-sdk@0.7.28(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.25",
20
+ "coze-coding-dev-sdk": "^0.7.28",
21
21
  "dotenv": "^17.2.3",
22
22
  "drizzle-kit": "^0.31.8",
23
23
  "drizzle-orm": "^0.45.1",
@@ -22,7 +22,7 @@
22
22
  "@types/express": "^5.0.0",
23
23
  "@types/node": "^22.10.5",
24
24
  "autoprefixer": "^10.4.20",
25
- "coze-coding-dev-sdk": "^0.7.25",
25
+ "coze-coding-dev-sdk": "^0.7.28",
26
26
  "esbuild": "^0.24.2",
27
27
  "eslint": "^9",
28
28
  "eslint-plugin-import": "^2.32.0",
@@ -32,8 +32,8 @@ importers:
32
32
  specifier: ^10.4.20
33
33
  version: 10.4.23(postcss@8.5.6)
34
34
  coze-coding-dev-sdk:
35
- specifier: ^0.7.25
36
- version: 0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
35
+ specifier: ^0.7.28
36
+ version: 0.7.28(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0)
37
37
  esbuild:
38
38
  specifier: ^0.27.2
39
39
  version: 0.27.2
@@ -910,8 +910,8 @@ packages:
910
910
  typescript:
911
911
  optional: true
912
912
 
913
- coze-coding-dev-sdk@0.7.25:
914
- resolution: {integrity: sha512-5683ngikMdsRW0slGTE2OAZ1Fyj0lhkC4fGNOwsqKc35e68/gtg9KmmtK9CK9SZ+5/oIn/4wLoHXFB0gHJtO2A==}
913
+ coze-coding-dev-sdk@0.7.28:
914
+ resolution: {integrity: sha512-ku7AiVWUmgCrUuMT1m2iTmHIwG39EfmcAhPASd8M7XyKxIC6A1cjIIe/3YpStRsj8pMF9LU+pxHWxisf+F44oQ==}
915
915
  engines: {node: '>=18.0.0'}
916
916
  hasBin: true
917
917
 
@@ -3281,7 +3281,7 @@ snapshots:
3281
3281
  optionalDependencies:
3282
3282
  typescript: 5.9.3
3283
3283
 
3284
- coze-coding-dev-sdk@0.7.25(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
3284
+ coze-coding-dev-sdk@0.7.28(openai@6.16.0(ws@8.19.0)(zod@4.3.5))(ws@8.19.0):
3285
3285
  dependencies:
3286
3286
  '@langchain/core': 1.1.16(openai@6.16.0(ws@8.19.0)(zod@4.3.5))
3287
3287
  '@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)
@@ -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
@@ -57,6 +57,7 @@ shift
57
57
  child_pid=$!
58
58
 
59
59
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
60
+ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
60
61
  ( trap "" TERM
61
62
  sleep "${timeout_seconds}"
62
63
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -64,6 +65,7 @@ child_pid=$!
64
65
  sleep 5
65
66
  kill -KILL -- "-$$" 2>/dev/null || true
66
67
  ) &
68
+ fi
67
69
 
68
70
  wait "${child_pid}"
69
71
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -0,0 +1,114 @@
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
+ [ -d "$workspace_dir" ] || return
61
+
62
+ while IFS= read -r -d '' entry; do
63
+ name="$(basename "$entry")"
64
+ [ "$name" = "node_modules" ] || rm -rf "$entry"
65
+ done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
66
+ }
67
+
68
+ cleanup_legacy_shadow_project() {
69
+ local entry name
70
+ while IFS= read -r -d '' entry; do
71
+ name="$(basename "$entry")"
72
+ case "$name" in
73
+ node_modules|.next|client|server) continue ;;
74
+ esac
75
+ rm -rf "$entry"
76
+ done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
77
+
78
+ for workspace in client server; do
79
+ cleanup_legacy_workspace "$WORK_DIR/$workspace"
80
+ done
81
+ }
82
+
83
+ link_node_modules() {
84
+ local source_dir="$1" target_dir="$2"
85
+ local current=""
86
+ mkdir -p "$target_dir"
87
+ if [ -L "$source_dir/node_modules" ]; then
88
+ current="$(readlink "$source_dir/node_modules")"
89
+ case "$current" in
90
+ "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
91
+ *)
92
+ echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
93
+ exit 1
94
+ ;;
95
+ esac
96
+ rm "$source_dir/node_modules"
97
+ elif [ -e "$source_dir/node_modules" ]; then
98
+ rm -rf "$source_dir/node_modules"
99
+ fi
100
+ ln -s "$target_dir" "$source_dir/node_modules"
101
+ }
102
+
103
+ cleanup_legacy_shadow_project
104
+ link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
105
+ for workspace in client server; do
106
+ if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
107
+ link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
108
+ fi
109
+ done
110
+
111
+ echo "[node_modules] Installing dependencies for $PROJECT_ROOT with node_modules at $WORK_DIR"
112
+ (cd "$PROJECT_ROOT" && pnpm install "$@")
113
+
114
+ 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
- pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
- if command -v coze-dev > /dev/null 2>&1 && coze-dev check-bins --help > /dev/null 2>&1; then
11
- coze-dev check-bins --fix
12
- fi
9
+ bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
@@ -1,8 +1,4 @@
1
1
 
2
- import { spawn } from 'child_process';
3
- import { resolve, join, basename } from 'path';
4
- import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
5
- import { homedir } from 'os';
6
2
 
7
3
 
8
4
 
@@ -64,61 +60,6 @@ const config = {
64
60
  onAfterRender: async (_context, _outputPath) => {
65
61
  // 输出由 init 命令统一处理
66
62
  },
67
-
68
- onComplete: async (_context, outputPath) => {
69
- // Skip pnpm update in test environment to avoid monorepo workspace issues
70
- if (process.env.NODE_ENV === 'test') {
71
- console.log('⊘ Skipping dependency update in test environment');
72
- return;
73
- }
74
-
75
- const cmd = 'pnpm';
76
- const args = ['update', 'coze-coding-dev-sdk@^0.7.25'];
77
- console.log(
78
- `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
79
- );
80
-
81
- try {
82
- const projectRoot = resolve(outputPath);
83
-
84
- // Determine log directory
85
- const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
86
- const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
87
- mkdirSync(logDir, { recursive: true });
88
-
89
- // Use project name in log file to avoid conflicts
90
- const projectName = basename(projectRoot);
91
- const logFile = join(logDir, `${projectName}-init.log`);
92
-
93
- // Write log header
94
- const timestamp = new Date().toISOString();
95
- appendFileSync(
96
- logFile,
97
- `\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
98
- );
99
-
100
- // Open log file for appending
101
- const logFd = openSync(logFile, 'a');
102
-
103
- // Spawn in detached mode
104
- const child = spawn(cmd, args, {
105
- cwd: projectRoot,
106
- detached: true,
107
- stdio: ['ignore', logFd, logFd],
108
- });
109
-
110
- child.unref();
111
- closeSync(logFd);
112
-
113
- console.log(
114
- '✓ coze-coding-dev-sdk update triggered (running in background)',
115
- );
116
- console.log(` Log file: ${logFile}`);
117
- } catch (error) {
118
- console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
119
- console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
120
- }
121
- },
122
63
  };
123
64
 
124
65
  export default config;
package/lib/cli.js CHANGED
@@ -2114,7 +2114,7 @@ const EventBuilder = {
2114
2114
  };
2115
2115
 
2116
2116
  var name = "@coze-arch/cli";
2117
- var version = "0.1.4-alpha.b94eab";
2117
+ var version = "0.1.4-alpha.f69bb1";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -9179,6 +9179,7 @@ const shouldRenderFile = (filePath) => {
9179
9179
  '.prettierrc',
9180
9180
  '.babelrc',
9181
9181
  '.sh',
9182
+ '.ps1',
9182
9183
  ]);
9183
9184
 
9184
9185
  const ext = path.extname(filePath).toLowerCase();
@@ -9882,18 +9883,38 @@ const execute = async (
9882
9883
  };
9883
9884
 
9884
9885
  function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
9886
+ const getDependencyPreparationCommand = (projectPath) => {
9887
+ if (fs.existsSync(path.join(projectPath, 'scripts', 'prepare.sh'))) {
9888
+ return 'bash ./scripts/prepare.sh';
9889
+ }
9890
+ if (
9891
+ fs.existsSync(
9892
+ path.join(
9893
+ projectPath,
9894
+ '.cozeproj',
9895
+ 'scripts',
9896
+ 'prepare-node-modules.sh',
9897
+ ),
9898
+ )
9899
+ ) {
9900
+ return 'bash ./.cozeproj/scripts/prepare-node-modules.sh';
9901
+ }
9902
+ return 'pnpm install';
9903
+ };
9904
+
9885
9905
  /**
9886
- * 运行 pnpm install
9906
+ * 优先通过模板提供的 wrapper 准备依赖。
9887
9907
  */
9888
- const runPnpmInstall = (projectPath) => {
9889
- logger.info('\nInstalling dependencies with pnpm...');
9908
+ const prepareDependencies = (projectPath) => {
9909
+ logger.info('\nPreparing dependencies with the project wrapper...');
9890
9910
 
9891
- const result = shelljs.exec('pnpm install', {
9911
+ const command = getDependencyPreparationCommand(projectPath);
9912
+ const result = shelljs.exec(command, {
9892
9913
  cwd: projectPath,
9893
9914
  silent: true,
9894
9915
  });
9895
9916
 
9896
- // verbose 模式下输出 pnpm install 的详细日志
9917
+ // verbose 模式下输出依赖准备命令的详细日志
9897
9918
  if (result.stdout) {
9898
9919
  logger.verbose(result.stdout);
9899
9920
  }
@@ -9902,11 +9923,11 @@ const runPnpmInstall = (projectPath) => {
9902
9923
  }
9903
9924
 
9904
9925
  if (result.code === 0) {
9905
- logger.success('Dependencies installed successfully!');
9926
+ logger.success('Dependencies prepared successfully!');
9906
9927
  } else {
9907
9928
  // 仅在失败时输出详细信息以便排查
9908
9929
  const errorMessage = [
9909
- `pnpm install failed with exit code ${result.code}`,
9930
+ `${command} failed with exit code ${result.code}`,
9910
9931
  result.stderr ? `\nStderr:\n${result.stderr}` : '',
9911
9932
  result.stdout ? `\nStdout:\n${result.stdout}` : '',
9912
9933
  ]
@@ -10131,7 +10152,7 @@ const installDependenciesStep = ctx => {
10131
10152
  try {
10132
10153
  if (!skipInstall) {
10133
10154
  if (ctx.hasPackageJson) {
10134
- runPnpmInstall(ctx.absoluteOutputPath);
10155
+ prepareDependencies(ctx.absoluteOutputPath);
10135
10156
  ctx.timer.logPhase('Dependencies installation');
10136
10157
  } else {
10137
10158
  logger.info(
@@ -10140,7 +10161,7 @@ const installDependenciesStep = ctx => {
10140
10161
  }
10141
10162
  }
10142
10163
  } catch (error) {
10143
- // 捕获 pnpm install 失败的情况
10164
+ // 捕获依赖准备失败的情况
10144
10165
  installSuccess = false;
10145
10166
  installErrorCode = 1;
10146
10167
  installErrorType = 'execution_failed';
@@ -10227,7 +10248,9 @@ const startDevServerStep = ctx => {
10227
10248
  logger.info('\nNext steps:');
10228
10249
  logger.info(` cd ${ctx.outputPath}`);
10229
10250
  if (skipInstall && ctx.hasPackageJson) {
10230
- logger.info(' pnpm install');
10251
+ logger.info(
10252
+ ` ${getDependencyPreparationCommand(ctx.absoluteOutputPath)}`,
10253
+ );
10231
10254
  }
10232
10255
  if (skipGit) {
10233
10256
  logger.info(' git init');
@@ -10339,7 +10362,7 @@ const registerCommand$1 = program => {
10339
10362
  .argument('[directory]', 'Output directory for the project')
10340
10363
  .requiredOption('-t, --template <name>', 'Template name')
10341
10364
  .option('-o, --output <path>', 'Output directory', process.cwd())
10342
- .option('--skip-install', 'Skip automatic pnpm install', false)
10365
+ .option('--skip-install', 'Skip automatic dependency preparation', false)
10343
10366
  .option('--skip-git', 'Skip automatic git initialization', false)
10344
10367
  .option(
10345
10368
  '--skip-commit',