vue-standard-wanfu 2.0.0
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/README.md +106 -0
- package/bin/cli.js +131 -0
- package/package.json +35 -0
- package/template/.prettierrc +9 -0
- package/template/README.md +133 -0
- package/template/eslint.config.js +30 -0
- package/template/index.html +13 -0
- package/template/package-lock.json +3566 -0
- package/template/package.json +35 -0
- package/template/src/app/App.vue +16 -0
- package/template/src/components/HelloWorld.vue +82 -0
- package/template/src/main.ts +12 -0
- package/template/src/pages/index.vue +136 -0
- package/template/src/router/index.ts +17 -0
- package/template/src/styles/main.css +32 -0
- package/template/src/types/index.ts +25 -0
- package/template/tsconfig.json +33 -0
- package/template/tsconfig.node.json +11 -0
- package/template/vite.config.ts +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# create-vue-standard
|
|
2
|
+
|
|
3
|
+
基于前端开发规范的 Vue 3 项目脚手架工具,快速创建符合规范的标准项目。
|
|
4
|
+
|
|
5
|
+
## 使用方法
|
|
6
|
+
|
|
7
|
+
### 使用 npm
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm create vue-standard@latest
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 使用 pnpm(推荐)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm create vue-standard
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 使用 yarn
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn create vue-standard
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 直接指定项目名称
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm create vue-standard my-project
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 使用命令行参数
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm create vue-standard my-project --description "My Vue Project" --author "Your Name"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 交互式创建流程
|
|
38
|
+
|
|
39
|
+
运行命令后,会提示你输入:
|
|
40
|
+
|
|
41
|
+
1. **项目名称** - 项目的文件夹名称
|
|
42
|
+
2. **项目描述** - 项目的简短描述
|
|
43
|
+
3. **作者名称** - 项目作者
|
|
44
|
+
4. **是否初始化 Git** - 自动初始化 Git 仓库并提交
|
|
45
|
+
|
|
46
|
+
## 创建的项目包含
|
|
47
|
+
|
|
48
|
+
✅ Vue 3.5+
|
|
49
|
+
✅ TypeScript (strict 模式)
|
|
50
|
+
✅ Vite 8 构建工具
|
|
51
|
+
✅ Vue Router 4
|
|
52
|
+
✅ Pinia 状态管理
|
|
53
|
+
✅ ESLint + Prettier 代码规范
|
|
54
|
+
✅ 完整的项目结构
|
|
55
|
+
✅ 示例页面和组件
|
|
56
|
+
✅ 响应式设计
|
|
57
|
+
|
|
58
|
+
## 项目特性
|
|
59
|
+
|
|
60
|
+
- 📋 **符合规范** - 严格遵循前端开发规范 v1.01
|
|
61
|
+
- 🎯 **开箱即用** - 无需额外配置,立即开始开发
|
|
62
|
+
- 🔧 **易于定制** - 清晰的目录结构,方便扩展
|
|
63
|
+
- 🚀 **现代化** - 使用最新稳定版本的技术栈
|
|
64
|
+
|
|
65
|
+
## 开发说明
|
|
66
|
+
|
|
67
|
+
### 本地开发
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# 克隆项目
|
|
71
|
+
git clone <repository-url>
|
|
72
|
+
cd create-vue-standard
|
|
73
|
+
|
|
74
|
+
# 安装依赖
|
|
75
|
+
pnpm install
|
|
76
|
+
|
|
77
|
+
# 链接到全局(用于测试)
|
|
78
|
+
pnpm link --global
|
|
79
|
+
|
|
80
|
+
# 测试脚手架
|
|
81
|
+
create-vue-standard test-project
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 发布到 npm
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 登录 npm
|
|
88
|
+
npm login
|
|
89
|
+
|
|
90
|
+
# 更新版本号
|
|
91
|
+
npm version patch # 或 minor, major
|
|
92
|
+
|
|
93
|
+
# 发布
|
|
94
|
+
npm publish
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 技术实现
|
|
98
|
+
|
|
99
|
+
- **prompts** - 交互式命令行提示
|
|
100
|
+
- **kolorist** - 终端彩色输出
|
|
101
|
+
- **fs-extra** - 增强的文件系统操作
|
|
102
|
+
- **minimist** - 命令行参数解析
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import { red, green, blue, yellow } from 'kolorist';
|
|
5
|
+
import minimist from 'minimist';
|
|
6
|
+
import fs from 'fs-extra';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
import { copyTemplate } from '../lib/copy.js';
|
|
11
|
+
import { initGit } from '../lib/git.js';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
|
|
16
|
+
// 解析命令行参数
|
|
17
|
+
const argv = minimist(process.argv.slice(2));
|
|
18
|
+
const targetDir = argv._[0];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 主函数
|
|
22
|
+
*/
|
|
23
|
+
async function main() {
|
|
24
|
+
console.log(`\n${blue('✨')} ${green('欢迎使用 Vue 标准项目脚手架')}\n`);
|
|
25
|
+
|
|
26
|
+
let result;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// 如果没有指定目录,交互式询问
|
|
30
|
+
if (!targetDir) {
|
|
31
|
+
result = await prompts(
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
type: 'text',
|
|
35
|
+
name: 'projectName',
|
|
36
|
+
message: '请输入项目名称:',
|
|
37
|
+
initial: 'vue-project',
|
|
38
|
+
validate: (value) => {
|
|
39
|
+
if (!value || value.trim() === '') {
|
|
40
|
+
return '项目名称不能为空';
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
name: 'description',
|
|
48
|
+
message: '请输入项目描述:',
|
|
49
|
+
initial: 'A Vue 3 project',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
name: 'author',
|
|
54
|
+
message: '请输入作者名称:',
|
|
55
|
+
initial: '',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
{
|
|
59
|
+
onCancel: () => {
|
|
60
|
+
console.log(yellow('\n👋 已取消创建\n'));
|
|
61
|
+
process.exit(0);
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
// 使用命令行参数
|
|
67
|
+
result = {
|
|
68
|
+
projectName: targetDir,
|
|
69
|
+
description: argv.description || 'A Vue 3 project',
|
|
70
|
+
author: argv.author || '',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { projectName, description, author } = result;
|
|
75
|
+
const root = path.join(process.cwd(), projectName);
|
|
76
|
+
|
|
77
|
+
// 检查目录是否已存在
|
|
78
|
+
if (fs.existsSync(root)) {
|
|
79
|
+
const { overwrite } = await prompts({
|
|
80
|
+
type: 'confirm',
|
|
81
|
+
name: 'overwrite',
|
|
82
|
+
message: `目录 "${projectName}" 已存在,是否覆盖?`,
|
|
83
|
+
initial: false,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (!overwrite) {
|
|
87
|
+
console.log(red('\n❌ 操作已取消\n'));
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 清空目录
|
|
92
|
+
fs.emptyDirSync(root);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(`\n${blue('📦')} 正在创建项目...`);
|
|
96
|
+
|
|
97
|
+
// 复制模板文件
|
|
98
|
+
await copyTemplate(root, {
|
|
99
|
+
projectName,
|
|
100
|
+
description,
|
|
101
|
+
author,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// 初始化 git
|
|
105
|
+
const { useGit } = await prompts({
|
|
106
|
+
type: 'confirm',
|
|
107
|
+
name: 'useGit',
|
|
108
|
+
message: '是否初始化 Git 仓库?',
|
|
109
|
+
initial: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (useGit) {
|
|
113
|
+
console.log(`${blue('🔧')} 初始化 Git 仓库...`);
|
|
114
|
+
initGit(root);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 显示成功信息
|
|
118
|
+
console.log(`\n${green('✅')} 项目创建成功!\n`);
|
|
119
|
+
console.log(`${blue('📁')} 项目位置: ${root}\n`);
|
|
120
|
+
console.log(`${blue('🚀')} 开始使用:\n`);
|
|
121
|
+
console.log(` ${yellow('cd')} ${projectName}`);
|
|
122
|
+
console.log(` ${yellow('pnpm install')}`);
|
|
123
|
+
console.log(` ${yellow('pnpm dev')}\n`);
|
|
124
|
+
console.log(`${blue('📖')} 更多信息请查看 README.md\n`);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(red('\n❌ 项目创建失败:'), error.message);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-standard-wanfu",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "基于前端开发规范的 Vue 3 项目脚手架",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-vue-standard-wanfu": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"vue",
|
|
18
|
+
"vue3",
|
|
19
|
+
"scaffold",
|
|
20
|
+
"template",
|
|
21
|
+
"typescript",
|
|
22
|
+
"vite"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"prompts": "^2.4.2",
|
|
28
|
+
"kolorist": "^1.8.0",
|
|
29
|
+
"fs-extra": "^11.2.0",
|
|
30
|
+
"minimist": "^1.2.8"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Hello World - Vue 3 项目
|
|
2
|
+
|
|
3
|
+
这是一个符合《前端开发规范 v1.01》的 Vue 3 Hello World 示例项目。
|
|
4
|
+
|
|
5
|
+
## 技术栈
|
|
6
|
+
|
|
7
|
+
- **Vue 3.5+** - 渐进式 JavaScript 框架
|
|
8
|
+
- **TypeScript** - 类型安全的 JavaScript 超集
|
|
9
|
+
- **Vite 8** - 下一代前端构建工具
|
|
10
|
+
- **Vue Router 4** - 官方路由管理器
|
|
11
|
+
- **Pinia** - 直观的状态管理库
|
|
12
|
+
- **ESLint + Prettier** - 代码质量和格式化工具
|
|
13
|
+
|
|
14
|
+
## 项目结构
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
hello-world/
|
|
18
|
+
├── src/
|
|
19
|
+
│ ├── app/ # 应用启动、全局配置
|
|
20
|
+
│ │ └── App.vue # 根组件
|
|
21
|
+
│ ├── components/ # 通用组件
|
|
22
|
+
│ │ └── HelloWorld.vue
|
|
23
|
+
│ ├── pages/ # 页面组件
|
|
24
|
+
│ │ └── index.vue # 首页
|
|
25
|
+
│ ├── router/ # 路由配置
|
|
26
|
+
│ │ └── index.ts
|
|
27
|
+
│ ├── styles/ # 全局样式
|
|
28
|
+
│ │ └── main.css
|
|
29
|
+
│ ├── types/ # 类型定义
|
|
30
|
+
│ │ └── index.ts
|
|
31
|
+
│ └── main.ts # 入口文件
|
|
32
|
+
├── index.html # HTML 模板
|
|
33
|
+
├── package.json # 项目依赖
|
|
34
|
+
├── tsconfig.json # TypeScript 配置
|
|
35
|
+
├── vite.config.ts # Vite 配置
|
|
36
|
+
├── eslint.config.js # ESLint 配置
|
|
37
|
+
└── .prettierrc # Prettier 配置
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 快速开始
|
|
41
|
+
|
|
42
|
+
### 环境要求
|
|
43
|
+
|
|
44
|
+
- Node.js >= 24 (LTS)
|
|
45
|
+
- pnpm >= 10
|
|
46
|
+
|
|
47
|
+
### 安装依赖
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 开发模式
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
访问 http://localhost:3000
|
|
60
|
+
|
|
61
|
+
### 构建生产版本
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm build
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 类型检查
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pnpm typecheck
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 代码检查
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm lint
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 代码格式化
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pnpm format
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 功能特性
|
|
86
|
+
|
|
87
|
+
✅ TypeScript 严格模式
|
|
88
|
+
✅ Vue 3 Composition API
|
|
89
|
+
✅ 路由懒加载
|
|
90
|
+
✅ 组件化开发
|
|
91
|
+
✅ 响应式设计
|
|
92
|
+
✅ 代码规范和格式化
|
|
93
|
+
✅ 路径别名 (@/)
|
|
94
|
+
|
|
95
|
+
## 规范遵循
|
|
96
|
+
|
|
97
|
+
本项目严格遵循以下规范:
|
|
98
|
+
|
|
99
|
+
1. **组件命名**: PascalCase
|
|
100
|
+
2. **文件命名**: kebab-case
|
|
101
|
+
3. **TypeScript**: 启用 strict 模式
|
|
102
|
+
4. **代码注释**: JSDoc + 禅道关联
|
|
103
|
+
5. **区域折叠**: #region / #endregion
|
|
104
|
+
6. **Props 和 Emits**: 完整类型声明
|
|
105
|
+
7. **响应式状态**: ref/computed 合理使用
|
|
106
|
+
|
|
107
|
+
## 示例说明
|
|
108
|
+
|
|
109
|
+
### HelloWorld 组件
|
|
110
|
+
|
|
111
|
+
- 接收 `message` prop
|
|
112
|
+
- 触发 `click` 事件
|
|
113
|
+
- 使用 `<script setup>` 语法
|
|
114
|
+
- Props 和 Emits 类型完整
|
|
115
|
+
|
|
116
|
+
### 首页 (index.vue)
|
|
117
|
+
|
|
118
|
+
- 展示项目信息
|
|
119
|
+
- 计数器功能演示
|
|
120
|
+
- 响应式状态管理
|
|
121
|
+
- 事件处理示例
|
|
122
|
+
|
|
123
|
+
## 开发建议
|
|
124
|
+
|
|
125
|
+
1. 新功能请在 `features/` 目录下按业务模块组织
|
|
126
|
+
2. 通用组件放在 `components/` 目录
|
|
127
|
+
3. 组合式函数统一使用 `useXxx` 命名
|
|
128
|
+
4. API 请求封装在 `services/` 或 `lib/` 目录
|
|
129
|
+
5. 提交代码前运行 lint 和 typecheck
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import vuePlugin from 'eslint-plugin-vue';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
js.configs.recommended,
|
|
7
|
+
...tseslint.configs.recommended,
|
|
8
|
+
...vuePlugin.configs['flat/recommended'],
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.{js,mjs,cjs,ts,vue}'],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
ecmaVersion: 2020,
|
|
13
|
+
sourceType: 'module',
|
|
14
|
+
},
|
|
15
|
+
rules: {
|
|
16
|
+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
17
|
+
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
18
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
19
|
+
'vue/multi-word-component-names': 'off',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
files: ['**/*.vue'],
|
|
24
|
+
languageOptions: {
|
|
25
|
+
parserOptions: {
|
|
26
|
+
parser: tseslint.parser,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Hello World - Vue 3</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|