@coze-arch/cli 0.0.1-alpha.d85d9d → 0.0.1-alpha.db1c06

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 (53) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +13 -12
  2. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
  3. package/lib/__templates__/expo/client/metro.config.js +3 -0
  4. package/lib/__templates__/expo/client/package.json +35 -35
  5. package/lib/__templates__/expo/client/screens/demo/index.tsx +3 -3
  6. package/lib/__templates__/expo/package.json +1 -1
  7. package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +3 -2
  8. package/lib/__templates__/expo/pnpm-lock.yaml +340 -1736
  9. package/lib/__templates__/expo/server/package.json +9 -7
  10. package/lib/__templates__/expo/server/src/index.ts +1 -0
  11. package/lib/__templates__/expo/template.config.js +56 -0
  12. package/lib/__templates__/native-static/.coze +11 -0
  13. package/lib/__templates__/native-static/index.html +33 -0
  14. package/lib/__templates__/native-static/styles/main.css +136 -0
  15. package/lib/__templates__/native-static/template.config.js +22 -0
  16. package/lib/__templates__/nextjs/package.json +3 -1
  17. package/lib/__templates__/nextjs/pnpm-lock.yaml +119 -106
  18. package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
  19. package/lib/__templates__/nextjs/template.config.js +49 -14
  20. package/lib/__templates__/taro/.coze +1 -1
  21. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +5 -6
  22. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +6 -8
  23. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
  24. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
  25. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
  26. package/lib/__templates__/taro/README.md +81 -17
  27. package/lib/__templates__/taro/_gitignore +40 -0
  28. package/lib/__templates__/taro/_npmrc +18 -0
  29. package/lib/__templates__/taro/config/index.ts +4 -3
  30. package/lib/__templates__/taro/eslint.config.mjs +79 -0
  31. package/lib/__templates__/taro/package.json +32 -33
  32. package/lib/__templates__/taro/pnpm-lock.yaml +742 -677
  33. package/lib/__templates__/taro/server/package.json +10 -7
  34. package/lib/__templates__/taro/server/src/main.ts +14 -2
  35. package/lib/__templates__/taro/src/app.css +18 -18
  36. package/lib/__templates__/taro/src/app.tsx +9 -0
  37. package/lib/__templates__/taro/src/index.html +20 -1
  38. package/lib/__templates__/taro/src/pages/index/index.tsx +14 -11
  39. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +171 -0
  40. package/lib/__templates__/taro/src/{utils → presets}/h5-styles.ts +15 -4
  41. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  42. package/lib/__templates__/taro/src/presets/wx-debug.ts +23 -0
  43. package/lib/__templates__/templates.json +11 -0
  44. package/lib/__templates__/vite/package.json +5 -1
  45. package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
  46. package/lib/__templates__/vite/src/main.ts +17 -47
  47. package/lib/__templates__/vite/template.config.js +49 -14
  48. package/lib/__templates__/vite/vite.config.ts +1 -0
  49. package/lib/cli.js +62 -68
  50. package/package.json +2 -1
  51. package/lib/__templates__/taro/.eslintrc +0 -40
  52. package/lib/__templates__/taro/commitlint.config.mjs +0 -1
  53. package/lib/__templates__/taro/src/app.ts +0 -28
@@ -11,27 +11,30 @@
11
11
  "start:prod": "node dist/main"
12
12
  },
13
13
  "dependencies": {
14
+ "@aws-sdk/client-s3": "^3.958.0",
15
+ "@aws-sdk/lib-storage": "^3.958.0",
14
16
  "@nestjs/common": "^10.4.15",
15
17
  "@nestjs/core": "^10.4.15",
16
18
  "@nestjs/platform-express": "^10.4.15",
19
+ "@supabase/supabase-js": "2.95.3",
17
20
  "better-sqlite3": "^11.9.1",
18
- "@aws-sdk/client-s3": "^3.958.0",
19
- "@aws-sdk/lib-storage": "^3.958.0",
20
- "coze-coding-dev-sdk": "^0.7.3",
21
+ "coze-coding-dev-sdk": "^0.7.16",
22
+ "dotenv": "^17.2.3",
21
23
  "drizzle-kit": "^0.31.8",
22
24
  "drizzle-orm": "^0.45.1",
23
25
  "drizzle-zod": "^0.8.3",
26
+ "express": "5.2.1",
24
27
  "pg": "^8.16.3",
25
- "zod": "^4.3.5",
26
- "rxjs": "^7.8.1"
28
+ "rxjs": "^7.8.1",
29
+ "zod": "^4.3.5"
27
30
  },
28
31
  "devDependencies": {
29
32
  "@nestjs/cli": "^10.4.9",
30
33
  "@nestjs/schematics": "^10.2.3",
31
34
  "@types/better-sqlite3": "^7.6.13",
32
- "@types/express": "^5.0.0",
35
+ "@types/express": "5.0.6",
33
36
  "@types/node": "^22.10.2",
34
37
  "drizzle-kit": "^0.31.8",
35
38
  "typescript": "^5.7.2"
36
39
  }
37
- }
40
+ }
@@ -3,6 +3,18 @@ import { AppModule } from '@/app.module';
3
3
  import * as express from 'express';
4
4
  import { HttpStatusInterceptor } from '@/interceptors/http-status.interceptor';
5
5
 
6
+ function parsePort(): number {
7
+ const args = process.argv.slice(2);
8
+ const portIndex = args.indexOf('-p');
9
+ if (portIndex !== -1 && args[portIndex + 1]) {
10
+ const port = parseInt(args[portIndex + 1], 10);
11
+ if (!isNaN(port) && port > 0 && port < 65536) {
12
+ return port;
13
+ }
14
+ }
15
+ return <%= serverPort %>;
16
+ }
17
+
6
18
  async function bootstrap() {
7
19
  const app = await NestFactory.create(AppModule);
8
20
 
@@ -19,8 +31,8 @@ async function bootstrap() {
19
31
  // 1. 开启优雅关闭 Hooks (关键!)
20
32
  app.enableShutdownHooks();
21
33
 
22
- // 2. 增加错误处理,防止端口被占时直接崩溃,而是给出一个清晰的提示
23
- const port = <%= serverPort %>;
34
+ // 2. 解析端口
35
+ const port = parsePort();
24
36
  try {
25
37
  await app.listen(port);
26
38
  console.log(`Server running on http://localhost:${port}`);
@@ -2,51 +2,51 @@
2
2
 
3
3
  /*
4
4
  * H5 端 rem 适配:与小程序 rpx 缩放一致
5
- * 375px 屏幕:1rem = 16px,小程序 32rpx = 16px
5
+ * 375px 屏幕:1rem = 16px,小程序 32rpx = 16px
6
6
  */
7
7
  html {
8
- font-size: 4vw !important;
8
+ font-size: 4vw !important;
9
9
  }
10
10
 
11
11
  /* 小程序页面容器高度设置,确保垂直居中生效 */
12
12
  /* stylelint-disable-next-line selector-type-no-unknown */
13
13
  page {
14
- height: 100%;
14
+ height: 100%;
15
15
  }
16
16
 
17
17
  /* H5 端组件默认样式修复 */
18
18
  taro-view-core {
19
- display: block;
19
+ display: block;
20
20
  }
21
21
 
22
22
  taro-text-core {
23
- display: inline;
23
+ display: inline;
24
24
  }
25
25
 
26
26
  taro-input-core {
27
- display: block;
28
- width: 100%;
27
+ display: block;
28
+ width: 100%;
29
29
  }
30
30
 
31
31
  taro-input-core input {
32
- width: 100%;
33
- background: transparent;
34
- border: none;
35
- outline: none;
32
+ width: 100%;
33
+ background: transparent;
34
+ border: none;
35
+ outline: none;
36
36
  }
37
37
 
38
38
  /* 全局按钮样式重置 */
39
39
  taro-button-core,
40
40
  button {
41
- margin: 0 !important;
42
- padding: 0 !important;
43
- line-height: inherit;
44
- display: flex;
45
- align-items: center;
46
- justify-content: center;
41
+ margin: 0 !important;
42
+ padding: 0 !important;
43
+ line-height: inherit;
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
47
  }
48
48
 
49
49
  taro-button-core::after,
50
50
  button::after {
51
- border: none;
51
+ border: none;
52
52
  }
@@ -0,0 +1,9 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import '@/app.css';
3
+ import { Preset } from './presets';
4
+
5
+ const App = ({ children }: PropsWithChildren) => {
6
+ return <Preset>{children}</Preset>;
7
+ };
8
+
9
+ export default App;
@@ -14,7 +14,26 @@
14
14
  </head>
15
15
 
16
16
  <body>
17
- <div id="app"></div>
17
+ <div id="app">
18
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="lab(2.86037 0.455312 0.568903)"
19
+ stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="
20
+ position: fixed;
21
+ inset: 0;
22
+ margin: auto;
23
+ width: 24px;
24
+ height: 24px;
25
+ animation: __app-loading-spin 1s linear infinite;
26
+ ">
27
+ <path d="M21 12a9 9 0 1 1-6.219-8.56" />
28
+ </svg>
29
+ <style>
30
+ @keyframes __app-loading-spin {
31
+ to {
32
+ transform: rotate(360deg);
33
+ }
34
+ }
35
+ </style>
36
+ </div>
18
37
  </body>
19
38
 
20
39
  </html>
@@ -1,20 +1,23 @@
1
- import { View, Text, Image } from '@tarojs/components'
2
- import { useLoad } from '@tarojs/taro'
3
- import { Network } from '@/network'
4
- import './index.css'
1
+ import { View, Text, Image } from '@tarojs/components';
2
+ import { useLoad } from '@tarojs/taro';
3
+ import { Network } from '@/network';
4
+ import './index.css';
5
5
 
6
6
  /**
7
7
  * 默认首页,直接覆盖本页内容
8
8
  */
9
9
  const IndexPage = () => {
10
10
  useLoad(async () => {
11
- const res = await Network.request({ url: '/api/hello' })
12
- console.log(res.data)
13
- })
11
+ const res = await Network.request({ url: '/api/hello' });
12
+ console.log(res.data);
13
+ });
14
14
 
15
15
  return (
16
16
  <View className="w-full h-full flex flex-col justify-center items-center gap-1">
17
- <Image className="w-32 h-28" src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif" />
17
+ <Image
18
+ className="w-32 h-28"
19
+ src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
20
+ />
18
21
  <View className="self-stretch flex flex-col justify-start items-start gap-2">
19
22
  <Text className="self-stretch text-center justify-start text-base-accent-foreground text-base font-bold">
20
23
  应用开发中
@@ -24,7 +27,7 @@ const IndexPage = () => {
24
27
  </Text>
25
28
  </View>
26
29
  </View>
27
- )
28
- }
30
+ );
31
+ };
29
32
 
30
- export default IndexPage
33
+ export default IndexPage;
@@ -0,0 +1,171 @@
1
+ import { View, Text } from '@tarojs/components';
2
+ import Taro, { useDidShow, usePageScroll } from '@tarojs/taro';
3
+ import { useState, useEffect, PropsWithChildren, useCallback } from 'react';
4
+ import { ChevronLeft, House } from 'lucide-react-taro';
5
+
6
+ interface NavConfig {
7
+ navigationBarTitleText?: string;
8
+ navigationBarBackgroundColor?: string;
9
+ navigationBarTextStyle?: 'black' | 'white';
10
+ navigationStyle?: 'default' | 'custom';
11
+ transparentTitle?: 'none' | 'always' | 'auto';
12
+ }
13
+
14
+ enum LeftIcon {
15
+ Back = 'back',
16
+ Home = 'home',
17
+ None = 'none',
18
+ }
19
+
20
+ interface NavState {
21
+ visible: boolean;
22
+ title: string;
23
+ bgColor: string;
24
+ textStyle: 'black' | 'white';
25
+ navStyle: 'default' | 'custom';
26
+ transparent: 'none' | 'always' | 'auto';
27
+ leftIcon: LeftIcon;
28
+ }
29
+
30
+ const DEFAULT_NAV_STATE: NavState = {
31
+ visible: false,
32
+ title: '',
33
+ bgColor: '#ffffff',
34
+ textStyle: 'black',
35
+ navStyle: 'default',
36
+ transparent: 'none',
37
+ leftIcon: LeftIcon.None,
38
+ };
39
+
40
+ const getTabBarPages = (): Set<string> => {
41
+ const tabBar = Taro.getApp()?.config?.tabBar;
42
+ return new Set(
43
+ tabBar?.list?.map((item: { pagePath: string }) => item.pagePath) || [],
44
+ );
45
+ };
46
+
47
+ const computeLeftIcon = (
48
+ route: string,
49
+ tabBarPages: Set<string>,
50
+ historyLength: number,
51
+ ): LeftIcon => {
52
+ if (!route) return LeftIcon.None;
53
+
54
+ const isHomePage =
55
+ route === 'pages/index/index' || route === '/pages/index/index';
56
+ const isTabBarPage = tabBarPages.has(route);
57
+ const hasHistory = historyLength > 1;
58
+
59
+ if (isTabBarPage || isHomePage) return LeftIcon.None;
60
+ if (hasHistory) return LeftIcon.Back;
61
+ return LeftIcon.Home;
62
+ };
63
+
64
+ export const H5NavBar = ({ children }: PropsWithChildren) => {
65
+ const [navState, setNavState] = useState<NavState>(DEFAULT_NAV_STATE);
66
+ const [scrollOpacity, setScrollOpacity] = useState(0);
67
+
68
+ const updateNavState = useCallback(() => {
69
+ const pages = Taro.getCurrentPages();
70
+ const currentPage = pages[pages.length - 1];
71
+ const route = currentPage?.route || '';
72
+ const config: NavConfig = (currentPage as any)?.config || {};
73
+ const tabBarPages = getTabBarPages();
74
+
75
+ const isSinglePageApp = tabBarPages.size <= 1 && pages.length <= 1;
76
+
77
+ setNavState({
78
+ visible: !isSinglePageApp,
79
+ title: config.navigationBarTitleText || '',
80
+ bgColor: config.navigationBarBackgroundColor || '#ffffff',
81
+ textStyle: config.navigationBarTextStyle || 'black',
82
+ navStyle: config.navigationStyle || 'default',
83
+ transparent: config.transparentTitle || 'none',
84
+ leftIcon: isSinglePageApp
85
+ ? LeftIcon.None
86
+ : computeLeftIcon(route, tabBarPages, pages.length),
87
+ });
88
+ }, []);
89
+
90
+ useDidShow(() => {
91
+ updateNavState();
92
+ });
93
+
94
+ usePageScroll(({ scrollTop }) => {
95
+ if (navState.transparent === 'auto') {
96
+ setScrollOpacity(Math.min(scrollTop / 100, 1));
97
+ }
98
+ });
99
+
100
+ useEffect(() => {
101
+ if (TARO_ENV !== 'h5') return;
102
+
103
+ const titleEl = document.querySelector('title') || document.head;
104
+ const observer = new MutationObserver(() => updateNavState());
105
+ observer.observe(titleEl, {
106
+ subtree: true,
107
+ childList: true,
108
+ characterData: true,
109
+ });
110
+
111
+ return () => observer.disconnect();
112
+ }, [updateNavState]);
113
+
114
+ if (
115
+ TARO_ENV !== 'h5' ||
116
+ navState.navStyle === 'custom' ||
117
+ !navState.visible
118
+ ) {
119
+ return <>{children}</>;
120
+ }
121
+
122
+ const iconColor = navState.textStyle === 'white' ? '#fff' : '#333';
123
+ const textColorClass =
124
+ navState.textStyle === 'white' ? 'text-white' : 'text-gray-800';
125
+
126
+ const getBgStyle = () => {
127
+ if (navState.transparent === 'always') {
128
+ return { backgroundColor: 'transparent' };
129
+ }
130
+ if (navState.transparent === 'auto') {
131
+ return { backgroundColor: navState.bgColor, opacity: scrollOpacity };
132
+ }
133
+ return { backgroundColor: navState.bgColor };
134
+ };
135
+
136
+ const handleBack = () => Taro.navigateBack();
137
+ const handleGoHome = () => Taro.switchTab({ url: '/pages/index/index' });
138
+
139
+ return (
140
+ <View className="flex flex-col h-full">
141
+ <View
142
+ className={`fixed top-0 left-0 right-0 h-11 flex items-center justify-center z-1000 ${navState.transparent === 'none' ? 'border-b border-gray-200' : ''}`}
143
+ style={getBgStyle()}
144
+ >
145
+ {navState.leftIcon === LeftIcon.Back && (
146
+ <View
147
+ className="absolute left-2 top-1/2 -translate-y-1/2 p-1 flex items-center justify-center"
148
+ onClick={handleBack}
149
+ >
150
+ <ChevronLeft size={24} color={iconColor} />
151
+ </View>
152
+ )}
153
+ {navState.leftIcon === LeftIcon.Home && (
154
+ <View
155
+ className="absolute left-2 top-1/2 -translate-y-1/2 p-1 flex items-center justify-center"
156
+ onClick={handleGoHome}
157
+ >
158
+ <House size={22} color={iconColor} />
159
+ </View>
160
+ )}
161
+ <Text
162
+ className={`text-base font-medium max-w-3/5 truncate ${textColorClass}`}
163
+ >
164
+ {navState.title}
165
+ </Text>
166
+ </View>
167
+ <View className="h-11 shrink-0" />
168
+ <View className="pb-11 h-full">{children}</View>
169
+ </View>
170
+ );
171
+ };
@@ -3,9 +3,9 @@
3
3
  * 如无必要,请勿修改本文件
4
4
  */
5
5
  export function injectH5Styles() {
6
- if (TARO_ENV !== 'h5') return
6
+ if (TARO_ENV !== 'h5') return;
7
7
 
8
- const style = document.createElement('style')
8
+ const style = document.createElement('style');
9
9
  style.innerHTML = `
10
10
  /* H5 端隐藏 TabBar 空图标(只隐藏没有 src 的图标) */
11
11
  .weui-tabbar__icon:not([src]),
@@ -17,6 +17,17 @@ export function injectH5Styles() {
17
17
  .weui-tabbar__item:has(.weui-tabbar__icon[src='']) .weui-tabbar__label {
18
18
  margin-top: 0 !important;
19
19
  }
20
- `
21
- document.head.appendChild(style)
20
+
21
+ /* Vite 错误覆盖层无法选择文本的问题 */
22
+ vite-error-overlay {
23
+ /* stylelint-disable-next-line property-no-vendor-prefix */
24
+ -webkit-user-select: text !important;
25
+ }
26
+
27
+ vite-error-overlay::part(window) {
28
+ max-width: 90vw;
29
+ padding: 10px;
30
+ }
31
+ `;
32
+ document.head.appendChild(style);
22
33
  }
@@ -0,0 +1,18 @@
1
+ import { useLaunch } from '@tarojs/taro';
2
+ import { PropsWithChildren } from 'react';
3
+ import { H5NavBar } from './h5-navbar';
4
+ import { injectH5Styles } from './h5-styles';
5
+ import { enableWxDebugIfNeeded } from './wx-debug';
6
+
7
+ export const Preset = ({ children }: PropsWithChildren) => {
8
+ useLaunch(() => {
9
+ enableWxDebugIfNeeded();
10
+ injectH5Styles();
11
+ });
12
+
13
+ if (TARO_ENV === 'h5') {
14
+ return <H5NavBar>{children}</H5NavBar>;
15
+ }
16
+
17
+ return <>{children}</>;
18
+ };
@@ -0,0 +1,23 @@
1
+ import Taro from '@tarojs/taro'
2
+
3
+ /**
4
+ * 微信小程序调试工具
5
+ * 在开发版/体验版自动开启调试模式
6
+ */
7
+ export function enableWxDebugIfNeeded() {
8
+ // 仅在微信小程序环境执行
9
+ if (Taro.getEnv() === Taro.ENV_TYPE.WEAPP) {
10
+ try {
11
+ const accountInfo = Taro.getAccountInfoSync()
12
+ const envVersion = accountInfo.miniProgram.envVersion
13
+ console.log('[Debug] envVersion:', envVersion)
14
+
15
+ // 开发版/体验版自动开启调试
16
+ if (envVersion !== 'release') {
17
+ Taro.setEnableDebug({ enableDebug: true })
18
+ }
19
+ } catch (error) {
20
+ console.error('[Debug] 开启调试模式失败:', error)
21
+ }
22
+ }
23
+ }
@@ -26,6 +26,17 @@
26
26
  "additionalProperties": false
27
27
  }
28
28
  },
29
+ {
30
+ "name": "native-static",
31
+ "description": "Native Static(纯静态):`coze init ${COZE_WORKSPACE_PATH} --template native-static`\n- 适用:纯静态 HTML/CSS/JS 项目、静态网站\n- 使用 Python http.server 作为开发服务器\n- 不需要 Node.js 环境,适合简单静态内容",
32
+ "location": "./native-static",
33
+ "paramsSchema": {
34
+ "type": "object",
35
+ "properties": {},
36
+ "required": [],
37
+ "additionalProperties": false
38
+ }
39
+ },
29
40
  {
30
41
  "name": "nextjs",
31
42
  "description": "Next.js(复杂项目):`coze init ${COZE_WORKSPACE_PATH} --template nextjs`\n- 适用:全栈应用、复杂多页面等复杂项目\n- 使用默认nextjs项目规范\n - **目录规范**: 默认开启src目录(打开--src-dir选项):项目文件(如 app 目录、pages 目录、components 等)初始化到 src/ 目录下。\n - **项目理解加速**:初始可以依赖项目下 `package.json` 文件理解项目类型,如果没有或无法理解退化成阅读其他文件。\n - **UI设计与组件规范**:Next.js项目**必须默认**采用 shadcn/ui 风格和规范,`shadcn/ui`组件默认完整的预装在`src/components/ui/`目录下",
@@ -10,9 +10,13 @@
10
10
  "start": "bash ./scripts/start.sh",
11
11
  "ts-check": "tsc -p tsconfig.json"
12
12
  },
13
+ "dependencies": {
14
+ "@supabase/supabase-js": "2.95.3",
15
+ "dotenv": "^17.2.3"
16
+ },
13
17
  "devDependencies": {
14
18
  "autoprefixer": "^10.4.20",
15
- "coze-coding-dev-sdk": "^0.7.3",
19
+ "coze-coding-dev-sdk": "^0.7.16",
16
20
  "eslint": "^9",
17
21
  "only-allow": "^1.2.2",
18
22
  "postcss": "^8.4.49",