@coze-arch/cli 0.0.36-alpha.3ab612 → 0.0.36-alpha.4e6503

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 (151) hide show
  1. package/README.md +104 -68
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +19 -80
  3. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
  4. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  5. package/lib/__templates__/expo/client/metro.config.js +1 -3
  6. package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
  7. package/lib/__templates__/expo/server/package.json +2 -2
  8. package/lib/__templates__/expo/server/src/index.ts +1 -1
  9. package/lib/__templates__/expo/template.config.js +2 -11
  10. package/lib/__templates__/native-static/.coze +0 -2
  11. package/lib/__templates__/nextjs/.coze +0 -5
  12. package/lib/__templates__/nextjs/package.json +1 -1
  13. package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
  14. package/lib/__templates__/nextjs/scripts/dev.sh +7 -205
  15. package/lib/__templates__/nextjs/template.config.js +2 -4
  16. package/lib/__templates__/nuxt-vue/.coze +0 -5
  17. package/lib/__templates__/nuxt-vue/package.json +1 -1
  18. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
  19. package/lib/__templates__/nuxt-vue/scripts/dev.sh +1 -82
  20. package/lib/__templates__/pi-agent/package.json +1 -1
  21. package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
  22. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
  23. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +68 -150
  24. package/lib/__templates__/taro/AGENTS.md +7 -11
  25. package/lib/__templates__/taro/README.md +4 -4
  26. package/lib/__templates__/taro/config/index.ts +2 -10
  27. package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
  28. package/lib/__templates__/taro/server/package.json +1 -1
  29. package/lib/__templates__/taro/server/src/main.ts +2 -8
  30. package/lib/__templates__/templates.json +1 -51
  31. package/lib/__templates__/vite/package.json +1 -1
  32. package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
  33. package/lib/__templates__/vite/scripts/build.ps1 +1 -1
  34. package/lib/__templates__/vite/scripts/dev.ps1 +65 -9
  35. package/lib/__templates__/vite/scripts/dev.sh +1 -82
  36. package/lib/__templates__/vite/scripts/start.ps1 +8 -2
  37. package/lib/__templates__/vite/template.config.js +2 -4
  38. package/lib/cli.js +204 -3590
  39. package/package.json +3 -5
  40. package/docs/deploy.md +0 -179
  41. package/lib/__templates__/native-static/scripts/serve.ps1 +0 -7
  42. package/lib/__templates__/nextjs/scripts/build.ps1 +0 -16
  43. package/lib/__templates__/nextjs/scripts/dev.ps1 +0 -63
  44. package/lib/__templates__/nextjs/scripts/prepare.ps1 +0 -18
  45. package/lib/__templates__/nextjs/scripts/start.ps1 +0 -11
  46. package/lib/__templates__/nextjs/scripts/validate.ps1 +0 -8
  47. package/lib/__templates__/nuxt-vue/scripts/build.ps1 +0 -12
  48. package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +0 -63
  49. package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +0 -12
  50. package/lib/__templates__/nuxt-vue/scripts/start.ps1 +0 -11
  51. package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +0 -8
  52. package/lib/__templates__/phaser/.coze +0 -18
  53. package/lib/__templates__/phaser/README.md +0 -45
  54. package/lib/__templates__/phaser/_gitignore +0 -23
  55. package/lib/__templates__/phaser/_npmrc +0 -14
  56. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  57. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  58. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  59. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  60. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  61. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  62. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  63. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  64. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  65. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  66. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  67. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  68. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  69. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  70. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  71. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  72. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  73. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  74. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  75. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  76. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  77. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  78. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  79. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  80. package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +0 -11
  81. package/lib/__templates__/phaser/debug-runtime/flow-graph.json +0 -20
  82. package/lib/__templates__/phaser/index.html +0 -12
  83. package/lib/__templates__/phaser/package.json +0 -31
  84. package/lib/__templates__/phaser/pnpm-lock.yaml +0 -661
  85. package/lib/__templates__/phaser/scripts/build.ps1 +0 -12
  86. package/lib/__templates__/phaser/scripts/build.sh +0 -8
  87. package/lib/__templates__/phaser/scripts/dev.ps1 +0 -49
  88. package/lib/__templates__/phaser/scripts/dev.sh +0 -82
  89. package/lib/__templates__/phaser/scripts/prepare.ps1 +0 -8
  90. package/lib/__templates__/phaser/scripts/prepare.sh +0 -7
  91. package/lib/__templates__/phaser/scripts/spawn-detached.cjs +0 -29
  92. package/lib/__templates__/phaser/scripts/start.ps1 +0 -49
  93. package/lib/__templates__/phaser/scripts/start.sh +0 -82
  94. package/lib/__templates__/phaser/scripts/validate.ps1 +0 -7
  95. package/lib/__templates__/phaser/scripts/validate.sh +0 -7
  96. package/lib/__templates__/phaser/src/assets.ts +0 -15
  97. package/lib/__templates__/phaser/src/global.d.ts +0 -39
  98. package/lib/__templates__/phaser/src/main.ts +0 -28
  99. package/lib/__templates__/phaser/src/scene/BootScene.ts +0 -213
  100. package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +0 -69
  101. package/lib/__templates__/phaser/src/style.css +0 -28
  102. package/lib/__templates__/phaser/src/types.ts +0 -32
  103. package/lib/__templates__/phaser/src/utils/asset-loader.ts +0 -319
  104. package/lib/__templates__/phaser/src/utils/index.ts +0 -2
  105. package/lib/__templates__/phaser/src/utils/mark-editable.ts +0 -13
  106. package/lib/__templates__/phaser/template.config.js +0 -43
  107. package/lib/__templates__/phaser/tsconfig.json +0 -23
  108. package/lib/__templates__/phaser/vite.config.ts +0 -96
  109. package/lib/__templates__/phaser-static/.coze +0 -15
  110. package/lib/__templates__/phaser-static/README.md +0 -40
  111. package/lib/__templates__/phaser-static/_gitignore +0 -6
  112. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
  113. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
  114. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
  115. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
  116. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
  117. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
  118. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
  119. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
  120. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
  121. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
  122. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
  123. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
  124. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
  125. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
  126. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
  127. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
  128. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
  129. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
  130. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
  131. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
  132. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
  133. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
  134. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
  135. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
  136. package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +0 -11
  137. package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +0 -20
  138. package/lib/__templates__/phaser-static/index.html +0 -17
  139. package/lib/__templates__/phaser-static/scripts/serve.ps1 +0 -7
  140. package/lib/__templates__/phaser-static/src/assets.js +0 -15
  141. package/lib/__templates__/phaser-static/src/main.js +0 -26
  142. package/lib/__templates__/phaser-static/src/phaser.js +0 -7
  143. package/lib/__templates__/phaser-static/src/scene/BootScene.js +0 -205
  144. package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +0 -67
  145. package/lib/__templates__/phaser-static/src/style.css +0 -28
  146. package/lib/__templates__/phaser-static/src/utils/asset-loader.js +0 -267
  147. package/lib/__templates__/phaser-static/src/utils/index.js +0 -2
  148. package/lib/__templates__/phaser-static/src/utils/mark-editable.js +0 -3
  149. package/lib/__templates__/phaser-static/template.config.js +0 -35
  150. package/lib/deploy/package-project.js +0 -244
  151. package/lib/deploy/package-project.py +0 -183
package/README.md CHANGED
@@ -1,107 +1,143 @@
1
- # @coze-arch/cli
1
+ # @coze-coding/cli
2
2
 
3
- Coze Coding 的项目模板与本地运行 CLI。发布包名为 `@coze-arch/cli`,命令为
4
- `coze-dev`。
3
+ Coze Coding 的项目模板引擎,提供基于前端技术栈的项目初始化能力。
4
+
5
+ ## 特性
6
+
7
+ - 🚀 **快速初始化**: 一键创建预配置的项目模板
8
+ - 🤖 **AI 优先设计**: 专为 AI Agent 消费设计,提供清晰的错误信息和自描述能力
9
+ - 📦 **多模板支持**: 支持 React、Next.js、HTML 等多种技术栈
10
+ - 🔧 **类型安全**: 基于 JSON Schema 的参数校验和 TypeScript 类型生成
11
+ - ⚡ **命令代理**: 统一的 dev/build/start 命令,抹平不同技术栈差异
5
12
 
6
13
  ## 安装
7
14
 
8
15
  ```bash
9
- npm install -g @coze-arch/cli
10
- coze-dev --help
16
+ rush update
17
+
11
18
  ```
12
19
 
13
- 也可以不全局安装:
20
+ ## 使用
21
+
22
+ ### 初始化项目
14
23
 
15
24
  ```bash
16
- npx @coze-arch/cli --help
25
+ coze-coding init --template react --app-name my-app --use-typescript --use-tailwind
17
26
  ```
18
27
 
19
- ## 初始化项目
28
+ ### 查看可用模板
20
29
 
21
30
  ```bash
22
- coze-dev init my-app --template <template> --app-name my-app
23
- coze-dev init --help
31
+ coze-coding init --help
24
32
  ```
25
33
 
26
- `init` 默认会渲染模板、安装依赖、初始化 Git、创建初始提交并启动开发服务。按需使用
27
- `--skip-install`、`--skip-git`、`--skip-commit`、`--skip-dev` 跳过这些步骤。模板名称和
28
- 参数以 `coze-dev init --help` 的实时输出为准;未声明的参数会以 kebab-case 转为
29
- camelCase 后传给模板。
34
+ ### 开发命令
30
35
 
31
- ## 在项目中运行
36
+ ```bash
37
+ # 启动开发服务器
38
+ coze-coding dev
32
39
 
33
- 初始化产物根目录的 `.coze` 是统一命令契约:
40
+ # 构建生产版本
41
+ coze-coding build
34
42
 
35
- ```bash
36
- coze-dev dev # 读取 dev.run
37
- coze-dev build # 读取 deploy.build
38
- coze-dev start # 读取 deploy.run
39
- coze-dev validate # 读取 dev.validate
43
+ # 启动生产服务器
44
+ coze-coding start
40
45
  ```
41
46
 
42
- `dev` 和 `build` 在执行前会尝试应用模板补丁;补丁失败会记录调试信息,但不会阻止主命令。
43
- 子进程日志默认写入 `~/.coze-logs/dev.log`,可用 `--log-file <path>` 覆盖。
47
+ ## 模板参数
44
48
 
45
- ## Windows WSL
49
+ 每个模板都有自己的参数配置,通过 CLI 参数透传。参数名使用 kebab-case 格式,会自动转换为 camelCase 传入模板配置。
46
50
 
47
- 原生 Windows(`process.platform === "win32"`)优先使用 `.coze` 中非空的 Windows
48
- 覆盖命令;未配置时回退默认命令。WSL 被识别为 Linux,始终执行默认命令。
51
+ 例如:
52
+ - `--app-name` → `appName`
53
+ - `--use-typescript` → `useTypeScript`
54
+ - `--port` → `port`
49
55
 
50
- | CLI 命令或场景 | 默认字段 | Windows 覆盖字段 |
51
- | --- | --- | --- |
52
- | `coze-dev dev` | `dev.run` | `dev.run_win` |
53
- | `coze-dev build` | `deploy.build` | `deploy.build_win` |
54
- | `coze-dev start` | `deploy.run` | `deploy.run_win` |
55
- | `coze-dev validate` | `dev.validate` | `dev.validate_win` |
56
- | `coze-dev deploy` 的本地打包 | `dev.pack` | `dev.pack_win` |
56
+ ## 开发模板
57
57
 
58
- 已支持 Windows 的内置 Web 与 Phaser 模板将覆盖命令映射到 PowerShell 脚本,例如:
58
+ ### 模板结构
59
59
 
60
- ```toml
61
- [dev]
62
- run = ["bash", "./scripts/dev.sh"]
63
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/dev.ps1"]
60
+ ```
61
+ template-name/
62
+ ├── template.config.ts # 模板配置(开发时)
63
+ ├── template.config.js # 模板配置(生产时)
64
+ ├── .coze # 项目配置文件
65
+ └── src/ # 源代码(支持 EJS 模板)
66
+ ```
64
67
 
65
- [deploy]
66
- build = ["bash", "./scripts/build.sh"]
67
- build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/build.ps1"]
68
+ ### 参数定义
69
+
70
+ 使用 JSON Schema 定义模板参数:
71
+
72
+ ```typescript
73
+ import type { JSONSchemaType } from 'ajv';
74
+
75
+ export interface TemplateParams {
76
+ appName: string;
77
+ useTypeScript: boolean;
78
+ port: number;
79
+ }
80
+
81
+ export const paramsSchema: JSONSchemaType<TemplateParams> = {
82
+ type: 'object',
83
+ properties: {
84
+ appName: {
85
+ type: 'string',
86
+ minLength: 1,
87
+ pattern: '^[a-z0-9-]+$',
88
+ cliParam: '--app-name',
89
+ description: 'Application name'
90
+ },
91
+ useTypeScript: {
92
+ type: 'boolean',
93
+ default: true,
94
+ cliParam: '--use-typescript',
95
+ description: 'Enable TypeScript'
96
+ },
97
+ port: {
98
+ type: 'number',
99
+ default: 3000,
100
+ minimum: 1024,
101
+ maximum: 65535,
102
+ cliParam: '--port',
103
+ description: 'Development server port'
104
+ }
105
+ },
106
+ required: ['appName'],
107
+ additionalProperties: false
108
+ };
68
109
  ```
69
110
 
70
- ## 部署
111
+ ### 生命周期钩子
71
112
 
72
- `coze-dev deploy` 内置于同一 CLI。认证优先读取
73
- `~/.coze/desktop/runtime.beta.json`,其次读取 `~/.coze/desktop/runtime.json`;
74
- 桌面 Token 不可用时再回退到 `COZE_API_TOKEN` 和 `~/.coze/cli/config.json` 登录态:
113
+ ```typescript
114
+ export const onBeforeRender = (context) => {
115
+ // 渲染前处理
116
+ return context;
117
+ };
75
118
 
76
- ```bash
77
- coze-dev deploy auth login
78
- coze-dev deploy doctor
79
- coze-dev deploy code deploy --source-root . --yes --wait
119
+ export const onAfterRender = (context, outputPath) => {
120
+ // 渲染后处理
121
+ };
80
122
  ```
81
123
 
82
- 完整的应用、环境变量、Pages 和小程序命令说明见 [部署文档](./docs/deploy.md)。
83
- `dev.pack_win` 是自定义模板可选的 Windows 打包覆盖;当前 Expo、Taro 和 Pi Agent 模板
84
- 不承诺 Windows 支持。
124
+ ## 编码规范
85
125
 
86
- ## 模板开发
126
+ 本项目严格遵循函数式编程风格:
87
127
 
88
- 模板位于 `src/__templates__/`,每个模板通过 `template.config.ts` 定义参数和渲染钩子,
89
- `.coze` 定义生成项目的运行命令。新增模板或修改模板目录后执行:
128
+ - 使用纯函数和不可变数据
129
+ - ✅ 函数组合和高阶函数
130
+ - ✅ 使用工厂函数和闭包
131
+ - ❌ 禁止使用 class
132
+ - ❌ 避免副作用和可变状态
90
133
 
91
- ```bash
92
- npm run prebuild
93
- ```
134
+ 详见 [技术设计文档](./docs/technical-design.md#7-编码规范)
94
135
 
95
- 模板开发细节见 [模板开发指南](./docs/how-to-dev.md)。仓库开发依赖由 Rush 管理,不要在本包目录单独执行 `npm install` 或 `pnpm install`。
136
+ ## 文档
96
137
 
97
- ## 本地开发与验证
138
+ - [需求文档](./docs/requirement.md)
139
+ - [技术设计](./docs/technical-design.md)
98
140
 
99
- 源码入口支持直接运行,无需先构建:
100
-
101
- ```bash
102
- node src/cli.js --help
103
- npm run test
104
- npm run build
105
- ```
141
+ ## 许可证
106
142
 
107
- 端到端模板验证使用 `npm run test:e2e`,会真实安装模板依赖并启动服务。发布前需完成该验证。
143
+ 内部项目
@@ -1,27 +1,18 @@
1
- #!/usr/bin/env bash
2
-
3
1
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
2
  PREVIEW_DIR="/source/preview"
5
3
  LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
6
4
  LOG_CLIENT_FILE="$LOG_DIR/client.log"
7
- LOG_SERVER_FILE="$LOG_DIR/server.log"
8
5
  mkdir -p "$LOG_DIR"
9
6
 
10
7
  # ==================== 配置项 ====================
11
8
  # Server 服务配置
12
9
  SERVER_HOST="0.0.0.0"
13
- SERVER_PORT="${SERVER_PORT:-<%= serverPort %>}"
10
+ SERVER_PORT="9091"
14
11
  # Expo 项目配置
15
12
  EXPO_HOST="0.0.0.0"
16
13
  EXPO_DIR="expo"
17
- # DEPLOY_RUN_PORT 是平台注入的对外端口,EXPO_PORT 保留为本地覆盖项。
18
- EXPO_PORT="${DEPLOY_RUN_PORT:-${EXPO_PORT:-<%= port %>}}"
19
- COZE_HARDWARE_DID="${COZE_HARDWARE_DID:-}"
20
- if [ -n "${EXPO_PORT:-}" ] && [ -n "${COZE_HARDWARE_DID}" ]; then
21
- WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-https://cozedaemon-${COZE_HARDWARE_DID}-${EXPO_PORT}.dev.coze.site}"
22
- else
23
- WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
24
- fi
14
+ EXPO_PORT="5000"
15
+ WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
25
16
  ASSUME_YES="1"
26
17
  EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$WEB_URL}"
27
18
  EXPO_PUBLIC_COZE_PROJECT_ID="${COZE_PROJECT_ID:-}"
@@ -31,7 +22,6 @@ export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL EXPO_PUBLIC_COZE_PRO
31
22
  # 运行时变量(为避免 set -u 的未绑定错误,预置为空)
32
23
  SERVER_PID=""
33
24
  EXPO_PID=""
34
- PNPM_BIN=""
35
25
 
36
26
  # ==================== 工具函数 ====================
37
27
  check_command() {
@@ -122,67 +112,22 @@ wait_port_connectable() {
122
112
  return 1
123
113
  }
124
114
 
125
- # coze-daemon 会在 runtime shell 退出时清理原进程组。
126
- # 通过 Node detached spawn 创建独立 session/进程组,并将 stdio 直接写入日志。
127
- spawn_detached() {
128
- local cwd="$1"
129
- local log_file="$2"
130
- shift 2
131
-
132
- node - "$cwd" "$log_file" "$@" <<'NODE'
133
- const fs = require('node:fs');
134
- const { spawn } = require('node:child_process');
135
-
136
- const [cwd, logFile, command, ...args] = process.argv.slice(2);
137
- if (!cwd || !logFile || !command) {
138
- throw new Error('spawn_detached 缺少 cwd、log_file 或 command');
139
- }
140
-
141
- const logFd = fs.openSync(logFile, 'a');
142
- try {
143
- const child = spawn(command, args, {
144
- cwd,
145
- detached: true,
146
- env: process.env,
147
- stdio: ['ignore', logFd, logFd],
148
- });
149
- child.unref();
150
- process.stdout.write(String(child.pid));
151
- } finally {
152
- fs.closeSync(logFd);
153
- }
154
- NODE
155
- }
156
-
157
- stop_detached() {
158
- local pid="${1:-}"
159
- if [ -z "$pid" ]; then
160
- return
161
- fi
162
-
163
- kill -TERM -- "-$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || true
164
- sleep 1
165
- kill -KILL -- "-$pid" 2>/dev/null || true
166
- }
167
-
168
115
  start_expo() {
169
116
  local offline="${1:-0}"
170
- local -a expo_env
171
- expo_env=(
172
- "EXPO_NO_DEPENDENCY_VALIDATION=1"
173
- "EXPO_PUBLIC_BACKEND_BASE_URL=$EXPO_PUBLIC_BACKEND_BASE_URL"
174
- "EXPO_PACKAGER_PROXY_URL=$EXPO_PACKAGER_PROXY_URL"
175
- "EXPO_PUBLIC_COZE_PROJECT_ID=$EXPO_PUBLIC_COZE_PROJECT_ID"
176
- )
117
+
118
+ pushd "$ROOT_DIR/client"
119
+
177
120
  if [ "$offline" = "1" ]; then
178
- expo_env+=("EXPO_OFFLINE=1")
121
+ ( EXPO_OFFLINE=1 EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
122
+ nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
123
+ else
124
+ ( EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
125
+ nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
179
126
  fi
127
+ EXPO_PID=$!
128
+ disown $EXPO_PID 2>/dev/null || true
180
129
 
181
- EXPO_PID="$(spawn_detached \
182
- "$ROOT_DIR/client" \
183
- "$LOG_CLIENT_FILE" \
184
- /usr/bin/env "${expo_env[@]}" \
185
- "$PNPM_BIN" exec expo start --clear --port "$EXPO_PORT")"
130
+ popd
186
131
  }
187
132
 
188
133
  detect_expo_fetch_failed() {
@@ -223,8 +168,6 @@ check_command "npm"
223
168
  check_command "pnpm"
224
169
  check_command "lsof"
225
170
  check_command "bash"
226
- check_command "node"
227
- PNPM_BIN="$(command -v pnpm)"
228
171
 
229
172
  # 端口占用预检查与处理
230
173
  ensure_port SERVER_PORT "$SERVER_PORT"
@@ -232,12 +175,9 @@ ensure_port EXPO_PORT "$EXPO_PORT"
232
175
 
233
176
  echo "==================== 启动 server 服务 ===================="
234
177
  echo "正在执行:pnpm run dev (server)"
235
- : > "$LOG_SERVER_FILE"
236
- export SERVER_PORT
237
- SERVER_PID="$(spawn_detached \
238
- "$ROOT_DIR/server" \
239
- /dev/null \
240
- "$PNPM_BIN" run dev)"
178
+ ( pushd "$ROOT_DIR/server" > /dev/null && SERVER_PORT="$SERVER_PORT" nohup pnpm run dev; popd > /dev/null ) &
179
+ SERVER_PID=$!
180
+ disown $SERVER_PID 2>/dev/null || true
241
181
  if [ -z "${SERVER_PID}" ]; then
242
182
  echo "无法获取 server 后台进程 PID"
243
183
  fi
@@ -245,12 +185,11 @@ echo "server 服务已启动,进程 ID:${SERVER_PID:-unknown}"
245
185
 
246
186
  echo "==================== 启动 Expo 项目 ===================="
247
187
  echo "开始启动 Expo 服务,端口 ${EXPO_PORT}"
248
- : > "$LOG_CLIENT_FILE"
249
188
  start_expo 0
250
189
  if detect_expo_fetch_failed 8; then
251
190
  echo "Expo 启动检测到网络错误:TypeError: fetch failed,启用离线模式重试"
252
- stop_detached "$EXPO_PID"
253
- : > "$LOG_CLIENT_FILE"
191
+ if [ -n "${EXPO_PID}" ]; then kill -9 "$EXPO_PID" 2>/dev/null || true; fi
192
+ : > "$ROOT_DIR/logs/client.log"
254
193
  start_expo 1
255
194
  fi
256
195
  # 输出以下环境变量,确保 Expo 项目能正确连接到 Server 服务
@@ -5,7 +5,7 @@ set -euo pipefail
5
5
  ROOT_DIR="$(pwd)"
6
6
 
7
7
  HOST="${HOST:-0.0.0.0}"
8
- PORT="${DEPLOY_RUN_PORT:-${PORT:-<%= port %>}}"
8
+ PORT="${PORT:-5000}"
9
9
 
10
10
  # ==================== 工具函数 ====================
11
11
  info() {
@@ -4,7 +4,7 @@ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
4
  SERVER_DIR="$ROOT_DIR/server"
5
5
  LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
6
6
  LOG_SERVER_FILE="$LOG_DIR/server.log"
7
- SERVER_PORT="${SERVER_PORT:-<%= serverPort %>}"
7
+ SERVER_PORT="${SERVER_PORT:-9091}"
8
8
 
9
9
  mkdir -p "$LOG_DIR"
10
10
 
@@ -32,9 +32,7 @@ config.resolver.blockList = [
32
32
  /.*node_modules\/\.pnpm\/.*_tmp_\d+.*/,
33
33
  ];
34
34
 
35
- const DEFAULT_BACKEND_PORT = '<%= serverPort %>';
36
- const BACKEND_PORT = process.env.SERVER_PORT || DEFAULT_BACKEND_PORT;
37
- const BACKEND_TARGET = `http://localhost:${BACKEND_PORT}`;
35
+ const BACKEND_TARGET = 'http://localhost:9091';
38
36
 
39
37
  const apiProxy = createProxyMiddleware({
40
38
  target: BACKEND_TARGET,
@@ -269,8 +269,8 @@ importers:
269
269
  specifier: ^2.8.5
270
270
  version: 2.8.6
271
271
  coze-coding-dev-sdk:
272
- specifier: ^0.7.25-beta.8
273
- version: 0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
272
+ specifier: ^0.7.24
273
+ version: 0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
274
274
  dayjs:
275
275
  specifier: ^1.11.20
276
276
  version: 1.11.20
@@ -2643,8 +2643,8 @@ packages:
2643
2643
  resolution: {integrity: sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==}
2644
2644
  engines: {node: '>=10'}
2645
2645
 
2646
- coze-coding-dev-sdk@0.7.25-beta.8:
2647
- resolution: {integrity: sha512-RSKlXCO0W/OPDjx9D9JICn2cGeOJw3iG+y0Pr1AhAf7YdAjjNbBZoG7qfg0Zg2SqgaVN2qSLQFmKPbhNq9ZWSg==}
2646
+ coze-coding-dev-sdk@0.7.24:
2647
+ resolution: {integrity: sha512-oL9Tg5PwxP6iMixonzzMO4aBjOKWcFUMVM+iz5dPyaqQkG84HP1y9DqK5DJVmtdfJuYdAW7pzOatDqLvgvZiXg==}
2648
2648
  engines: {node: '>=18.0.0'}
2649
2649
  hasBin: true
2650
2650
 
@@ -9088,7 +9088,7 @@ snapshots:
9088
9088
  path-type: 4.0.0
9089
9089
  yaml: 1.10.2
9090
9090
 
9091
- coze-coding-dev-sdk@0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9091
+ coze-coding-dev-sdk@0.7.24(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9092
9092
  dependencies:
9093
9093
  '@langchain/core': 1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6))
9094
9094
  '@langchain/openai': 1.2.3(@langchain/core@1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6)))(ws@8.19.0)
@@ -6,13 +6,13 @@
6
6
  "build": "node build.js",
7
7
  "dev": "bash ../.cozeproj/scripts/server_dev_run.sh",
8
8
  "preinstall": "npx only-allow pnpm",
9
- "start": "NODE_ENV=production PORT=${PORT:-<%= port %>} node dist/index.js",
9
+ "start": "NODE_ENV=production PORT=${PORT:-5000} node dist/index.js",
10
10
  "lint": "tsc --noEmit"
11
11
  },
12
12
  "dependencies": {
13
13
  "@supabase/supabase-js": "2.95.3",
14
14
  "cors": "^2.8.5",
15
- "coze-coding-dev-sdk": "^0.7.25-beta.8",
15
+ "coze-coding-dev-sdk": "^0.7.24",
16
16
  "dayjs": "^1.11.20",
17
17
  "dotenv": "^17.2.3",
18
18
  "drizzle-orm": "^0.45.1",
@@ -2,7 +2,7 @@ import express from "express";
2
2
  import cors from "cors";
3
3
 
4
4
  const app = express();
5
- const port = process.env.PORT || <%= serverPort %>;
5
+ const port = process.env.PORT || 9091;
6
6
 
7
7
  // Middleware
8
8
  app.use(cors());
@@ -6,7 +6,6 @@
6
6
 
7
7
 
8
8
 
9
-
10
9
  export const paramsSchema = {
11
10
  type: 'object',
12
11
  properties: {
@@ -19,18 +18,11 @@ export const paramsSchema = {
19
18
  },
20
19
  port: {
21
20
  type: 'number',
22
- default: 5000,
21
+ default: 8081,
23
22
  minimum: 1024,
24
23
  maximum: 65535,
25
24
  description: 'Metro bundler port',
26
25
  },
27
- serverPort: {
28
- type: 'number',
29
- default: 9091,
30
- minimum: 1024,
31
- maximum: 65535,
32
- description: 'Express backend server port',
33
- },
34
26
  },
35
27
  required: [],
36
28
  additionalProperties: false,
@@ -40,8 +32,7 @@ const config = {
40
32
  description: 'Expo template for React Native applications',
41
33
  paramsSchema,
42
34
  defaultParams: {
43
- port: 5000,
44
- serverPort: 9091,
35
+ port: 9090,
45
36
  appName: 'my-expo-app',
46
37
  },
47
38
  onBeforeRender: async context => {
@@ -6,9 +6,7 @@ project_type = "web"
6
6
  [dev]
7
7
  build = []
8
8
  run = [ "sh", "-c", "python -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
9
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
10
9
 
11
10
  [deploy]
12
11
  build = []
13
12
  run = [ "sh", "-c", "python -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
14
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
@@ -4,16 +4,11 @@ project_type = "web"
4
4
 
5
5
  [dev]
6
6
  build = ["bash", "./scripts/prepare.sh"]
7
- build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/prepare.ps1"]
8
7
  run = ["bash", "./scripts/dev.sh"]
9
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/dev.ps1"]
10
8
  validate = ["bash", "./scripts/validate.sh"]
11
- validate_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/validate.ps1"]
12
9
  deps = ["git"] # -> apt install git
13
10
 
14
11
  [deploy]
15
12
  build = ["bash","./scripts/build.sh"]
16
- build_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/build.ps1"]
17
13
  run = ["bash","./scripts/start.sh"]
18
- run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/start.ps1"]
19
14
  deps = ["git"] # -> apt install git
@@ -47,7 +47,7 @@
47
47
  "class-variance-authority": "^0.7.1",
48
48
  "clsx": "^2.1.1",
49
49
  "cmdk": "^1.1.1",
50
- "coze-coding-dev-sdk": "^0.7.25-beta.8",
50
+ "coze-coding-dev-sdk": "^0.7.16",
51
51
  "date-fns": "^4.1.0",
52
52
  "dotenv": "^17.2.3",
53
53
  "drizzle-kit": "^0.31.8",
@@ -108,8 +108,8 @@ importers:
108
108
  specifier: ^1.1.1
109
109
  version: 1.1.1(@types/react-dom@19.2.3(@types/react@19.2.10))(@types/react@19.2.10)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
110
110
  coze-coding-dev-sdk:
111
- specifier: ^0.7.25-beta.8
112
- version: 0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
111
+ specifier: ^0.7.16
112
+ version: 0.7.16(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0)
113
113
  date-fns:
114
114
  specifier: ^4.1.0
115
115
  version: 4.1.0
@@ -3363,8 +3363,8 @@ packages:
3363
3363
  typescript:
3364
3364
  optional: true
3365
3365
 
3366
- coze-coding-dev-sdk@0.7.25-beta.8:
3367
- resolution: {integrity: sha512-RSKlXCO0W/OPDjx9D9JICn2cGeOJw3iG+y0Pr1AhAf7YdAjjNbBZoG7qfg0Zg2SqgaVN2qSLQFmKPbhNq9ZWSg==}
3366
+ coze-coding-dev-sdk@0.7.16:
3367
+ resolution: {integrity: sha512-B7gRPBa+sfrZL8ur0+F/92SOgZgFaWD/fOnCN2DjthnHSdmCYhAJWCfqzG2oO2vwTiYCXkKUuTBZ3MJLMj886g==}
3368
3368
  engines: {node: '>=18.0.0'}
3369
3369
  hasBin: true
3370
3370
 
@@ -9627,7 +9627,7 @@ snapshots:
9627
9627
  optionalDependencies:
9628
9628
  typescript: 5.9.3
9629
9629
 
9630
- coze-coding-dev-sdk@0.7.25-beta.8(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9630
+ coze-coding-dev-sdk@0.7.16(openai@6.16.0(ws@8.19.0)(zod@4.3.6))(ws@8.19.0):
9631
9631
  dependencies:
9632
9632
  '@langchain/core': 1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6))
9633
9633
  '@langchain/openai': 1.2.3(@langchain/core@1.1.17(openai@6.16.0(ws@8.19.0)(zod@4.3.6)))(ws@8.19.0)