@coze-arch/cli 0.0.36-alpha.1dcb49 → 0.0.36-alpha.64974b

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 (106) hide show
  1. package/README.md +66 -104
  2. package/docs/deploy.md +172 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +74 -18
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
  5. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  6. package/lib/__templates__/expo/client/metro.config.js +3 -1
  7. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  8. package/lib/__templates__/expo/server/package.json +2 -2
  9. package/lib/__templates__/expo/server/src/index.ts +1 -1
  10. package/lib/__templates__/expo/template.config.js +11 -2
  11. package/lib/__templates__/native-static/.coze +2 -0
  12. package/lib/__templates__/native-static/scripts/serve.ps1 +7 -0
  13. package/lib/__templates__/nextjs/.coze +5 -0
  14. package/lib/__templates__/nextjs/scripts/build.ps1 +16 -0
  15. package/lib/__templates__/nextjs/scripts/dev.ps1 +63 -0
  16. package/lib/__templates__/nextjs/scripts/dev.sh +83 -2
  17. package/lib/__templates__/nextjs/scripts/prepare.ps1 +18 -0
  18. package/lib/__templates__/nextjs/scripts/start.ps1 +11 -0
  19. package/lib/__templates__/nextjs/scripts/validate.ps1 +8 -0
  20. package/lib/__templates__/nextjs/template.config.js +3 -1
  21. package/lib/__templates__/nuxt-vue/.coze +5 -0
  22. package/lib/__templates__/nuxt-vue/scripts/build.ps1 +12 -0
  23. package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +63 -0
  24. package/lib/__templates__/nuxt-vue/scripts/dev.sh +82 -1
  25. package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +12 -0
  26. package/lib/__templates__/nuxt-vue/scripts/start.ps1 +11 -0
  27. package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +8 -0
  28. package/lib/__templates__/phaser/.coze +5 -0
  29. package/lib/__templates__/phaser/README.md +8 -0
  30. package/lib/__templates__/phaser/_gitignore +1 -0
  31. package/lib/__templates__/phaser/package.json +1 -1
  32. package/lib/__templates__/phaser/scripts/build.ps1 +12 -0
  33. package/lib/__templates__/phaser/scripts/dev.ps1 +49 -0
  34. package/lib/__templates__/phaser/scripts/dev.sh +74 -3
  35. package/lib/__templates__/phaser/scripts/prepare.ps1 +8 -0
  36. package/lib/__templates__/phaser/scripts/spawn-detached.cjs +29 -0
  37. package/lib/__templates__/phaser/scripts/start.ps1 +49 -0
  38. package/lib/__templates__/phaser/scripts/start.sh +74 -3
  39. package/lib/__templates__/phaser/scripts/validate.ps1 +7 -0
  40. package/lib/__templates__/phaser/src/global.d.ts +3 -0
  41. package/lib/__templates__/phaser/src/scene/BootScene.ts +4 -0
  42. package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +3 -0
  43. package/lib/__templates__/phaser/src/utils/mark-editable.ts +8 -1
  44. package/lib/__templates__/phaser/vite.config.ts +1 -25
  45. package/lib/__templates__/phaser-static/.coze +15 -0
  46. package/lib/__templates__/phaser-static/README.md +40 -0
  47. package/lib/__templates__/phaser-static/_gitignore +6 -0
  48. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  49. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  50. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  51. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  52. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  53. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  54. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  55. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  56. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  57. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  58. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  59. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  60. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  61. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  62. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  63. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  64. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  65. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  66. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  67. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  68. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  69. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  70. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  71. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  72. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +11 -0
  73. package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +20 -0
  74. package/lib/__templates__/phaser-static/index.html +17 -0
  75. package/lib/__templates__/phaser-static/scripts/serve.ps1 +7 -0
  76. package/lib/__templates__/phaser-static/src/assets.js +15 -0
  77. package/lib/__templates__/phaser-static/src/main.js +26 -0
  78. package/lib/__templates__/phaser-static/src/phaser.js +7 -0
  79. package/lib/__templates__/phaser-static/src/scene/BootScene.js +205 -0
  80. package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +67 -0
  81. package/lib/__templates__/phaser-static/src/style.css +28 -0
  82. package/lib/__templates__/phaser-static/src/utils/asset-loader.js +267 -0
  83. package/lib/__templates__/phaser-static/src/utils/index.js +2 -0
  84. package/lib/__templates__/phaser-static/src/utils/mark-editable.js +3 -0
  85. package/lib/__templates__/phaser-static/template.config.js +35 -0
  86. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
  87. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +150 -68
  88. package/lib/__templates__/taro/AGENTS.md +11 -7
  89. package/lib/__templates__/taro/README.md +4 -4
  90. package/lib/__templates__/taro/config/index.ts +10 -2
  91. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  92. package/lib/__templates__/taro/server/package.json +1 -1
  93. package/lib/__templates__/taro/server/src/main.ts +8 -2
  94. package/lib/__templates__/templates.json +26 -1
  95. package/lib/__templates__/vite/.coze +5 -0
  96. package/lib/__templates__/vite/scripts/build.ps1 +16 -0
  97. package/lib/__templates__/vite/scripts/dev.ps1 +63 -0
  98. package/lib/__templates__/vite/scripts/dev.sh +82 -1
  99. package/lib/__templates__/vite/scripts/prepare.ps1 +18 -0
  100. package/lib/__templates__/vite/scripts/start.ps1 +11 -0
  101. package/lib/__templates__/vite/scripts/validate.ps1 +8 -0
  102. package/lib/__templates__/vite/template.config.js +3 -1
  103. package/lib/cli.js +3466 -214
  104. package/lib/deploy/package-project.js +244 -0
  105. package/lib/deploy/package-project.py +183 -0
  106. package/package.json +5 -4
@@ -32,8 +32,89 @@ kill_port_if_listening() {
32
32
  fi
33
33
  }
34
34
 
35
+ <% if (process.env.NODE_ENV === 'test') { %>
36
+ echo "Clearing port ${DEPLOY_RUN_PORT} before start."
37
+ kill_port_if_listening
38
+ echo "Starting express + Vite dev server on port ${DEPLOY_RUN_PORT}..."
39
+
40
+ # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
41
+ exec env PORT="${DEPLOY_RUN_PORT}" pnpm tsx watch server/server.ts
42
+ <% } else { %>
43
+ LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
44
+ LOG_FILE="${LOG_DIR}/server.log"
45
+ PID_FILE="${LOG_DIR}/server.pid"
46
+
47
+ # coze-daemon 会在 runtime shell 退出时清理原进程组。
48
+ # 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
49
+ spawn_detached() {
50
+ local cwd="$1"
51
+ local log_file="$2"
52
+ shift 2
53
+
54
+ node - "$cwd" "$log_file" "$@" <<'NODE'
55
+ const fs = require('node:fs');
56
+ const { spawn } = require('node:child_process');
57
+
58
+ const [cwd, logFile, command, ...args] = process.argv.slice(2);
59
+ if (!cwd || !logFile || !command) {
60
+ throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
61
+ }
62
+
63
+ const logFd = fs.openSync(logFile, 'a');
64
+ try {
65
+ const child = spawn(command, args, {
66
+ cwd,
67
+ detached: true,
68
+ env: process.env,
69
+ stdio: ['ignore', logFd, logFd],
70
+ });
71
+ child.unref();
72
+ process.stdout.write(String(child.pid));
73
+ } finally {
74
+ fs.closeSync(logFd);
75
+ }
76
+ NODE
77
+ }
78
+
79
+ stop_detached() {
80
+ local pid="${1:-}"
81
+ if [[ -z "${pid}" ]]; then
82
+ return
83
+ fi
84
+
85
+ kill -TERM -- "-${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null || true
86
+ sleep 1
87
+ kill -KILL -- "-${pid}" 2>/dev/null || true
88
+ }
89
+
90
+ # 监听端口的是孙进程(pnpm -> tsx -> node),只清端口会漏掉上层 pnpm/tsx,
91
+ # 所以先按上次记录的 PID 把整个进程组回收掉。
92
+ if [[ -f "${PID_FILE}" ]]; then
93
+ stop_detached "$(cat "${PID_FILE}" 2>/dev/null || true)"
94
+ rm -f "${PID_FILE}"
95
+ fi
96
+
35
97
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
36
98
  kill_port_if_listening
37
99
  echo "Starting express + Vite dev server on port ${DEPLOY_RUN_PORT}..."
38
100
 
39
- PORT=${DEPLOY_RUN_PORT} pnpm tsx watch server/server.ts
101
+ mkdir -p "${LOG_DIR}"
102
+ : > "${LOG_FILE}"
103
+
104
+ export PORT="${DEPLOY_RUN_PORT}"
105
+ server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
106
+ "$(command -v pnpm)" tsx watch server/server.ts)"
107
+ echo "${server_pid}" > "${PID_FILE}"
108
+
109
+ sleep 1
110
+ if [[ -z "${server_pid}" ]] || ! kill -0 "${server_pid}" 2>/dev/null; then
111
+ echo "Dev server failed to start. See ${LOG_FILE}." >&2
112
+ tail -n 20 "${LOG_FILE}" >&2 || true
113
+ rm -f "${PID_FILE}"
114
+ exit 1
115
+ fi
116
+
117
+ echo "Dev server started (PID: ${server_pid})."
118
+ echo "Log file: ${LOG_FILE}"
119
+ echo "PID file: ${PID_FILE}"
120
+ <% } %>
@@ -0,0 +1,18 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ Set-Location $workspace
5
+
6
+ Write-Host "Installing dependencies..."
7
+ & pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
8
+ if ($LASTEXITCODE -ne 0) {
9
+ exit $LASTEXITCODE
10
+ }
11
+
12
+ if (Get-Command coze-dev -ErrorAction SilentlyContinue) {
13
+ & coze-dev check-bins --help *> $null
14
+ if ($LASTEXITCODE -eq 0) {
15
+ & coze-dev check-bins --fix
16
+ exit $LASTEXITCODE
17
+ }
18
+ }
@@ -0,0 +1,11 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ $defaultPort = <%= port %>
5
+ $port = if ($env:DEPLOY_RUN_PORT) { $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { $env:PORT } else { $defaultPort }
6
+ Set-Location $workspace
7
+
8
+ Write-Host "Starting express production server on port $port..."
9
+ $env:PORT = "$port"
10
+ & node dist-server/server.js
11
+ exit $LASTEXITCODE
@@ -0,0 +1,8 @@
1
+ $ErrorActionPreference = "Stop"
2
+
3
+ $workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
4
+ Set-Location $workspace
5
+
6
+ Write-Host "Running validate..."
7
+ & pnpm validate
8
+ exit $LASTEXITCODE
@@ -2,6 +2,7 @@
2
2
  import { spawn } from 'child_process';
3
3
  import { resolve, join, basename } from 'path';
4
4
  import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
5
+ import { homedir } from 'os';
5
6
 
6
7
 
7
8
 
@@ -81,7 +82,8 @@ const config = {
81
82
  const projectRoot = resolve(outputPath);
82
83
 
83
84
  // Determine log directory
84
- const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
85
+ const cozeHome = process.env.COZE_HOME || join(homedir(), '.coze');
86
+ const logDir = process.env.COZE_LOG_DIR || join(cozeHome, 'logs');
85
87
  mkdirSync(logDir, { recursive: true });
86
88
 
87
89
  // Use project name in log file to avoid conflicts