@coze-arch/cli 0.0.1-alpha.912cd5 → 0.0.1-alpha.a3fb1a
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.
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +21 -15
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +28 -14
- package/lib/__templates__/expo/package.json +2 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +82 -0
- package/lib/__templates__/nextjs/.coze +3 -3
- package/lib/__templates__/nextjs/package.json +9 -0
- package/lib/__templates__/nextjs/pnpm-lock.yaml +2545 -144
- package/lib/__templates__/templates.json +1 -1
- package/lib/__templates__/vite/.coze +3 -3
- package/lib/__templates__/vite/README.md +204 -26
- package/lib/__templates__/vite/template.config.js +1 -1
- package/lib/cli.js +24 -7
- package/package.json +3 -1
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
requires = ["nodejs-24"]
|
|
3
3
|
|
|
4
4
|
[dev]
|
|
5
|
-
run = ["
|
|
5
|
+
run = ["bash", "./scripts/dev.sh"]
|
|
6
6
|
deps = ["git"] # -> apt install git
|
|
7
7
|
|
|
8
8
|
[deploy]
|
|
9
|
-
build = ["
|
|
10
|
-
run = ["
|
|
9
|
+
build = ["bash","./scripts/build.sh"]
|
|
10
|
+
run = ["bash","./scripts/start.sh"]
|
|
11
11
|
deps = ["git"] # -> apt install git
|
|
@@ -1,61 +1,239 @@
|
|
|
1
1
|
# <%= appName %>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
这是一个基于 TypeScript + Vite + Tailwind CSS 的轻量级 Web 应用项目,由扣子编程 CLI 创建。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 快速开始
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### 启动开发服务器
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
coze dev
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
启动后,在浏览器中打开 [http://localhost:<%= port %>](http://localhost:<%= port %>) 查看应用。
|
|
14
|
+
|
|
15
|
+
开发服务器支持热更新(HMR),修改代码后页面会自动刷新。
|
|
16
|
+
|
|
17
|
+
### 构建生产版本
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
|
-
|
|
20
|
+
coze build
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
构建产物位于 `dist/` 目录,可直接部署到静态托管服务。
|
|
24
|
+
|
|
25
|
+
### 预览生产版本
|
|
20
26
|
|
|
21
27
|
```bash
|
|
22
|
-
coze
|
|
28
|
+
coze start
|
|
23
29
|
```
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
在本地启动一个静态服务器,预览生产构建的效果。
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
## 项目结构
|
|
28
34
|
|
|
29
|
-
```
|
|
30
|
-
|
|
35
|
+
```
|
|
36
|
+
├── index.html # HTML 入口文件
|
|
37
|
+
├── src/
|
|
38
|
+
│ ├── index.ts # 应用入口(初始化)
|
|
39
|
+
│ ├── main.ts # 主逻辑文件
|
|
40
|
+
│ └── index.css # 全局样式(包含 Tailwind 指令)
|
|
41
|
+
├── vite.config.ts # Vite 配置
|
|
42
|
+
├── tailwind.config.ts # Tailwind CSS 配置
|
|
43
|
+
└── tsconfig.json # TypeScript 配置
|
|
31
44
|
```
|
|
32
45
|
|
|
33
|
-
|
|
46
|
+
## 核心开发规范
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
### 1. 样式开发
|
|
49
|
+
|
|
50
|
+
**使用 Tailwind CSS**
|
|
51
|
+
|
|
52
|
+
本项目使用 Tailwind CSS 进行样式开发,支持亮色/暗色模式自动切换。
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// 使用 Tailwind 工具类
|
|
56
|
+
app.innerHTML = `
|
|
57
|
+
<div class="flex items-center justify-center min-h-screen bg-white dark:bg-black">
|
|
58
|
+
<h1 class="text-4xl font-bold text-black dark:text-white">
|
|
59
|
+
Hello World
|
|
60
|
+
</h1>
|
|
61
|
+
</div>
|
|
62
|
+
`;
|
|
37
63
|
```
|
|
38
64
|
|
|
39
|
-
|
|
65
|
+
**主题变量**
|
|
66
|
+
|
|
67
|
+
主题变量定义在 `src/index.css` 中,支持自动适配系统主题:
|
|
68
|
+
|
|
69
|
+
```css
|
|
70
|
+
:root {
|
|
71
|
+
--background: #ffffff;
|
|
72
|
+
--foreground: #171717;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@media (prefers-color-scheme: dark) {
|
|
76
|
+
:root {
|
|
77
|
+
--background: #0a0a0a;
|
|
78
|
+
--foreground: #ededed;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
40
82
|
|
|
41
|
-
|
|
83
|
+
**常用 Tailwind 类名**
|
|
84
|
+
|
|
85
|
+
- 布局:`flex`, `grid`, `container`, `mx-auto`
|
|
86
|
+
- 间距:`p-4`, `m-4`, `gap-4`, `space-x-4`
|
|
87
|
+
- 颜色:`bg-white`, `text-black`, `dark:bg-black`, `dark:text-white`
|
|
88
|
+
- 排版:`text-lg`, `font-bold`, `leading-8`, `tracking-tight`
|
|
89
|
+
- 响应式:`sm:`, `md:`, `lg:`, `xl:`
|
|
90
|
+
|
|
91
|
+
### 2. 依赖管理
|
|
92
|
+
|
|
93
|
+
**必须使用 pnpm 管理依赖**
|
|
42
94
|
|
|
43
95
|
```bash
|
|
44
|
-
|
|
96
|
+
# ✅ 安装依赖
|
|
97
|
+
pnpm install
|
|
98
|
+
|
|
99
|
+
# ✅ 添加新依赖
|
|
100
|
+
pnpm add package-name
|
|
101
|
+
|
|
102
|
+
# ✅ 添加开发依赖
|
|
103
|
+
pnpm add -D package-name
|
|
104
|
+
|
|
105
|
+
# ❌ 禁止使用 npm 或 yarn
|
|
106
|
+
# npm install # 错误!
|
|
107
|
+
# yarn add # 错误!
|
|
45
108
|
```
|
|
46
109
|
|
|
47
|
-
|
|
110
|
+
项目已配置 `preinstall` 脚本,使用其他包管理器会报错。
|
|
111
|
+
|
|
112
|
+
### 3. TypeScript 开发
|
|
113
|
+
|
|
114
|
+
**类型安全**
|
|
115
|
+
|
|
116
|
+
充分利用 TypeScript 的类型系统,确保代码质量:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// 定义接口
|
|
120
|
+
interface User {
|
|
121
|
+
id: number;
|
|
122
|
+
name: string;
|
|
123
|
+
email: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 使用类型
|
|
127
|
+
function createUser(data: User): void {
|
|
128
|
+
console.log(`Creating user: ${data.name}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// DOM 操作类型推断
|
|
132
|
+
const button = document.querySelector<HTMLButtonElement>('#my-button');
|
|
133
|
+
if (button) {
|
|
134
|
+
button.addEventListener('click', () => {
|
|
135
|
+
console.log('Button clicked');
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**避免 any 类型**
|
|
141
|
+
|
|
142
|
+
尽量避免使用 `any`,使用 `unknown` 或具体类型:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// ❌ 不推荐
|
|
146
|
+
function process(data: any) { }
|
|
147
|
+
|
|
148
|
+
// ✅ 推荐
|
|
149
|
+
function process(data: unknown) {
|
|
150
|
+
if (typeof data === 'string') {
|
|
151
|
+
console.log(data.toUpperCase());
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 常见开发场景
|
|
157
|
+
|
|
158
|
+
### 添加新页面
|
|
159
|
+
|
|
160
|
+
本项目是单页应用(SPA),如需多页面:
|
|
161
|
+
|
|
162
|
+
1. 在 `src/` 下创建新的 `.ts` 文件
|
|
163
|
+
2. 在 `vite.config.ts` 中配置多入口
|
|
164
|
+
3. 创建对应的 `.html` 文件
|
|
165
|
+
|
|
166
|
+
### DOM 操作
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// 获取元素
|
|
170
|
+
const app = document.getElementById('app');
|
|
171
|
+
const button = document.querySelector<HTMLButtonElement>('.my-button');
|
|
172
|
+
|
|
173
|
+
// 动态创建元素
|
|
174
|
+
const div = document.createElement('div');
|
|
175
|
+
div.className = 'flex items-center gap-4';
|
|
176
|
+
div.textContent = 'Hello World';
|
|
177
|
+
app?.appendChild(div);
|
|
178
|
+
|
|
179
|
+
// 事件监听
|
|
180
|
+
button?.addEventListener('click', (e) => {
|
|
181
|
+
console.log('Clicked', e);
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 数据获取
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Fetch API
|
|
189
|
+
async function fetchData() {
|
|
190
|
+
try {
|
|
191
|
+
const response = await fetch('https://api.example.com/data');
|
|
192
|
+
const data = await response.json();
|
|
193
|
+
return data;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error('Failed to fetch data:', error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 使用数据
|
|
200
|
+
fetchData().then(data => {
|
|
201
|
+
console.log(data);
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 环境变量
|
|
206
|
+
|
|
207
|
+
在 `.env` 文件中定义环境变量(需以 `VITE_` 开头):
|
|
48
208
|
|
|
49
209
|
```bash
|
|
50
|
-
|
|
210
|
+
VITE_API_URL=https://api.example.com
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
在代码中使用:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const apiUrl = import.meta.env.VITE_API_URL;
|
|
217
|
+
console.log(apiUrl); // https://api.example.com
|
|
51
218
|
```
|
|
52
219
|
|
|
53
|
-
##
|
|
220
|
+
## 技术栈
|
|
221
|
+
|
|
222
|
+
- **构建工具**: Vite 6.x
|
|
223
|
+
- **语言**: TypeScript 5.x
|
|
224
|
+
- **样式**: Tailwind CSS 3.x
|
|
225
|
+
- **包管理器**: pnpm 9+
|
|
226
|
+
|
|
227
|
+
## 参考文档
|
|
54
228
|
|
|
55
|
-
-
|
|
229
|
+
- [Vite 官方文档](https://cn.vitejs.dev/)
|
|
230
|
+
- [TypeScript 官方文档](https://www.typescriptlang.org/zh/docs/)
|
|
231
|
+
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
|
56
232
|
|
|
57
|
-
##
|
|
233
|
+
## 重要提示
|
|
58
234
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
235
|
+
1. **必须使用 pnpm** 作为包管理器
|
|
236
|
+
2. **使用 TypeScript** 进行类型安全开发,避免使用 `any`
|
|
237
|
+
3. **使用 Tailwind CSS** 进行样式开发,支持响应式和暗色模式
|
|
238
|
+
4. **环境变量必须以 `VITE_` 开头** 才能在客户端代码中访问
|
|
239
|
+
5. **开发时使用 `coze dev`**,支持热更新和快速刷新
|
package/lib/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ var jsYaml = require('js-yaml');
|
|
|
11
11
|
var perf_hooks = require('perf_hooks');
|
|
12
12
|
var addFormats = require('ajv-formats');
|
|
13
13
|
var Ajv = require('ajv');
|
|
14
|
+
var minimist = require('minimist');
|
|
14
15
|
var changeCase = require('change-case');
|
|
15
16
|
var ejs = require('ejs');
|
|
16
17
|
|
|
@@ -882,6 +883,8 @@ const getTemplatePath = async (
|
|
|
882
883
|
* 从 Commander 解析透传参数
|
|
883
884
|
* 将 kebab-case 的 CLI 参数转换为 camelCase
|
|
884
885
|
*
|
|
886
|
+
* 使用 minimist 解析 process.argv,自动处理类型转换
|
|
887
|
+
*
|
|
885
888
|
* @param command - Commander 命令实例
|
|
886
889
|
* @param knownOptions - 已知的选项集合(不需要透传的选项)
|
|
887
890
|
* @returns 参数对象
|
|
@@ -890,20 +893,34 @@ const parsePassThroughParams = (
|
|
|
890
893
|
command,
|
|
891
894
|
knownOptions = new Set(),
|
|
892
895
|
) => {
|
|
893
|
-
|
|
896
|
+
// 使用 minimist 解析所有参数
|
|
897
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- slice(2) to skip node and script path
|
|
898
|
+
const parsed = minimist(process.argv.slice(2));
|
|
894
899
|
|
|
895
|
-
|
|
896
|
-
|
|
900
|
+
// 过滤掉已知选项和位置参数(_)
|
|
901
|
+
const filtered = Object.entries(parsed).reduce(
|
|
897
902
|
(params, [key, value]) => {
|
|
898
|
-
|
|
903
|
+
// 跳过 minimist 的位置参数数组
|
|
904
|
+
if (key === '_') {
|
|
905
|
+
return params;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// 跳过已知选项(支持原始格式和 camelCase 格式)
|
|
909
|
+
if (knownOptions.has(key) || knownOptions.has(changeCase.camelCase(key))) {
|
|
899
910
|
return params;
|
|
900
911
|
}
|
|
901
912
|
|
|
913
|
+
// 将 kebab-case 转换为 camelCase
|
|
902
914
|
const camelKey = changeCase.camelCase(key);
|
|
903
|
-
|
|
915
|
+
// eslint-disable-next-line security/detect-object-injection -- camelKey is sanitized by camelCase
|
|
916
|
+
params[camelKey] = value;
|
|
917
|
+
|
|
918
|
+
return params;
|
|
904
919
|
},
|
|
905
|
-
|
|
920
|
+
{},
|
|
906
921
|
);
|
|
922
|
+
|
|
923
|
+
return filtered;
|
|
907
924
|
};
|
|
908
925
|
|
|
909
926
|
/**
|
|
@@ -1581,7 +1598,7 @@ const registerCommand = program => {
|
|
|
1581
1598
|
});
|
|
1582
1599
|
};
|
|
1583
1600
|
|
|
1584
|
-
var version = "0.0.1-alpha.
|
|
1601
|
+
var version = "0.0.1-alpha.a3fb1a";
|
|
1585
1602
|
var packageJson = {
|
|
1586
1603
|
version: version};
|
|
1587
1604
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze-arch/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.a3fb1a",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "coze coding devtools cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"commander": "~12.1.0",
|
|
39
39
|
"ejs": "^3.1.10",
|
|
40
40
|
"js-yaml": "^4.1.0",
|
|
41
|
+
"minimist": "^1.2.5",
|
|
41
42
|
"shelljs": "^0.10.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"@types/ejs": "^3.1.5",
|
|
52
53
|
"@types/iarna__toml": "^2.0.5",
|
|
53
54
|
"@types/js-yaml": "^4.0.9",
|
|
55
|
+
"@types/minimist": "^1.2.5",
|
|
54
56
|
"@types/node": "^24",
|
|
55
57
|
"@types/shelljs": "^0.10.0",
|
|
56
58
|
"@vitest/coverage-v8": "~4.0.16",
|