@coze-arch/cli 0.0.1-alpha.bcc7d9 → 0.0.1-alpha.bd55ba
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/dev_run.sh +15 -14
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +9 -8
- package/lib/__templates__/expo/README.md +2 -2
- package/lib/__templates__/expo/client/eslint.config.mjs +17 -1
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +36 -35
- package/lib/__templates__/expo/client/screens/demo/index.tsx +3 -3
- package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/package.json +1 -1
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +338 -1735
- package/lib/__templates__/expo/server/package.json +9 -7
- package/lib/__templates__/expo/server/src/index.ts +1 -0
- package/lib/__templates__/expo/template.config.js +56 -0
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/package.json +3 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +1051 -934
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -60
- package/lib/__templates__/nextjs/template.config.js +49 -14
- package/lib/__templates__/taro/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +751 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +223 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +80 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +107 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23100 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +52 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +75 -0
- package/lib/__templates__/vite/package.json +5 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +146 -1659
- package/lib/__templates__/vite/src/main.ts +17 -47
- package/lib/__templates__/vite/template.config.js +49 -14
- package/lib/__templates__/vite/vite.config.ts +1 -0
- package/lib/__templates__/vite-vue/.coze +12 -0
- package/lib/__templates__/vite-vue/README.md +342 -0
- package/lib/__templates__/vite-vue/_gitignore +66 -0
- package/lib/__templates__/vite-vue/_npmrc +23 -0
- package/lib/__templates__/vite-vue/eslint.config.mjs +9 -0
- package/lib/__templates__/vite-vue/index.html +13 -0
- package/lib/__templates__/vite-vue/package.json +37 -0
- package/lib/__templates__/vite-vue/pnpm-lock.yaml +3132 -0
- package/lib/__templates__/vite-vue/postcss.config.mjs +6 -0
- package/lib/__templates__/vite-vue/scripts/build.sh +14 -0
- package/lib/__templates__/vite-vue/scripts/dev.sh +32 -0
- package/lib/__templates__/vite-vue/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite-vue/scripts/start.sh +15 -0
- package/lib/__templates__/vite-vue/src/App.vue +38 -0
- package/lib/__templates__/vite-vue/src/index.css +29 -0
- package/lib/__templates__/vite-vue/src/main.ts +6 -0
- package/lib/__templates__/vite-vue/src/vite-env.d.ts +8 -0
- package/lib/__templates__/vite-vue/tailwind.config.js +9 -0
- package/lib/__templates__/vite-vue/template.config.js +127 -0
- package/lib/__templates__/vite-vue/tsconfig.json +17 -0
- package/lib/__templates__/vite-vue/vite.config.ts +28 -0
- package/lib/cli.js +373 -82
- package/package.json +2 -1
- package/lib/__templates__/expo/patches/expo@54.0.32.patch +0 -28
|
@@ -7,56 +7,26 @@ export function initApp(): void {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
app.innerHTML = `
|
|
10
|
-
<div class="flex
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<!-- 头部:Logo 和 产品名称 -->
|
|
14
|
-
<div class="flex items-center gap-3">
|
|
10
|
+
<div class="flex h-full items-center justify-center bg-background text-foreground transition-colors duration-300 dark:bg-background dark:text-foreground overflow-hidden min-h-screen">
|
|
11
|
+
<main class="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center">
|
|
12
|
+
<div class="flex flex-col items-center justify-between gap-4">
|
|
15
13
|
<img
|
|
16
|
-
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/
|
|
14
|
+
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
|
|
17
15
|
alt="扣子编程 Logo"
|
|
18
|
-
width=
|
|
19
|
-
height=
|
|
20
|
-
style="width:
|
|
16
|
+
width={156}
|
|
17
|
+
height={130}
|
|
18
|
+
style="width: 156px; height: 130px; object-fit: contain;"
|
|
21
19
|
/>
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
</
|
|
32
|
-
<p class="max-w-2xl text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
|
33
|
-
当前是空白入口文件,项目正在开发中,请稍候...
|
|
34
|
-
<br />
|
|
35
|
-
开发完成后界面将自动更新。如未自动更新成功,可以手动点击右上角刷新或重启按钮查看效果。
|
|
36
|
-
</p>
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<!-- 底部按钮区 -->
|
|
40
|
-
<div class="flex w-full flex-col gap-4 text-base font-medium sm:w-auto sm:flex-row">
|
|
41
|
-
<!-- 按钮 1:前往首页 -->
|
|
42
|
-
<a
|
|
43
|
-
class="flex h-12 w-full min-w-[160px] items-center justify-center gap-2 rounded-full bg-black px-8 text-white transition-colors hover:bg-zinc-800 dark:bg-white dark:text-black dark:hover:bg-zinc-200 md:w-auto"
|
|
44
|
-
href="https://code.coze.cn/"
|
|
45
|
-
target="_blank"
|
|
46
|
-
rel="noopener noreferrer"
|
|
47
|
-
>
|
|
48
|
-
前往首页
|
|
49
|
-
</a>
|
|
50
|
-
|
|
51
|
-
<!-- 按钮 2:查看文档 -->
|
|
52
|
-
<a
|
|
53
|
-
class="flex h-12 w-full min-w-[160px] items-center justify-center rounded-full border border-solid border-black/[.08] px-8 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-auto"
|
|
54
|
-
href="https://docs.coze.cn/"
|
|
55
|
-
target="_blank"
|
|
56
|
-
rel="noopener noreferrer"
|
|
57
|
-
>
|
|
58
|
-
查看文档
|
|
59
|
-
</a>
|
|
20
|
+
<div>
|
|
21
|
+
<div class="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center">
|
|
22
|
+
<h1 class="max-w-xl text-base font-semibold leading-tight tracking-tight text-foreground dark:text-foreground">
|
|
23
|
+
应用开发中
|
|
24
|
+
</h1>
|
|
25
|
+
<p class="max-w-2xl text-sm-14 leading-8 text-muted-foreground dark:text-muted-foreground">
|
|
26
|
+
请稍后,页面即将呈现
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
60
30
|
</div>
|
|
61
31
|
</main>
|
|
62
32
|
</div>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
import { resolve } from 'path';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { resolve, join, basename } from 'path';
|
|
4
|
+
import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
@@ -59,32 +60,66 @@ const config = {
|
|
|
59
60
|
return context;
|
|
60
61
|
},
|
|
61
62
|
|
|
62
|
-
onAfterRender: async (
|
|
63
|
+
onAfterRender: async (_context, outputPath) => {
|
|
63
64
|
console.log(`\nProject created at: ${outputPath}`);
|
|
64
65
|
console.log('\nConfiguration:');
|
|
65
66
|
console.log(' - Framework: vite');
|
|
66
67
|
console.log(' - TypeScript: enabled');
|
|
67
68
|
console.log(' - App Router: enabled');
|
|
68
|
-
console.log(` - Port: ${
|
|
69
|
+
console.log(` - Port: ${_context.port}`);
|
|
70
|
+
},
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
onComplete: async (_context, outputPath) => {
|
|
73
|
+
// Skip pnpm update in test environment to avoid monorepo workspace issues
|
|
71
74
|
if (process.env.NODE_ENV === 'test') {
|
|
72
75
|
console.log('⊘ Skipping dependency update in test environment');
|
|
73
76
|
return;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
const cmd =
|
|
77
|
-
|
|
79
|
+
const cmd = 'pnpm';
|
|
80
|
+
const args = ['update', 'coze-coding-dev-sdk@^0.7.0'];
|
|
81
|
+
console.log(
|
|
82
|
+
`\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
|
|
83
|
+
);
|
|
84
|
+
|
|
78
85
|
try {
|
|
79
86
|
const projectRoot = resolve(outputPath);
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
|
|
88
|
+
// Determine log directory
|
|
89
|
+
const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
|
|
90
|
+
mkdirSync(logDir, { recursive: true });
|
|
91
|
+
|
|
92
|
+
// Use project name in log file to avoid conflicts
|
|
93
|
+
const projectName = basename(projectRoot);
|
|
94
|
+
const logFile = join(logDir, `${projectName}-init.log`);
|
|
95
|
+
|
|
96
|
+
// Write log header
|
|
97
|
+
const timestamp = new Date().toISOString();
|
|
98
|
+
appendFileSync(
|
|
99
|
+
logFile,
|
|
100
|
+
`\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Open log file for appending
|
|
104
|
+
const logFd = openSync(logFile, 'a');
|
|
105
|
+
|
|
106
|
+
// Spawn in detached mode
|
|
107
|
+
const child = spawn(cmd, args, {
|
|
108
|
+
cwd: projectRoot,
|
|
109
|
+
detached: true,
|
|
110
|
+
stdio: ['ignore', logFd, logFd],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
child.unref();
|
|
114
|
+
closeSync(logFd);
|
|
115
|
+
|
|
116
|
+
console.log(
|
|
117
|
+
'✓ coze-coding-dev-sdk update triggered (running in background)',
|
|
118
|
+
);
|
|
119
|
+
console.log(` Log file: ${logFile}`);
|
|
85
120
|
} catch (error) {
|
|
86
|
-
console.error('✗ Failed to
|
|
87
|
-
|
|
121
|
+
console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
|
|
122
|
+
console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
|
|
88
123
|
}
|
|
89
124
|
},
|
|
90
125
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
requires = ["nodejs-24"]
|
|
3
|
+
|
|
4
|
+
[dev]
|
|
5
|
+
build = ["bash", "./scripts/prepare.sh"]
|
|
6
|
+
run = ["bash", "./scripts/dev.sh"]
|
|
7
|
+
deps = ["git"] # -> apt install git
|
|
8
|
+
|
|
9
|
+
[deploy]
|
|
10
|
+
build = ["bash","./scripts/build.sh"]
|
|
11
|
+
run = ["bash","./scripts/start.sh"]
|
|
12
|
+
deps = ["git"] # -> apt install git
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# <%= appName %>
|
|
2
|
+
|
|
3
|
+
这是一个基于 Vue 3 + TypeScript + Vite + Tailwind CSS 的现代化 Web 应用项目,由扣子编程 CLI 创建。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
### 启动开发服务器
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
coze dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
启动后,在浏览器中打开 [http://localhost:<%= port %>](http://localhost:<%= port %>) 查看应用。
|
|
14
|
+
|
|
15
|
+
开发服务器支持热更新(HMR),修改代码后页面会自动刷新。
|
|
16
|
+
|
|
17
|
+
### 构建生产版本
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
coze build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
构建产物位于 `dist/` 目录,可直接部署到静态托管服务。
|
|
24
|
+
|
|
25
|
+
### 预览生产版本
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
coze start
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
在本地启动一个静态服务器,预览生产构建的效果。
|
|
32
|
+
|
|
33
|
+
## 项目结构
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
├── index.html # HTML 入口文件
|
|
37
|
+
├── src/
|
|
38
|
+
│ ├── main.ts # Vue 应用入口(初始化)
|
|
39
|
+
│ ├── App.vue # 根 Vue 组件
|
|
40
|
+
│ ├── vite-env.d.ts # Vite 类型声明
|
|
41
|
+
│ └── index.css # 全局样式(包含 Tailwind 指令)
|
|
42
|
+
├── vite.config.ts # Vite 配置(含 Vue 插件)
|
|
43
|
+
├── tailwind.config.ts # Tailwind CSS 配置
|
|
44
|
+
└── tsconfig.json # TypeScript 配置
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 核心开发规范
|
|
48
|
+
|
|
49
|
+
### 1. 样式开发
|
|
50
|
+
|
|
51
|
+
**使用 Tailwind CSS**
|
|
52
|
+
|
|
53
|
+
本项目使用 Tailwind CSS 进行样式开发,支持亮色/暗色模式自动切换。
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
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
|
+
</template>
|
|
63
|
+
```
|
|
64
|
+
|
|
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
|
+
```
|
|
82
|
+
|
|
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 管理依赖**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
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 # 错误!
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
项目已配置 `preinstall` 脚本,使用其他包管理器会报错。
|
|
111
|
+
|
|
112
|
+
### 3. TypeScript 开发
|
|
113
|
+
|
|
114
|
+
**类型安全**
|
|
115
|
+
|
|
116
|
+
充分利用 TypeScript 的类型系统,确保代码质量:
|
|
117
|
+
|
|
118
|
+
```vue
|
|
119
|
+
<script setup lang="ts">
|
|
120
|
+
import { ref } from 'vue';
|
|
121
|
+
|
|
122
|
+
// 定义接口
|
|
123
|
+
interface User {
|
|
124
|
+
id: number;
|
|
125
|
+
name: string;
|
|
126
|
+
email: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 使用响应式数据和类型
|
|
130
|
+
const user = ref<User>({
|
|
131
|
+
id: 1,
|
|
132
|
+
name: 'John Doe',
|
|
133
|
+
email: 'john@example.com'
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// 使用类型化的函数
|
|
137
|
+
const createUser = (data: User): void => {
|
|
138
|
+
console.log(`Creating user: ${data.name}`);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// 事件处理
|
|
142
|
+
const handleClick = (): void => {
|
|
143
|
+
console.log('Button clicked');
|
|
144
|
+
};
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<template>
|
|
148
|
+
<div>
|
|
149
|
+
<p>{{ user.name }}</p>
|
|
150
|
+
<button @click="handleClick">Click me</button>
|
|
151
|
+
</div>
|
|
152
|
+
</template>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**避免 any 类型**
|
|
156
|
+
|
|
157
|
+
尽量避免使用 `any`,使用 `unknown` 或具体类型:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// ❌ 不推荐
|
|
161
|
+
function process(data: any) { }
|
|
162
|
+
|
|
163
|
+
// ✅ 推荐
|
|
164
|
+
function process(data: unknown) {
|
|
165
|
+
if (typeof data === 'string') {
|
|
166
|
+
console.log(data.toUpperCase());
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 常见开发场景
|
|
172
|
+
|
|
173
|
+
### 创建新组件
|
|
174
|
+
|
|
175
|
+
在 `src/` 下创建新的 `.vue` 文件:
|
|
176
|
+
|
|
177
|
+
```vue
|
|
178
|
+
<!-- src/components/HelloWorld.vue -->
|
|
179
|
+
<script setup lang="ts">
|
|
180
|
+
import { ref } from 'vue';
|
|
181
|
+
|
|
182
|
+
interface Props {
|
|
183
|
+
msg: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const props = defineProps<Props>();
|
|
187
|
+
const count = ref(0);
|
|
188
|
+
|
|
189
|
+
const increment = (): void => {
|
|
190
|
+
count.value++;
|
|
191
|
+
};
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
<template>
|
|
195
|
+
<div class="flex flex-col items-center gap-4">
|
|
196
|
+
<h1 class="text-2xl font-bold">{{ msg }}</h1>
|
|
197
|
+
<p class="text-lg">Count: {{ count }}</p>
|
|
198
|
+
<button
|
|
199
|
+
@click="increment"
|
|
200
|
+
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
201
|
+
>
|
|
202
|
+
Increment
|
|
203
|
+
</button>
|
|
204
|
+
</div>
|
|
205
|
+
</template>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
在 `App.vue` 中使用:
|
|
209
|
+
|
|
210
|
+
```vue
|
|
211
|
+
<script setup lang="ts">
|
|
212
|
+
import HelloWorld from './components/HelloWorld.vue';
|
|
213
|
+
</script>
|
|
214
|
+
|
|
215
|
+
<template>
|
|
216
|
+
<HelloWorld msg="Hello Vue 3!" />
|
|
217
|
+
</template>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 组合式 API(Composition API)
|
|
221
|
+
|
|
222
|
+
使用 Vue 3 的 Composition API 管理组件逻辑:
|
|
223
|
+
|
|
224
|
+
```vue
|
|
225
|
+
<script setup lang="ts">
|
|
226
|
+
import { ref, computed, onMounted } from 'vue';
|
|
227
|
+
|
|
228
|
+
// 响应式状态
|
|
229
|
+
const count = ref(0);
|
|
230
|
+
const message = ref('Hello');
|
|
231
|
+
|
|
232
|
+
// 计算属性
|
|
233
|
+
const doubleCount = computed(() => count.value * 2);
|
|
234
|
+
|
|
235
|
+
// 方法
|
|
236
|
+
const increment = (): void => {
|
|
237
|
+
count.value++;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// 生命周期钩子
|
|
241
|
+
onMounted(() => {
|
|
242
|
+
console.log('Component mounted');
|
|
243
|
+
});
|
|
244
|
+
</script>
|
|
245
|
+
|
|
246
|
+
<template>
|
|
247
|
+
<div>
|
|
248
|
+
<p>{{ message }}</p>
|
|
249
|
+
<p>Count: {{ count }}, Double: {{ doubleCount }}</p>
|
|
250
|
+
<button @click="increment">Increment</button>
|
|
251
|
+
</div>
|
|
252
|
+
</template>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 数据获取
|
|
256
|
+
|
|
257
|
+
使用 Vue 的响应式系统配合异步数据获取:
|
|
258
|
+
|
|
259
|
+
```vue
|
|
260
|
+
<script setup lang="ts">
|
|
261
|
+
import { ref, onMounted } from 'vue';
|
|
262
|
+
|
|
263
|
+
interface ApiData {
|
|
264
|
+
id: number;
|
|
265
|
+
title: string;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const data = ref<ApiData | null>(null);
|
|
269
|
+
const loading = ref(false);
|
|
270
|
+
const error = ref<string | null>(null);
|
|
271
|
+
|
|
272
|
+
const fetchData = async (): Promise<void> => {
|
|
273
|
+
loading.value = true;
|
|
274
|
+
error.value = null;
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
const response = await fetch('https://api.example.com/data');
|
|
278
|
+
data.value = await response.json();
|
|
279
|
+
} catch (err) {
|
|
280
|
+
error.value = 'Failed to fetch data';
|
|
281
|
+
console.error('Failed to fetch data:', err);
|
|
282
|
+
} finally {
|
|
283
|
+
loading.value = false;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
onMounted(() => {
|
|
288
|
+
fetchData();
|
|
289
|
+
});
|
|
290
|
+
</script>
|
|
291
|
+
|
|
292
|
+
<template>
|
|
293
|
+
<div>
|
|
294
|
+
<div v-if="loading">Loading...</div>
|
|
295
|
+
<div v-else-if="error" class="text-red-500">{{ error }}</div>
|
|
296
|
+
<div v-else-if="data">
|
|
297
|
+
<h2>{{ data.title }}</h2>
|
|
298
|
+
<p>ID: {{ data.id }}</p>
|
|
299
|
+
</div>
|
|
300
|
+
</div>
|
|
301
|
+
</template>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### 环境变量
|
|
305
|
+
|
|
306
|
+
在 `.env` 文件中定义环境变量(需以 `VITE_` 开头):
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
VITE_API_URL=https://api.example.com
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
在代码中使用:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
const apiUrl = import.meta.env.VITE_API_URL;
|
|
316
|
+
console.log(apiUrl); // https://api.example.com
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## 技术栈
|
|
320
|
+
|
|
321
|
+
- **框架**: Vue 3.x (Composition API)
|
|
322
|
+
- **构建工具**: Vite 6.x
|
|
323
|
+
- **语言**: TypeScript 5.x
|
|
324
|
+
- **样式**: Tailwind CSS 3.x
|
|
325
|
+
- **包管理器**: pnpm 9+
|
|
326
|
+
|
|
327
|
+
## 参考文档
|
|
328
|
+
|
|
329
|
+
- [Vue 3 官方文档](https://cn.vuejs.org/)
|
|
330
|
+
- [Vue 3 Composition API](https://cn.vuejs.org/guide/extras/composition-api-faq.html)
|
|
331
|
+
- [Vite 官方文档](https://cn.vitejs.dev/)
|
|
332
|
+
- [TypeScript 官方文档](https://www.typescriptlang.org/zh/docs/)
|
|
333
|
+
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
|
334
|
+
|
|
335
|
+
## 重要提示
|
|
336
|
+
|
|
337
|
+
1. **必须使用 pnpm** 作为包管理器
|
|
338
|
+
2. **使用 Vue 3 Composition API** (`<script setup>`) 进行组件开发
|
|
339
|
+
3. **使用 TypeScript** 进行类型安全开发,为 props、emit 和 ref 添加类型
|
|
340
|
+
4. **使用 Tailwind CSS** 进行样式开发,支持响应式和暗色模式
|
|
341
|
+
5. **环境变量必须以 `VITE_` 开头** 才能在客户端代码中访问
|
|
342
|
+
6. **开发时使用 `coze dev`**,支持热更新和快速刷新
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
.pnp
|
|
4
|
+
.pnp.js
|
|
5
|
+
|
|
6
|
+
# Production build
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
out/
|
|
10
|
+
|
|
11
|
+
# Testing
|
|
12
|
+
coverage/
|
|
13
|
+
*.lcov
|
|
14
|
+
.nyc_output
|
|
15
|
+
|
|
16
|
+
# Environment variables
|
|
17
|
+
.env
|
|
18
|
+
.env.local
|
|
19
|
+
.env.development.local
|
|
20
|
+
.env.test.local
|
|
21
|
+
.env.production.local
|
|
22
|
+
|
|
23
|
+
# Logs
|
|
24
|
+
logs/
|
|
25
|
+
*.log
|
|
26
|
+
npm-debug.log*
|
|
27
|
+
yarn-debug.log*
|
|
28
|
+
yarn-error.log*
|
|
29
|
+
pnpm-debug.log*
|
|
30
|
+
lerna-debug.log*
|
|
31
|
+
|
|
32
|
+
# Runtime data
|
|
33
|
+
pids
|
|
34
|
+
*.pid
|
|
35
|
+
*.seed
|
|
36
|
+
*.pid.lock
|
|
37
|
+
|
|
38
|
+
# Cache
|
|
39
|
+
.cache/
|
|
40
|
+
.eslintcache
|
|
41
|
+
.stylelintcache
|
|
42
|
+
|
|
43
|
+
# Editor directories and files
|
|
44
|
+
.vscode/*
|
|
45
|
+
!.vscode/extensions.json
|
|
46
|
+
!.vscode/settings.json
|
|
47
|
+
.idea/
|
|
48
|
+
*.suo
|
|
49
|
+
*.ntvs*
|
|
50
|
+
*.njsproj
|
|
51
|
+
*.sln
|
|
52
|
+
*.sw?
|
|
53
|
+
|
|
54
|
+
# OS files
|
|
55
|
+
.DS_Store
|
|
56
|
+
.DS_Store?
|
|
57
|
+
._*
|
|
58
|
+
Thumbs.db
|
|
59
|
+
|
|
60
|
+
# TypeScript
|
|
61
|
+
*.tsbuildinfo
|
|
62
|
+
|
|
63
|
+
# Vite
|
|
64
|
+
.vite/
|
|
65
|
+
|
|
66
|
+
.coze-logs
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
loglevel=error
|
|
2
|
+
registry=https://registry.npmmirror.com
|
|
3
|
+
|
|
4
|
+
strictStorePkgContentCheck=false
|
|
5
|
+
verifyStoreIntegrity=false
|
|
6
|
+
|
|
7
|
+
# 网络优化
|
|
8
|
+
network-concurrency=16
|
|
9
|
+
fetch-retries=3
|
|
10
|
+
fetch-timeout=60000
|
|
11
|
+
|
|
12
|
+
# 严格使用 peer dependencies
|
|
13
|
+
strict-peer-dependencies=false
|
|
14
|
+
|
|
15
|
+
# 自动生成 lockfile
|
|
16
|
+
auto-install-peers=true
|
|
17
|
+
|
|
18
|
+
# lockfile 配置
|
|
19
|
+
lockfile=true
|
|
20
|
+
prefer-frozen-lockfile=true
|
|
21
|
+
|
|
22
|
+
# 如果 lockfile 存在但过期,更新而不是失败
|
|
23
|
+
resolution-mode=highest
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
4
|
+
|
|
5
|
+
export default defineConfig([
|
|
6
|
+
eslint.configs.recommended,
|
|
7
|
+
...tseslint.configs.recommended,
|
|
8
|
+
globalIgnores(['dist/**', 'node_modules/**']),
|
|
9
|
+
]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta name="description" content="扣子编程,你的 AI 开发伙伴已就位" />
|
|
7
|
+
<title>扣子编程 - AI 开发伙伴</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= appName %>",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vue 3 application with Vite + TypeScript",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "bash ./scripts/build.sh",
|
|
8
|
+
"dev": "bash ./scripts/dev.sh",
|
|
9
|
+
"preinstall": "npx only-allow pnpm",
|
|
10
|
+
"lint": "eslint",
|
|
11
|
+
"start": "bash ./scripts/start.sh",
|
|
12
|
+
"ts-check": "vue-tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@supabase/supabase-js": "2.95.3",
|
|
16
|
+
"dotenv": "^17.2.3",
|
|
17
|
+
"vue": "^3.5.13"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
21
|
+
"autoprefixer": "^10.4.20",
|
|
22
|
+
"coze-coding-dev-sdk": "^0.7.16",
|
|
23
|
+
"eslint": "^9",
|
|
24
|
+
"less": "^4.2.1",
|
|
25
|
+
"only-allow": "^1.2.2",
|
|
26
|
+
"postcss": "^8.4.49",
|
|
27
|
+
"tailwindcss": "^3.4.17",
|
|
28
|
+
"typescript": "^5.6.0",
|
|
29
|
+
"typescript-eslint": "^8",
|
|
30
|
+
"vite": "^7.2.4",
|
|
31
|
+
"vue-tsc": "^2.2.0"
|
|
32
|
+
},
|
|
33
|
+
"packageManager": "pnpm@9.0.0",
|
|
34
|
+
"engines": {
|
|
35
|
+
"pnpm": ">=9.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|