@coze-arch/cli 0.0.1-alpha.77c1b0 → 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/client/scripts/install-missing-deps.js +36 -12
- package/lib/__templates__/expo/metro.config.js +15 -15
- package/lib/__templates__/expo/package.json +12 -2
- package/lib/__templates__/expo/pnpm-lock.yaml +131 -4
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/.coze +3 -3
- package/lib/__templates__/nextjs/README.md +341 -19
- package/lib/__templates__/nextjs/components.json +21 -0
- package/lib/__templates__/nextjs/package.json +57 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +8953 -1509
- package/lib/__templates__/nextjs/scripts/dev.sh +2 -1
- package/lib/__templates__/nextjs/server.mjs +50 -0
- package/lib/__templates__/nextjs/src/app/globals.css +99 -8
- package/lib/__templates__/nextjs/src/app/layout.tsx +4 -0
- package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
- package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
- package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
- package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
- package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
- package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
- package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
- package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
- package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
- package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
- package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
- package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
- package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
- package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
- package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
- package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
- package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
- package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
- package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
- package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
- package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
- package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
- package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
- package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
- package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
- package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
- package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
- package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
- package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
- package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +56 -0
- package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
- package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
- package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +726 -0
- package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
- package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
- package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
- package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
- package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
- package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
- package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
- package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
- package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
- package/lib/__templates__/nextjs/template.config.js +1 -1
- package/lib/__templates__/templates.json +1 -39
- package/lib/__templates__/vite/.coze +3 -3
- package/lib/__templates__/vite/README.md +204 -26
- package/lib/__templates__/vite/template.config.js +2 -2
- package/lib/cli.js +42 -8
- package/package.json +5 -2
- package/lib/__templates__/react-rsbuild/.coze +0 -11
- package/lib/__templates__/react-rsbuild/.vscode/settings.json +0 -121
- package/lib/__templates__/react-rsbuild/README.md +0 -61
- package/lib/__templates__/react-rsbuild/_gitignore +0 -97
- package/lib/__templates__/react-rsbuild/_npmrc +0 -22
- package/lib/__templates__/react-rsbuild/package.json +0 -31
- package/lib/__templates__/react-rsbuild/pnpm-lock.yaml +0 -997
- package/lib/__templates__/react-rsbuild/rsbuild.config.ts +0 -13
- package/lib/__templates__/react-rsbuild/scripts/build.sh +0 -14
- package/lib/__templates__/react-rsbuild/scripts/dev.sh +0 -51
- package/lib/__templates__/react-rsbuild/scripts/start.sh +0 -15
- package/lib/__templates__/react-rsbuild/src/App.tsx +0 -60
- package/lib/__templates__/react-rsbuild/src/index.css +0 -21
- package/lib/__templates__/react-rsbuild/src/index.html +0 -12
- package/lib/__templates__/react-rsbuild/src/index.tsx +0 -16
- package/lib/__templates__/react-rsbuild/tailwind.config.js +0 -9
- package/lib/__templates__/react-rsbuild/template.config.js +0 -54
- package/lib/__templates__/react-rsbuild/tsconfig.json +0 -17
- package/lib/__templates__/rsbuild/.coze +0 -11
- package/lib/__templates__/rsbuild/.vscode/settings.json +0 -7
- package/lib/__templates__/rsbuild/README.md +0 -61
- package/lib/__templates__/rsbuild/_gitignore +0 -97
- package/lib/__templates__/rsbuild/_npmrc +0 -22
- package/lib/__templates__/rsbuild/package.json +0 -24
- package/lib/__templates__/rsbuild/pnpm-lock.yaml +0 -888
- package/lib/__templates__/rsbuild/rsbuild.config.ts +0 -12
- package/lib/__templates__/rsbuild/scripts/build.sh +0 -14
- package/lib/__templates__/rsbuild/scripts/dev.sh +0 -51
- package/lib/__templates__/rsbuild/scripts/start.sh +0 -15
- package/lib/__templates__/rsbuild/src/index.css +0 -21
- package/lib/__templates__/rsbuild/src/index.html +0 -12
- package/lib/__templates__/rsbuild/src/index.ts +0 -5
- package/lib/__templates__/rsbuild/src/main.ts +0 -65
- package/lib/__templates__/rsbuild/tailwind.config.js +0 -9
- package/lib/__templates__/rsbuild/template.config.js +0 -56
- package/lib/__templates__/rsbuild/tsconfig.json +0 -16
|
@@ -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`**,支持热更新和快速刷新
|
|
@@ -19,7 +19,7 @@ export const paramsSchema = {
|
|
|
19
19
|
},
|
|
20
20
|
port: {
|
|
21
21
|
type: 'number',
|
|
22
|
-
default:
|
|
22
|
+
default: 6000,
|
|
23
23
|
minimum: 1024,
|
|
24
24
|
maximum: 65535,
|
|
25
25
|
description: 'Development server port',
|
|
@@ -33,7 +33,7 @@ const config = {
|
|
|
33
33
|
paramsSchema,
|
|
34
34
|
|
|
35
35
|
defaultParams: {
|
|
36
|
-
port:
|
|
36
|
+
port: 5000,
|
|
37
37
|
appName: 'app',
|
|
38
38
|
},
|
|
39
39
|
|
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
|
/**
|
|
@@ -1171,6 +1188,7 @@ const processTemplateFiles = async (
|
|
|
1171
1188
|
|
|
1172
1189
|
/**
|
|
1173
1190
|
* 检查输出目录是否为空
|
|
1191
|
+
* 注意:.git 目录会被忽略,允许在已初始化 git 的目录中创建项目
|
|
1174
1192
|
*
|
|
1175
1193
|
* @param outputPath - 输出目录路径
|
|
1176
1194
|
* @returns 是否为空
|
|
@@ -1180,7 +1198,9 @@ const isOutputDirEmpty = async (
|
|
|
1180
1198
|
) => {
|
|
1181
1199
|
try {
|
|
1182
1200
|
const entries = await fs$1.readdir(outputPath);
|
|
1183
|
-
|
|
1201
|
+
// 过滤掉 .git 目录,允许在已初始化 git 的目录中创建项目
|
|
1202
|
+
const filteredEntries = entries.filter(entry => entry !== '.git');
|
|
1203
|
+
return filteredEntries.length === 0;
|
|
1184
1204
|
} catch (e) {
|
|
1185
1205
|
// 目录不存在,视为空
|
|
1186
1206
|
return true;
|
|
@@ -1364,8 +1384,18 @@ const runPnpmInstall = (projectPath) => {
|
|
|
1364
1384
|
|
|
1365
1385
|
/**
|
|
1366
1386
|
* 初始化 git 仓库并创建初始提交
|
|
1387
|
+
* 如果目录中已存在 .git,则跳过初始化
|
|
1367
1388
|
*/
|
|
1368
1389
|
const runGitInit = (projectPath) => {
|
|
1390
|
+
// 检查是否已存在 .git 目录
|
|
1391
|
+
const gitDir = path.join(projectPath, '.git');
|
|
1392
|
+
if (fs.existsSync(gitDir)) {
|
|
1393
|
+
logger.info(
|
|
1394
|
+
'\n💡 Git repository already exists, skipping git initialization',
|
|
1395
|
+
);
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1369
1399
|
const runGitCommand = (command) => {
|
|
1370
1400
|
logger.info(`Executing: ${command}`);
|
|
1371
1401
|
|
|
@@ -1568,6 +1598,10 @@ const registerCommand = program => {
|
|
|
1568
1598
|
});
|
|
1569
1599
|
};
|
|
1570
1600
|
|
|
1601
|
+
var version = "0.0.1-alpha.a3fb1a";
|
|
1602
|
+
var packageJson = {
|
|
1603
|
+
version: version};
|
|
1604
|
+
|
|
1571
1605
|
const commands = [
|
|
1572
1606
|
registerCommand,
|
|
1573
1607
|
registerCommand$1,
|
|
@@ -1582,7 +1616,7 @@ const main = () => {
|
|
|
1582
1616
|
.description(
|
|
1583
1617
|
'Coze Coding CLI - Project template engine for frontend stacks',
|
|
1584
1618
|
)
|
|
1585
|
-
.version(
|
|
1619
|
+
.version(packageJson.version);
|
|
1586
1620
|
|
|
1587
1621
|
commands.forEach(initCmd => initCmd(program));
|
|
1588
1622
|
|
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",
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"build": "tsx scripts/build.ts",
|
|
22
22
|
"generate-templates": "tsx scripts/generate-templates-config.ts",
|
|
23
23
|
"lint": "eslint ./ --cache",
|
|
24
|
+
"postpublish": "bash scripts/sync-npmmirror.sh",
|
|
24
25
|
"test": "vitest --run --passWithNoTests",
|
|
25
26
|
"test:all": "bash scripts/test-coverage.sh",
|
|
26
27
|
"test:cov": "vitest --run --passWithNoTests --coverage",
|
|
27
|
-
"test:e2e": "
|
|
28
|
+
"test:e2e": "bash scripts/e2e.sh",
|
|
28
29
|
"test:perf": "vitest bench --run --config vitest.perf.config.ts",
|
|
29
30
|
"test:perf:compare": "bash scripts/compare-perf.sh",
|
|
30
31
|
"test:perf:save": "bash scripts/run-perf-with-output.sh"
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"commander": "~12.1.0",
|
|
38
39
|
"ejs": "^3.1.10",
|
|
39
40
|
"js-yaml": "^4.1.0",
|
|
41
|
+
"minimist": "^1.2.5",
|
|
40
42
|
"shelljs": "^0.10.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
"@types/ejs": "^3.1.5",
|
|
51
53
|
"@types/iarna__toml": "^2.0.5",
|
|
52
54
|
"@types/js-yaml": "^4.0.9",
|
|
55
|
+
"@types/minimist": "^1.2.5",
|
|
53
56
|
"@types/node": "^24",
|
|
54
57
|
"@types/shelljs": "^0.10.0",
|
|
55
58
|
"@vitest/coverage-v8": "~4.0.16",
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"[css]": {
|
|
3
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
4
|
-
},
|
|
5
|
-
"[dotenv]": {
|
|
6
|
-
"editor.defaultFormatter": "foxundermoon.shell-format"
|
|
7
|
-
},
|
|
8
|
-
"[html]": {
|
|
9
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
10
|
-
},
|
|
11
|
-
"[ignore]": {
|
|
12
|
-
"editor.defaultFormatter": "foxundermoon.shell-format"
|
|
13
|
-
},
|
|
14
|
-
"[javascript]": {
|
|
15
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
16
|
-
},
|
|
17
|
-
"[javascriptreact]": {
|
|
18
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
19
|
-
},
|
|
20
|
-
"[json]": {
|
|
21
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
22
|
-
},
|
|
23
|
-
"[jsonc]": {
|
|
24
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
25
|
-
},
|
|
26
|
-
"[less]": {
|
|
27
|
-
"editor.defaultFormatter": "stylelint.vscode-stylelint"
|
|
28
|
-
},
|
|
29
|
-
"[scss]": {
|
|
30
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
31
|
-
},
|
|
32
|
-
"[shellscript]": {
|
|
33
|
-
"editor.defaultFormatter": "foxundermoon.shell-format"
|
|
34
|
-
},
|
|
35
|
-
"[sql]": {
|
|
36
|
-
"editor.defaultFormatter": "adpyke.vscode-sql-formatter"
|
|
37
|
-
},
|
|
38
|
-
"[svg]": {
|
|
39
|
-
"editor.defaultFormatter": "jock.svg"
|
|
40
|
-
},
|
|
41
|
-
"[typescript]": {
|
|
42
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
43
|
-
},
|
|
44
|
-
"[typescriptreact]": {
|
|
45
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
46
|
-
},
|
|
47
|
-
"[xml]": {
|
|
48
|
-
"editor.defaultFormatter": "mblode.pretty-formatter"
|
|
49
|
-
},
|
|
50
|
-
"[yaml]": {
|
|
51
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
52
|
-
},
|
|
53
|
-
"cSpell.diagnosticLevel": "Warning",
|
|
54
|
-
"css.validate": false,
|
|
55
|
-
"editor.codeActionsOnSave": {
|
|
56
|
-
"source.fixAll": "never",
|
|
57
|
-
"source.fixAll.eslint": "explicit",
|
|
58
|
-
"source.organizeImports": "never",
|
|
59
|
-
"source.removeUnused": "never",
|
|
60
|
-
"source.removeUnused.ts": "never",
|
|
61
|
-
"source.removeUnusedImports": "never",
|
|
62
|
-
"source.sort.json": "never"
|
|
63
|
-
// "source.sortImports": "always"
|
|
64
|
-
},
|
|
65
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
66
|
-
"editor.formatOnPaste": false,
|
|
67
|
-
"editor.formatOnSave": true,
|
|
68
|
-
"editor.formatOnType": false,
|
|
69
|
-
"editor.insertSpaces": true,
|
|
70
|
-
"editor.minimap.enabled": true,
|
|
71
|
-
//
|
|
72
|
-
"editor.rulers": [80, 120],
|
|
73
|
-
"editor.semanticHighlighting.enabled": false,
|
|
74
|
-
"editor.tabSize": 2,
|
|
75
|
-
"emmet.triggerExpansionOnTab": true,
|
|
76
|
-
"files.associations": {
|
|
77
|
-
".babelrc": "json",
|
|
78
|
-
".code-workspace": "jsonc",
|
|
79
|
-
".eslintrc": "jsonc",
|
|
80
|
-
".eslintrc*.json": "jsonc",
|
|
81
|
-
".htmlhintrc": "jsonc",
|
|
82
|
-
".stylelintrc": "javascript",
|
|
83
|
-
"*.json": "jsonc",
|
|
84
|
-
"*.log": "plaintext",
|
|
85
|
-
"*.map": "plaintext",
|
|
86
|
-
"**/coverage/**/*.*": "plaintext",
|
|
87
|
-
"**/pnpm-lock.yaml": "plaintext",
|
|
88
|
-
"htmlhintrc": "jsonc",
|
|
89
|
-
"package.json": "json",
|
|
90
|
-
"README": "markdown",
|
|
91
|
-
"stylelintrc": "jsonc",
|
|
92
|
-
".coze": "toml"
|
|
93
|
-
},
|
|
94
|
-
"files.defaultLanguage": "plaintext",
|
|
95
|
-
"files.eol": "\n",
|
|
96
|
-
"files.exclude": {
|
|
97
|
-
"**/.DS_Store": true,
|
|
98
|
-
"**/.git": true,
|
|
99
|
-
"**/.hg": true,
|
|
100
|
-
"**/.svn": true,
|
|
101
|
-
// "**/.lintcache": true,
|
|
102
|
-
"**/.swc": true,
|
|
103
|
-
"**/CVS": true,
|
|
104
|
-
"**/Thumbs.db": true
|
|
105
|
-
},
|
|
106
|
-
"files.insertFinalNewline": true,
|
|
107
|
-
"files.trimTrailingWhitespace": true,
|
|
108
|
-
"files.watcherExclude": {
|
|
109
|
-
"**/.git/objects/**": true,
|
|
110
|
-
"**/.git/subtree-cache/**": true,
|
|
111
|
-
"**/node_modules/*/**": true
|
|
112
|
-
},
|
|
113
|
-
"git.openRepositoryInParentFolders": "always",
|
|
114
|
-
"search.exclude": {
|
|
115
|
-
"**/dist": true,
|
|
116
|
-
"**/node_modules": true
|
|
117
|
-
},
|
|
118
|
-
// "editor.formatOnSaveMode": "modificationsIfAvailable",
|
|
119
|
-
"search.followSymlinks": false,
|
|
120
|
-
"search.useIgnoreFiles": true
|
|
121
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# <%= appName %>
|
|
2
|
-
|
|
3
|
-
React + TypeScript application built with Rsbuild.
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
Install dependencies:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Start development server:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm run dev
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Or use coze-coding CLI:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
coze-coding dev
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Build
|
|
26
|
-
|
|
27
|
-
Build for production:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm run build
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Or:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
coze-coding build
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Preview
|
|
40
|
-
|
|
41
|
-
Preview production build:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm run preview
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Or:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
coze-coding start
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Configuration
|
|
54
|
-
|
|
55
|
-
- Dev Server Port: <%= port %>
|
|
56
|
-
|
|
57
|
-
## Tech Stack
|
|
58
|
-
|
|
59
|
-
- React 18
|
|
60
|
-
- TypeScript
|
|
61
|
-
- Rsbuild
|