@coze-arch/cli 0.1.4-alpha.fb90f3 → 0.1.5-alpha.2e246f

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 (42) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +1 -1
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +3 -3
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +0 -2
  5. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  6. package/lib/__templates__/expo/client/components/Screen.tsx +25 -65
  7. package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +2 -6
  8. package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
  9. package/lib/__templates__/nextjs/.babelrc +15 -0
  10. package/lib/__templates__/nextjs/eslint.config.mjs +5 -11
  11. package/lib/__templates__/nextjs/next.config.ts +0 -10
  12. package/lib/__templates__/nextjs/package.json +6 -3
  13. package/lib/__templates__/nextjs/pnpm-lock.yaml +1071 -136
  14. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  15. package/lib/__templates__/nextjs/scripts/build.sh +2 -3
  16. package/lib/__templates__/nextjs/scripts/dev.sh +3 -6
  17. package/lib/__templates__/nextjs/scripts/prepare.sh +4 -1
  18. package/lib/__templates__/nextjs/src/app/layout.tsx +4 -0
  19. package/lib/__templates__/nextjs/src/server.ts +1 -1
  20. package/lib/__templates__/nextjs/template.config.js +59 -0
  21. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  22. package/lib/__templates__/nuxt-vue/scripts/dev.sh +0 -2
  23. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +4 -1
  24. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -3
  25. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -3
  26. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +1 -3
  27. package/lib/__templates__/vite/scripts/build.ps1 +1 -4
  28. package/lib/__templates__/vite/scripts/build.sh +1 -1
  29. package/lib/__templates__/vite/scripts/dev.ps1 +23 -7
  30. package/lib/__templates__/vite/scripts/dev.sh +0 -2
  31. package/lib/__templates__/vite/scripts/ensure-deps.ps1 +33 -0
  32. package/lib/__templates__/vite/scripts/prepare.ps1 +1 -6
  33. package/lib/__templates__/vite/scripts/prepare.sh +4 -1
  34. package/lib/__templates__/vite/template.config.js +59 -0
  35. package/lib/cli.js +19 -38
  36. package/package.json +1 -1
  37. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +0 -149
  38. package/lib/__templates__/nextjs/scripts/prepare-next-output.sh +0 -62
  39. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +0 -149
  40. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +0 -149
  41. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +0 -149
  42. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +0 -149
@@ -8,7 +8,7 @@ Write-Host "Installing dependencies..."
8
8
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
9
9
 
10
10
  Write-Host "Building the Next.js project..."
11
- & pnpm next build --webpack
11
+ & pnpm next build
12
12
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
13
13
 
14
14
  Write-Host "Bundling server with tsup..."
@@ -6,11 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-next-output.sh"
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
11
10
 
12
11
  echo "Building the Next.js project..."
13
- pnpm next build --webpack
12
+ pnpm next build
14
13
 
15
14
  echo "Bundling server with tsup..."
16
15
  pnpm tsup src/server.ts --format cjs --platform node --target node20 --outDir dist --no-splitting --no-minify
@@ -55,7 +55,6 @@ kill_port_if_listening() {
55
55
  <% if (process.env.NODE_ENV === 'test') { %>
56
56
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
57
57
  kill_port_if_listening
58
- bash "${COZE_WORKSPACE_PATH}/scripts/prepare-next-output.sh"
59
58
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
60
59
 
61
60
  # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
@@ -78,7 +77,6 @@ shift
78
77
  child_pid=$!
79
78
 
80
79
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
81
- if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
82
80
  ( trap "" TERM
83
81
  sleep "${timeout_seconds}"
84
82
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -86,7 +84,6 @@ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
86
84
  sleep 5
87
85
  kill -KILL -- "-$$" 2>/dev/null || true
88
86
  ) &
89
- fi
90
87
 
91
88
  wait "${child_pid}"
92
89
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -135,7 +132,7 @@ stop_detached() {
135
132
  kill -KILL -- "-${pid}" 2>/dev/null || true
136
133
  }
137
134
 
138
- READY_RETRIES=30
135
+ READY_RETRIES=10
139
136
  READY_PROBE_HOSTS=("127.0.0.1" "::1")
140
137
  LOG_TAIL_LINES=40
141
138
 
@@ -227,7 +224,6 @@ fi
227
224
 
228
225
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
229
226
  kill_port_if_listening
230
- bash "${COZE_WORKSPACE_PATH}/scripts/prepare-next-output.sh"
231
227
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
232
228
 
233
229
  mkdir -p "${LOG_DIR}"
@@ -251,7 +247,8 @@ fi
251
247
 
252
248
  if [[ "${ready_status}" -ne 0 ]]; then
253
249
  if [[ "${ready_status}" -eq 2 ]]; then
254
- echo "Dev server did not listen on port ${DEPLOY_RUN_PORT} after ${READY_RETRIES} attempts; stopping PID ${server_pid}." >&2
250
+ # 进程还活着但迟迟没监听端口:多半是编译/运行时报错后 tsx watch 驻留,日志里有真正原因。
251
+ echo "Dev server 在 ${READY_RETRIES} 次探测(每次 1s)内未就绪于端口 ${DEPLOY_RUN_PORT}(进程 ${server_pid} 仍在运行,已回收)。" >&2
255
252
  else
256
253
  echo "Dev server failed to start. See ${LOG_FILE}." >&2
257
254
  fi
@@ -6,4 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
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
@@ -1,4 +1,5 @@
1
1
  import type { Metadata } from 'next';
2
+ import { Inspector } from 'react-dev-inspector';
2
3
  import './globals.css';
3
4
 
4
5
  export const metadata: Metadata = {
@@ -60,9 +61,12 @@ export default function RootLayout({
60
61
  }: Readonly<{
61
62
  children: React.ReactNode;
62
63
  }>) {
64
+ const isDev = process.env.COZE_PROJECT_ENV === 'DEV';
65
+
63
66
  return (
64
67
  <html lang="en">
65
68
  <body className={`antialiased`}>
69
+ {isDev && <Inspector />}
66
70
  {children}
67
71
  </body>
68
72
  </html>
@@ -7,7 +7,7 @@ const hostname = process.env.HOSTNAME || 'localhost';
7
7
  const port = parseInt(process.env.PORT || '<%= port %>', 10);
8
8
 
9
9
  // Create Next.js app
10
- const app = next({ dev, hostname, port, webpack: true });
10
+ const app = next({ dev, hostname, port });
11
11
  const handle = app.getRequestHandler();
12
12
 
13
13
  app.prepare().then(() => {
@@ -1,5 +1,9 @@
1
1
 
2
2
 
3
+ import { spawn } from 'child_process';
4
+ import { resolve, join, basename } from 'path';
5
+ import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
6
+ import { homedir } from 'os';
3
7
 
4
8
 
5
9
 
@@ -53,6 +57,61 @@ const config = {
53
57
  onAfterRender: async (_context, _outputPath) => {
54
58
  // 输出由 init 命令统一处理
55
59
  },
60
+
61
+ onComplete: async (_context, outputPath) => {
62
+ // Skip pnpm update in test environment to avoid monorepo workspace issues
63
+ if (process.env.NODE_ENV === 'test') {
64
+ console.log('⊘ Skipping dependency update in test environment');
65
+ return;
66
+ }
67
+
68
+ const cmd = 'pnpm';
69
+ const args = ['update', 'coze-coding-dev-sdk@^0.7.28'];
70
+ console.log(
71
+ `\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
72
+ );
73
+
74
+ try {
75
+ const projectRoot = resolve(outputPath);
76
+
77
+ // Determine log directory
78
+ const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
79
+ const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
80
+ mkdirSync(logDir, { recursive: true });
81
+
82
+ // Use project name in log file to avoid conflicts
83
+ const projectName = basename(projectRoot);
84
+ const logFile = join(logDir, `${projectName}-init.log`);
85
+
86
+ // Write log header
87
+ const timestamp = new Date().toISOString();
88
+ appendFileSync(
89
+ logFile,
90
+ `\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
91
+ );
92
+
93
+ // Open log file for appending
94
+ const logFd = openSync(logFile, 'a');
95
+
96
+ // Spawn in detached mode
97
+ const child = spawn(cmd, args, {
98
+ cwd: projectRoot,
99
+ detached: true,
100
+ stdio: ['ignore', logFd, logFd],
101
+ });
102
+
103
+ child.unref();
104
+ closeSync(logFd);
105
+
106
+ console.log(
107
+ '✓ coze-coding-dev-sdk update triggered (running in background)',
108
+ );
109
+ console.log(` Log file: ${logFile}`);
110
+ } catch (error) {
111
+ console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
112
+ console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
113
+ }
114
+ },
56
115
  };
57
116
 
58
117
  export default config;
@@ -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
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Nuxt.js project..."
12
12
  pnpm nuxt build
@@ -77,7 +77,6 @@ shift
77
77
  child_pid=$!
78
78
 
79
79
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
80
- if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
81
80
  ( trap "" TERM
82
81
  sleep "${timeout_seconds}"
83
82
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -85,7 +84,6 @@ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
85
84
  sleep 5
86
85
  kill -KILL -- "-$$" 2>/dev/null || true
87
86
  ) &
88
- fi
89
87
 
90
88
  wait "${child_pid}"
91
89
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -6,7 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline
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
10
13
 
11
14
  echo "Preparing Nuxt project..."
12
15
  pnpm exec nuxt prepare
@@ -1,8 +1,7 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
3
 
4
- ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
- cd "$ROOT_DIR"
4
+ cd "${COZE_WORKSPACE_PATH}"
6
5
  if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
7
6
  echo "⚙️ Initializing environment..."
8
7
  # 使用 bash 执行,确保即使没有 x 权限也能跑
@@ -12,7 +11,7 @@ else
12
11
  fi
13
12
  echo "Installing dependencies..."
14
13
  # 安装所有依赖(包含 Taro 核心和 React)
15
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
14
+ pnpm install
16
15
 
17
16
  echo "Building the Taro project..."
18
17
  pnpm build
@@ -1,5 +1,2 @@
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
@@ -43,7 +43,6 @@ shift
43
43
  child_pid=$!
44
44
 
45
45
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
46
- if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
47
46
  ( trap "" TERM
48
47
  sleep "${timeout_seconds}"
49
48
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -51,7 +50,6 @@ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
51
50
  sleep 5
52
51
  kill -KILL -- "-$$" 2>/dev/null || true
53
52
  ) &
54
- fi
55
53
 
56
54
  wait "${child_pid}"
57
55
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -196,7 +194,7 @@ cleanup_previous_run() {
196
194
  # ---------------------------------------------------------
197
195
  echo "📦 Installing dependencies..."
198
196
  PNPM_BIN="$(command -v pnpm)"
199
- bash "$ROOT_DIR/.cozeproj/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
197
+ "${PNPM_BIN}" install
200
198
  echo "✅ Dependencies installed successfully!"
201
199
 
202
200
  # ---------------------------------------------------------
@@ -1,12 +1,9 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
3
  $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ & "$PSScriptRoot/ensure-deps.ps1"
4
5
  Set-Location $workspace
5
6
 
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
7
  Write-Host "Building frontend with Vite..."
11
8
  & pnpm vite build
12
9
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
@@ -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
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building frontend with Vite..."
12
12
  pnpm vite build
@@ -51,13 +51,29 @@ try {
51
51
  }
52
52
 
53
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
54
+
55
+ $startupTimeoutSeconds = 30
56
+ $startupDeadline = (Get-Date).AddSeconds($startupTimeoutSeconds)
57
+ while ((Get-Date) -lt $startupDeadline) {
58
+ if ($process.HasExited) {
59
+ Write-Error "Dev server exited before listening on port $port."
60
+ Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
61
+ Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
62
+ exit 1
63
+ }
64
+
65
+ if (Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue) {
66
+ Write-Host "Dev server is listening on port $port (PID: $($process.Id))."
67
+ Write-Host "Log file: $logFile"
68
+ exit 0
69
+ }
70
+
71
+ Start-Sleep -Milliseconds 200
59
72
  }
60
73
 
61
- Write-Host "Dev server started (PID: $($process.Id))."
62
- Write-Host "Log file: $logFile"
74
+ Write-Error "Dev server did not listen on port $port within $startupTimeoutSeconds seconds."
75
+ Stop-ProcessTree $process.Id
76
+ Get-Content $errorLogFile -Tail 20 -ErrorAction SilentlyContinue
77
+ Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
78
+ exit 1
63
79
  <% } %>
@@ -57,7 +57,6 @@ shift
57
57
  child_pid=$!
58
58
 
59
59
  # 先忽略 TERM,才能在向整组发 TERM(自己也在组里)之后存活下来补一发 KILL。
60
- if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
61
60
  ( trap "" TERM
62
61
  sleep "${timeout_seconds}"
63
62
  echo "[dev] 后台进程运行超过 ${timeout_seconds}s,回收进程组 $$。"
@@ -65,7 +64,6 @@ if [[ -z "${COZE_EVAL:-}" && -z "${COZE_PROJECT_TYPE:-}" ]]; then
65
64
  sleep 5
66
65
  kill -KILL -- "-$$" 2>/dev/null || true
67
66
  ) &
68
- fi
69
67
 
70
68
  wait "${child_pid}"
71
69
  kill -KILL -- "-$$" 2>/dev/null || true
@@ -0,0 +1,33 @@
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
+ $lockfile = Join-Path $workspace "pnpm-lock.yaml"
7
+ $modulesDirectory = Join-Path $workspace "node_modules"
8
+ $modulesManifest = Join-Path $modulesDirectory ".modules.yaml"
9
+ $lockHashFile = Join-Path $modulesDirectory ".coze-lockfile-sha256"
10
+
11
+ if (-not (Test-Path $lockfile)) {
12
+ throw "pnpm-lock.yaml is required to install dependencies."
13
+ }
14
+
15
+ $lockHash = (Get-FileHash -LiteralPath $lockfile -Algorithm SHA256).Hash
16
+ $cachedLockHash = if (Test-Path $lockHashFile) {
17
+ (Get-Content -LiteralPath $lockHashFile -Raw).Trim()
18
+ } else {
19
+ ""
20
+ }
21
+
22
+ if ((Test-Path $modulesManifest) -and $cachedLockHash -eq $lockHash) {
23
+ Write-Host "Dependencies already match pnpm-lock.yaml; skipping install."
24
+ return
25
+ }
26
+
27
+ Write-Host "Installing dependencies..."
28
+ & pnpm install --frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
29
+ if ($LASTEXITCODE -ne 0) {
30
+ throw "pnpm install failed with exit code $LASTEXITCODE."
31
+ }
32
+
33
+ Set-Content -LiteralPath $lockHashFile -Value $lockHash -NoNewline
@@ -1,14 +1,9 @@
1
1
  $ErrorActionPreference = "Stop"
2
2
 
3
3
  $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ & "$PSScriptRoot/ensure-deps.ps1"
4
5
  Set-Location $workspace
5
6
 
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
7
  if (Get-Command coze-dev -ErrorAction SilentlyContinue) {
13
8
  & coze-dev check-bins --help *> $null
14
9
  if ($LASTEXITCODE -eq 0) {
@@ -6,4 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
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
@@ -1,4 +1,8 @@
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';
2
6
 
3
7
 
4
8
 
@@ -60,6 +64,61 @@ const config = {
60
64
  onAfterRender: async (_context, _outputPath) => {
61
65
  // 输出由 init 命令统一处理
62
66
  },
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.28'];
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
+ },
63
122
  };
64
123
 
65
124
  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.fb90f3";
2117
+ var version = "0.1.5-alpha.2e246f";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -9883,38 +9883,18 @@ const execute = async (
9883
9883
  };
9884
9884
 
9885
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
-
9905
9886
  /**
9906
- * 优先通过模板提供的 wrapper 准备依赖。
9887
+ * 运行 pnpm install
9907
9888
  */
9908
- const prepareDependencies = (projectPath) => {
9909
- logger.info('\nPreparing dependencies with the project wrapper...');
9889
+ const runPnpmInstall = (projectPath) => {
9890
+ logger.info('\nInstalling dependencies with pnpm...');
9910
9891
 
9911
- const command = getDependencyPreparationCommand(projectPath);
9912
- const result = shelljs.exec(command, {
9892
+ const result = shelljs.exec('pnpm install', {
9913
9893
  cwd: projectPath,
9914
9894
  silent: true,
9915
9895
  });
9916
9896
 
9917
- // verbose 模式下输出依赖准备命令的详细日志
9897
+ // verbose 模式下输出 pnpm install 的详细日志
9918
9898
  if (result.stdout) {
9919
9899
  logger.verbose(result.stdout);
9920
9900
  }
@@ -9923,11 +9903,11 @@ const prepareDependencies = (projectPath) => {
9923
9903
  }
9924
9904
 
9925
9905
  if (result.code === 0) {
9926
- logger.success('Dependencies prepared successfully!');
9906
+ logger.success('Dependencies installed successfully!');
9927
9907
  } else {
9928
9908
  // 仅在失败时输出详细信息以便排查
9929
9909
  const errorMessage = [
9930
- `${command} failed with exit code ${result.code}`,
9910
+ `pnpm install failed with exit code ${result.code}`,
9931
9911
  result.stderr ? `\nStderr:\n${result.stderr}` : '',
9932
9912
  result.stdout ? `\nStdout:\n${result.stdout}` : '',
9933
9913
  ]
@@ -10152,7 +10132,7 @@ const installDependenciesStep = ctx => {
10152
10132
  try {
10153
10133
  if (!skipInstall) {
10154
10134
  if (ctx.hasPackageJson) {
10155
- prepareDependencies(ctx.absoluteOutputPath);
10135
+ runPnpmInstall(ctx.absoluteOutputPath);
10156
10136
  ctx.timer.logPhase('Dependencies installation');
10157
10137
  } else {
10158
10138
  logger.info(
@@ -10161,7 +10141,7 @@ const installDependenciesStep = ctx => {
10161
10141
  }
10162
10142
  }
10163
10143
  } catch (error) {
10164
- // 捕获依赖准备失败的情况
10144
+ // 捕获 pnpm install 失败的情况
10165
10145
  installSuccess = false;
10166
10146
  installErrorCode = 1;
10167
10147
  installErrorType = 'execution_failed';
@@ -10248,9 +10228,7 @@ const startDevServerStep = ctx => {
10248
10228
  logger.info('\nNext steps:');
10249
10229
  logger.info(` cd ${ctx.outputPath}`);
10250
10230
  if (skipInstall && ctx.hasPackageJson) {
10251
- logger.info(
10252
- ` ${getDependencyPreparationCommand(ctx.absoluteOutputPath)}`,
10253
- );
10231
+ logger.info(' pnpm install');
10254
10232
  }
10255
10233
  if (skipGit) {
10256
10234
  logger.info(' git init');
@@ -10362,7 +10340,7 @@ const registerCommand$1 = program => {
10362
10340
  .argument('[directory]', 'Output directory for the project')
10363
10341
  .requiredOption('-t, --template <name>', 'Template name')
10364
10342
  .option('-o, --output <path>', 'Output directory', process.cwd())
10365
- .option('--skip-install', 'Skip automatic dependency preparation', false)
10343
+ .option('--skip-install', 'Skip automatic pnpm install', false)
10366
10344
  .option('--skip-git', 'Skip automatic git initialization', false)
10367
10345
  .option(
10368
10346
  '--skip-commit',
@@ -11107,7 +11085,10 @@ class DeployApiClient {
11107
11085
  if (cozeAccount) {
11108
11086
  headers['x-coze-account'] = cozeAccount;
11109
11087
  }
11110
- const lane = _optionalChain$a([this, 'access', _4 => _4.globalOptions, 'access', _5 => _5.lane, 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]) || _optionalChain$a([this, 'access', _8 => _8.config, 'access', _9 => _9.xTTEnv, 'optionalAccess', _10 => _10.trim, 'call', _11 => _11()]);
11088
+ // Deployment traffic must only enter a PPE lane when the caller explicitly
11089
+ // opts in for this invocation. The shared CLI config may contain xTTEnv for
11090
+ // other command families, but it must not silently affect deployments.
11091
+ const lane = _optionalChain$a([this, 'access', _4 => _4.globalOptions, 'access', _5 => _5.lane, 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]);
11111
11092
  if (lane) {
11112
11093
  headers['x-use-ppe'] = '1';
11113
11094
  headers['x-tt-env'] = lane;
@@ -11138,7 +11119,7 @@ class DeployApiClient {
11138
11119
  if (!response.ok) {
11139
11120
  const root = isRecord(payload) ? payload : undefined;
11140
11121
  throw new CliError(
11141
- typeof _optionalChain$a([root, 'optionalAccess', _12 => _12.msg]) === 'string'
11122
+ typeof _optionalChain$a([root, 'optionalAccess', _8 => _8.msg]) === 'string'
11142
11123
  ? root.msg.slice(0, MAX_MESSAGE_LENGTH)
11143
11124
  : `Deployment API failed: ${response.status} ${response.statusText}` +
11144
11125
  `${validJson ? '' : '; response was not JSON'}`,
@@ -11571,7 +11552,7 @@ const registerContext = (program) => {
11571
11552
  organization_id: runtime.config.organizationId,
11572
11553
  space_id: runtime.config.spaceId,
11573
11554
  project_id: runtime.config.projectId,
11574
- lane: runtime.globalOptions.lane || runtime.config.xTTEnv,
11555
+ lane: runtime.globalOptions.lane,
11575
11556
  config_path: runtime.globalOptions.config || getSharedConfigPath(),
11576
11557
  });
11577
11558
  });
@@ -13508,7 +13489,7 @@ const registerDeploy = (deploy) => {
13508
13489
  risks: config.risk_list || [],
13509
13490
  ...(!appId && deploymentName ? { name: deploymentName } : {}),
13510
13491
  message: options.message,
13511
- lane: runtime.globalOptions.lane || runtime.config.xTTEnv,
13492
+ lane: runtime.globalOptions.lane,
13512
13493
  });
13513
13494
  return;
13514
13495
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.4-alpha.fb90f3",
3
+ "version": "0.1.5-alpha.2e246f",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",