@coze-arch/cli 0.0.1-alpha.cd0f36 → 0.0.1-alpha.cf9a3b

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 (32) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  2. package/lib/__templates__/expo/README.md +0 -1
  3. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +3 -4
  4. package/lib/__templates__/expo/client/metro.config.js +3 -0
  5. package/lib/__templates__/expo/pnpm-lock.yaml +101 -45
  6. package/lib/__templates__/expo/server/package.json +9 -7
  7. package/lib/__templates__/nextjs/package.json +3 -1
  8. package/lib/__templates__/nextjs/pnpm-lock.yaml +119 -106
  9. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -2
  10. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -3
  11. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
  12. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
  13. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
  14. package/lib/__templates__/taro/README.md +79 -17
  15. package/lib/__templates__/taro/config/index.ts +1 -1
  16. package/lib/__templates__/taro/eslint.config.mjs +25 -3
  17. package/lib/__templates__/taro/package.json +6 -4
  18. package/lib/__templates__/taro/pnpm-lock.yaml +378 -114
  19. package/lib/__templates__/taro/server/package.json +3 -1
  20. package/lib/__templates__/taro/server/src/main.ts +14 -2
  21. package/lib/__templates__/taro/src/app.css +18 -18
  22. package/lib/__templates__/taro/src/app.tsx +9 -0
  23. package/lib/__templates__/taro/src/index.html +20 -1
  24. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +171 -0
  25. package/lib/__templates__/taro/src/{utils → presets}/h5-styles.ts +15 -4
  26. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  27. package/lib/__templates__/vite/package.json +5 -1
  28. package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
  29. package/lib/cli.js +5 -59
  30. package/package.json +1 -1
  31. package/lib/__templates__/taro/src/app.ts +0 -14
  32. /package/lib/__templates__/taro/src/{utils → presets}/wx-debug.ts +0 -0
@@ -1 +1,24 @@
1
- pnpm build:weapp
1
+ # build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
2
+ export OUTPUT_ROOT=dist
3
+ PID_FILE="/tmp/coze-build_weapp.pid"
4
+
5
+ # 杀掉上次的构建进程组
6
+ if [ -f "$PID_FILE" ]; then
7
+ OLD_PID=$(cat "$PID_FILE")
8
+ if kill -0 "$OLD_PID" 2>/dev/null; then
9
+ echo "正在终止上次的构建进程组 (PID: $OLD_PID)..."
10
+ # 关键:kill 负数 PID = 杀掉整个进程组
11
+ kill -9 -"$OLD_PID" 2>/dev/null
12
+ sleep 1
13
+ fi
14
+ rm -f "$PID_FILE"
15
+ fi
16
+
17
+ # 用 setsid 创建新的进程组,方便下次整组杀掉
18
+ setsid pnpm build:weapp &
19
+ echo $! > "$PID_FILE"
20
+
21
+ echo "构建已启动 (PID: $(cat $PID_FILE))"
22
+
23
+ wait $!
24
+ rm -f "$PID_FILE"
@@ -10,7 +10,7 @@
10
10
  - **样式**: TailwindCSS 4.1.18
11
11
  - **Tailwind 适配层**: weapp-tailwindcss 4.9.2
12
12
  - **状态管理**: Zustand 5.0.9
13
- - **图标库**: lucide-react 0.511.0
13
+ - **图标库**: lucide-react-taro latest
14
14
  - **工程化**: Vite 4.2.0
15
15
  - **包管理**: pnpm
16
16
  - **运行时**: Node.js >= 18
@@ -28,14 +28,16 @@
28
28
  │ ├── dev.ts # 开发环境配置
29
29
  │ └── prod.ts # 生产环境配置
30
30
  ├── server/ # NestJS 后端服务
31
- │ └── src/
31
+ │ └── src/
32
32
  │ ├── main.ts # 服务入口
33
33
  │ ├── app.module.ts # 根模块
34
34
  │ ├── app.controller.ts # 应用控制器
35
35
  │ └── app.service.ts # 应用服务
36
36
  ├── src/ # 前端源码
37
37
  │ ├── pages/ # 页面组件
38
+ │ ├── presets/ # 框架预置逻辑(无需读取,如无必要不改动)
38
39
  │ ├── utils/ # 工具函数
40
+ │ ├── network.ts # 封装好的网络请求工具
39
41
  │ ├── app.ts # 应用入口
40
42
  │ ├── app.config.ts # 应用配置
41
43
  │ └── app.css # 全局样式
@@ -237,8 +239,8 @@ Network 是对 Taro.request、Taro.uploadFile、Taro.downloadFile 的封装,
237
239
  import { Network } from '@/network'
238
240
 
239
241
  // GET 请求
240
- const data = await Network.request({
241
- url: '/api/hello'
242
+ const data = await Network.request({
243
+ url: '/api/hello'
242
244
  })
243
245
 
244
246
  // POST 请求
@@ -267,8 +269,8 @@ await Network.downloadFile({
267
269
  import Taro from '@tarojs/taro'
268
270
 
269
271
  // ❌ 会导致自动域名拼接无法生效,除非是特殊指定域名
270
- const data = await Network.request({
271
- url: 'http://localhost/api/hello'
272
+ const data = await Network.request({
273
+ url: 'http://localhost/api/hello'
272
274
  })
273
275
 
274
276
  // ❌ 不要直接使用 Taro.request
@@ -344,23 +346,29 @@ const router = useRouter()
344
346
  const { id } = router.params
345
347
  ```
346
348
 
347
- ### 图标使用 (lucide-react)
349
+ ### 图标使用 (lucide-react-taro)
350
+
351
+ **IMPORTANT: 禁止使用 lucide-react,必须使用 lucide-react-taro 替代。**
348
352
 
349
- 项目集成了 [lucide-react](https://lucide.dev/) 图标库,提供丰富的 SVG 图标:
353
+ lucide-react-taro Lucide 图标库的 Taro 适配版本,专为小程序环境优化,API 与 lucide-react 一致:
350
354
 
351
355
  ```tsx
352
356
  import { View } from '@tarojs/components'
353
- import { Home, Settings, User, Search, Heart, Star } from 'lucide-react'
357
+ import { House, Settings, User, Search, Camera, Zap } from 'lucide-react-taro'
354
358
 
355
359
  const IconDemo = () => {
356
360
  return (
357
361
  <View className="flex gap-4">
358
- <Home size={24} color="#333" />
359
- <Settings size={24} className="text-blue-500" />
360
- <User size={20} strokeWidth={1.5} />
361
- <Search size={24} />
362
- <Heart size={24} fill="red" color="red" />
363
- <Star size={24} className="text-yellow-500" />
362
+ {/* 基本用法 */}
363
+ <House />
364
+ {/* 自定义尺寸和颜色 */}
365
+ <Settings size={32} color="#1890ff" />
366
+ {/* 自定义描边宽度 */}
367
+ <User size={24} strokeWidth={1.5} />
368
+ {/* 绝对描边宽度(描边不随 size 缩放) */}
369
+ <Camera size={48} strokeWidth={2} absoluteStrokeWidth />
370
+ {/* 组合使用 */}
371
+ <Zap size={32} color="#ff6b00" strokeWidth={1.5} className="my-icon" />
364
372
  </View>
365
373
  )
366
374
  }
@@ -368,12 +376,66 @@ const IconDemo = () => {
368
376
 
369
377
  常用属性:
370
378
  - `size` - 图标大小(默认 24)
371
- - `color` - 图标颜色
379
+ - `color` - 图标颜色(默认 currentColor,小程序中建议显式设置)
372
380
  - `strokeWidth` - 线条粗细(默认 2)
373
- - `className` - 支持 Tailwind 类名
381
+ - `absoluteStrokeWidth` - 绝对描边宽度,启用后描边不随 size 缩放
382
+ - `className` / `style` - 自定义样式
374
383
 
375
384
  更多图标请访问:https://lucide.dev/icons
376
385
 
386
+ ### TabBar 图标生成 (CLI 工具)
387
+
388
+ **IMPORTANT: 微信小程序的 TabBar 不支持 base64 或 SVG 图片,必须使用本地 PNG 文件。**
389
+
390
+ lucide-react-taro 提供了 CLI 工具来生成 TabBar 所需的 PNG 图标:
391
+
392
+ ```bash
393
+ # 生成带选中状态的图标
394
+ npx taro-lucide-tabbar House Settings User -c "#999999" -a "#1890ff"
395
+
396
+ # 指定输出目录和尺寸
397
+ npx taro-lucide-tabbar House Settings User -c "#999999" -a "#1890ff" -o ./src/assets/tabbar -s 81
398
+ ```
399
+
400
+ CLI 参数:
401
+ - `--color, -c` (默认 #000000): 图标颜色
402
+ - `--active-color, -a`: 选中状态颜色
403
+ - `--size, -s` (默认 81): 图标尺寸
404
+ - `--output, -o` (默认 ./tabbar-icons): 输出目录
405
+ - `--stroke-width` (默认 2): 描边宽度
406
+
407
+ 在 `app.config.ts` 中使用生成的图标:
408
+
409
+ ```typescript
410
+ export default defineAppConfig({
411
+ tabBar: {
412
+ color: '#999999',
413
+ selectedColor: '#1890ff',
414
+ backgroundColor: '#ffffff',
415
+ borderStyle: 'black',
416
+ list: [
417
+ {
418
+ pagePath: 'pages/index/index',
419
+ text: '首页',
420
+ iconPath: './assets/tabbar/house.png',
421
+ selectedIconPath: './assets/tabbar/house-active.png',
422
+ },
423
+ {
424
+ pagePath: 'pages/settings/index',
425
+ text: '设置',
426
+ iconPath: './assets/tabbar/settings.png',
427
+ selectedIconPath: './assets/tabbar/settings-active.png',
428
+ },
429
+ {
430
+ pagePath: 'pages/user/index',
431
+ text: '用户',
432
+ iconPath: './assets/tabbar/user.png',
433
+ selectedIconPath: './assets/tabbar/user-active.png',
434
+ },
435
+ ],
436
+ },
437
+ })
438
+
377
439
  ### Tailwind CSS 样式开发
378
440
 
379
441
  IMPORTANT:必须使用 tailwindcss 实现样式,只有在必要情况下才能 fallback 到 css / less
@@ -16,7 +16,7 @@ import pkg from '../package.json';
16
16
  // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
17
17
  export default defineConfig<'vite'>(async (merge, _env) => {
18
18
  const isWeChatApp = process.env.TARO_ENV === 'weapp';
19
- const outputRoot = isWeChatApp ? 'dist' : 'dist-web';
19
+ const outputRoot = process.env.OUTPUT_ROOT || (isWeChatApp ? 'dist-weapp' : 'dist-web')
20
20
 
21
21
  const baseConfig: UserConfigExport<'vite'> = {
22
22
  projectName: '<%= appName %>',
@@ -30,23 +30,45 @@ export default [
30
30
  message:
31
31
  '请勿在 src 目录下直接使用 process.env\n如需获取 URL 请求前缀,请使用已经注入全局的 PROJECT_DOMAIN()',
32
32
  },
33
+ {
34
+ selector:
35
+ ":matches(ExportNamedDeclaration, ExportDefaultDeclaration) :matches([id.name='Network'], [declaration.id.name='Network'])",
36
+ message:
37
+ "禁止自行定义 Network,项目已提供 src/network.ts,请直接使用: import { Network } from '@/network'",
38
+ },
33
39
  ],
34
40
  'no-restricted-properties': [
35
41
  'error',
36
42
  {
37
43
  object: 'Taro',
38
44
  property: 'request',
39
- message: '请使用 Network.request 替代 Taro.request',
45
+ message:
46
+ "请使用 Network.request 替代 Taro.request,导入方式: import { Network } from '@/network'",
40
47
  },
41
48
  {
42
49
  object: 'Taro',
43
50
  property: 'uploadFile',
44
- message: '请使用 Network.uploadFile 替代 Taro.uploadFile',
51
+ message:
52
+ "请使用 Network.uploadFile 替代 Taro.uploadFile,导入方式: import { Network } from '@/network'",
45
53
  },
46
54
  {
47
55
  object: 'Taro',
48
56
  property: 'downloadFile',
49
- message: '请使用 Network.downloadFile 替代 Taro.downloadFile',
57
+ message:
58
+ "请使用 Network.downloadFile 替代 Taro.downloadFile,导入方式: import { Network } from '@/network'",
59
+ },
60
+ ],
61
+ },
62
+ },
63
+ {
64
+ files: ['src/pages/index/index.tsx'],
65
+ rules: {
66
+ 'no-restricted-syntax': [
67
+ 'error',
68
+ {
69
+ selector: 'JSXText[value=/应用开发中/]',
70
+ message:
71
+ '检测到首页 (src/pages/index/index) 仍为默认占位页面,这会导致用户无法进入新增页面,请根据用户需求开发实际的首页功能和界面。如果已经开发了新的首页,也需要删除旧首页,并更新 src/app.config.ts 文件',
50
72
  },
51
73
  ],
52
74
  },
@@ -4,22 +4,24 @@
4
4
  "private": true,
5
5
  "description": "Coze Mini Program Application",
6
6
  "scripts": {
7
- "build": "pnpm exec concurrently -n lint,tsc,web,weapp,server -c red,blue,green,yellow,magenta \"pnpm lint:build\" \"pnpm tsc\" \"pnpm build:web\" \"pnpm build:weapp\" \"pnpm build:server\"",
7
+ "build": "pnpm exec concurrently --kill-others-on-fail --kill-signal SIGKILL -n lint,tsc,web,weapp,server -c red,blue,green,yellow,magenta \"pnpm lint:build\" \"pnpm tsc\" \"pnpm build:web\" \"pnpm build:weapp\" \"pnpm build:server\"",
8
8
  "build:server": "pnpm --filter server build",
9
9
  "build:weapp": "taro build --type weapp",
10
10
  "build:web": "taro build --type h5",
11
- "dev": "pnpm exec concurrently -n web,server -c blue,green \"pnpm dev:web\" \"pnpm dev:server\"",
11
+ "dev": "pnpm exec concurrently --kill-others --kill-signal SIGKILL -n web,server -c blue,green \"pnpm dev:web\" \"pnpm dev:server\"",
12
12
  "dev:server": "pnpm --filter server dev",
13
13
  "dev:weapp": "taro build --type weapp --watch",
14
14
  "dev:web": "taro build --type h5 --watch",
15
15
  "preinstall": "npx only-allow pnpm",
16
16
  "postinstall": "weapp-tw patch",
17
+ "kill:all": "pkill -9 -f 'concurrently' 2>/dev/null || true; pkill -9 -f 'nest start' 2>/dev/null || true; pkill -9 -f 'taro build' 2>/dev/null || true; pkill -9 -f 'node.*dev' 2>/dev/null || true; echo 'All dev processes cleaned'",
17
18
  "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
18
19
  "lint:build": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --max-warnings=0",
19
20
  "lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
20
21
  "new": "taro new",
21
22
  "preview:weapp": "taro build --type weapp --preview",
22
- "tsc": "npx tsc --noEmit --skipLibCheck"
23
+ "tsc": "npx tsc --noEmit --skipLibCheck",
24
+ "validate": "pnpm exec concurrently --kill-others-on-fail --kill-signal SIGKILL -n lint,tsc -c red,blue \"pnpm lint:build\" \"pnpm tsc\""
23
25
  },
24
26
  "lint-staged": {
25
27
  "src/**/*.{js,jsx,ts,tsx}": [
@@ -43,7 +45,7 @@
43
45
  "@tarojs/shared": "4.1.9",
44
46
  "@tarojs/taro": "4.1.9",
45
47
  "drizzle-kit": "^0.31.8",
46
- "lucide-react": "^0.511.0",
48
+ "lucide-react-taro": "^1.1.1",
47
49
  "react": "^18.0.0",
48
50
  "react-dom": "^18.0.0",
49
51
  "zustand": "^5.0.9"