create-vee-vue 0.0.0-stage → 1.0.1
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/bin/index.js +145 -0
- package/package.json +18 -4
- package/templates/vue-ts/.editorconfig +8 -0
- package/templates/vue-ts/.gitattributes +1 -0
- package/templates/vue-ts/.oxlintrc.json +10 -0
- package/templates/vue-ts/.prettierrc.json +6 -0
- package/templates/vue-ts/README.md +48 -0
- package/templates/vue-ts/env.d.ts +1 -0
- package/templates/vue-ts/eslint.config.ts +26 -0
- package/templates/vue-ts/index.html +13 -0
- package/templates/vue-ts/package.json +43 -0
- package/templates/vue-ts/public/favicon.ico +0 -0
- package/templates/vue-ts/src/App.vue +5 -0
- package/templates/vue-ts/src/main.ts +4 -0
- package/templates/vue-ts/tsconfig.app.json +18 -0
- package/templates/vue-ts/tsconfig.json +11 -0
- package/templates/vue-ts/tsconfig.node.json +28 -0
- package/templates/vue-ts/vite.config.ts +18 -0
- package/README.md +0 -3
package/bin/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { input, select } from "@inquirer/prompts";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
const program = new Command();
|
|
10
|
+
|
|
11
|
+
function normalizePackageName(name) {
|
|
12
|
+
return (
|
|
13
|
+
name
|
|
14
|
+
.trim()
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
// 空格和下划线替换为 -
|
|
17
|
+
.replace(/[\s_]+/g, "-")
|
|
18
|
+
// 移除不允许的字符
|
|
19
|
+
.replace(/[^a-z0-9.-]/g, "")
|
|
20
|
+
// 连续的 - 合并为一个
|
|
21
|
+
.replace(/-+/g, "-")
|
|
22
|
+
// 移除开头和结尾的 -
|
|
23
|
+
.replace(/^-+|-+$/g, "")
|
|
24
|
+
// npm 包名不能以 . 开头
|
|
25
|
+
.replace(/^\.+/, "")
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function updatePackageName(targetDir, projectName) {
|
|
30
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
31
|
+
|
|
32
|
+
// 读取 package.json
|
|
33
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
|
|
34
|
+
|
|
35
|
+
// JSON 字符串转换成 JavaScript 对象
|
|
36
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
37
|
+
|
|
38
|
+
// 修改项目名称
|
|
39
|
+
packageJson.name = projectName;
|
|
40
|
+
|
|
41
|
+
// 将对象转换成 JSON 字符串并写入文件
|
|
42
|
+
fs.writeFileSync(
|
|
43
|
+
packageJsonPath,
|
|
44
|
+
JSON.stringify(packageJson, null, 2) + "\n",
|
|
45
|
+
"utf-8",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
program
|
|
50
|
+
.name("create-vee-vue")
|
|
51
|
+
.description("Create a Vue 3 project using my template")
|
|
52
|
+
.version("1.0.0");
|
|
53
|
+
|
|
54
|
+
// 项目名称改为可选参数
|
|
55
|
+
program.argument("[project-name]", "项目名称").action(async (projectName) => {
|
|
56
|
+
try {
|
|
57
|
+
// 1. 用户没有输入项目名称时,弹出输入框
|
|
58
|
+
if (!projectName) {
|
|
59
|
+
projectName = await input({
|
|
60
|
+
message: "Project name:",
|
|
61
|
+
default: "my-vue-app",
|
|
62
|
+
validate(value) {
|
|
63
|
+
if (!value.trim()) {
|
|
64
|
+
return "项目名称不能为空";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const packageName = normalizePackageName(value);
|
|
68
|
+
|
|
69
|
+
if (!packageName) {
|
|
70
|
+
return "请输入有效的项目名称";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (packageName.length > 214) {
|
|
74
|
+
return "项目名称不能超过 214 个字符";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 去除项目名称首尾空格
|
|
83
|
+
projectName = projectName.trim();
|
|
84
|
+
|
|
85
|
+
// 生成合法的 npm 包名称
|
|
86
|
+
const packageName = normalizePackageName(projectName);
|
|
87
|
+
|
|
88
|
+
// 2. 选择项目模板
|
|
89
|
+
const templateName = await select({
|
|
90
|
+
message: "Select a template:",
|
|
91
|
+
choices: [
|
|
92
|
+
{
|
|
93
|
+
name: "Vue 3 + TypeScript",
|
|
94
|
+
value: "vue-ts",
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 3. 计算项目路径
|
|
100
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
101
|
+
|
|
102
|
+
// 4. 计算模板路径
|
|
103
|
+
const templateDir = path.resolve(__dirname, "../templates", templateName);
|
|
104
|
+
|
|
105
|
+
// 5. 检查项目目录是否存在
|
|
106
|
+
if (fs.existsSync(targetDir)) {
|
|
107
|
+
console.error(`目录已存在:${targetDir}`);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 6. 检查模板是否存在
|
|
113
|
+
if (!fs.existsSync(templateDir)) {
|
|
114
|
+
console.error(`模板不存在:${templateDir}`);
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 7. 复制模板
|
|
120
|
+
console.log(`Scaffolding project in ${projectName}...`);
|
|
121
|
+
|
|
122
|
+
fs.cpSync(templateDir, targetDir, {
|
|
123
|
+
recursive: true,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
updatePackageName(targetDir, packageName);
|
|
127
|
+
|
|
128
|
+
console.log("");
|
|
129
|
+
console.log("Done!");
|
|
130
|
+
console.log("");
|
|
131
|
+
console.log(` cd ${projectName}`);
|
|
132
|
+
console.log(" pnpm install");
|
|
133
|
+
console.log(" pnpm dev");
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error.name === "AbortPromptError") {
|
|
136
|
+
console.log("\n取消创建项目");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.error(error);
|
|
141
|
+
process.exitCode = 1;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
program.parseAsync();
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vee-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "My custom Vue 3 scaffolding",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-vee-vue": "./bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"templates"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "node ./bin/index.js"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@inquirer/prompts": "^8.7.5",
|
|
18
|
+
"commander": "^14.0.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# vee-vue-template
|
|
2
|
+
|
|
3
|
+
This template should help get you started developing with Vue 3 in Vite.
|
|
4
|
+
|
|
5
|
+
## Recommended IDE Setup
|
|
6
|
+
|
|
7
|
+
[VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
|
8
|
+
|
|
9
|
+
## Recommended Browser Setup
|
|
10
|
+
|
|
11
|
+
- Chromium-based browsers (Chrome, Edge, Brave, etc.):
|
|
12
|
+
- [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
|
|
13
|
+
- [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
|
|
14
|
+
- Firefox:
|
|
15
|
+
- [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)
|
|
16
|
+
- [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)
|
|
17
|
+
|
|
18
|
+
## Type Support for `.vue` Imports in TS
|
|
19
|
+
|
|
20
|
+
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
|
|
21
|
+
|
|
22
|
+
## Customize configuration
|
|
23
|
+
|
|
24
|
+
See [Vite Configuration Reference](https://vite.dev/config/).
|
|
25
|
+
|
|
26
|
+
## Project Setup
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pnpm install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Compile and Hot-Reload for Development
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pnpm dev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Type-Check, Compile and Minify for Production
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pnpm build
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Lint with [ESLint](https://eslint.org/)
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pnpm lint
|
|
48
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { globalIgnores } from 'eslint/config'
|
|
2
|
+
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
|
|
3
|
+
import pluginVue from 'eslint-plugin-vue'
|
|
4
|
+
import pluginOxlint from 'eslint-plugin-oxlint'
|
|
5
|
+
import skipFormatting from 'eslint-config-prettier/flat'
|
|
6
|
+
|
|
7
|
+
// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
|
|
8
|
+
// import { configureVueProject } from '@vue/eslint-config-typescript'
|
|
9
|
+
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
|
|
10
|
+
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
|
|
11
|
+
|
|
12
|
+
export default defineConfigWithVueTs(
|
|
13
|
+
{
|
|
14
|
+
name: 'app/files-to-lint',
|
|
15
|
+
files: ['**/*.{vue,ts,mts,tsx}'],
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
|
|
19
|
+
|
|
20
|
+
...pluginVue.configs['flat/essential'],
|
|
21
|
+
vueTsConfigs.recommended,
|
|
22
|
+
|
|
23
|
+
...pluginOxlint.buildFromOxlintConfigFile('.oxlintrc.json'),
|
|
24
|
+
|
|
25
|
+
skipFormatting,
|
|
26
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<link rel="icon" href="/favicon.ico">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Vite App</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,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vee-vue-template",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "run-p type-check \"build-only {@}\" --",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"build-only": "vite build",
|
|
11
|
+
"type-check": "vue-tsc --build",
|
|
12
|
+
"lint": "run-s \"lint:*\"",
|
|
13
|
+
"lint:oxlint": "oxlint . --fix",
|
|
14
|
+
"lint:eslint": "eslint . --fix --cache",
|
|
15
|
+
"format": "prettier --write --experimental-cli src/"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"vue": "^3.5.42"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tsconfig/node24": "^24.0.5",
|
|
22
|
+
"@types/node": "^24.13.4",
|
|
23
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
24
|
+
"@vue/eslint-config-typescript": "^14.9.0",
|
|
25
|
+
"@vue/tsconfig": "^0.9.1",
|
|
26
|
+
"eslint": "^10.10.0",
|
|
27
|
+
"eslint-config-prettier": "^10.1.8",
|
|
28
|
+
"eslint-plugin-oxlint": "~1.82.0",
|
|
29
|
+
"eslint-plugin-vue": "~10.11.0",
|
|
30
|
+
"jiti": "^2.7.0",
|
|
31
|
+
"npm-run-all2": "^9.0.3",
|
|
32
|
+
"oxlint": "~1.82.0",
|
|
33
|
+
"prettier": "3.9.6",
|
|
34
|
+
"typescript": "~6.0.0",
|
|
35
|
+
"vite": "^8.2.2",
|
|
36
|
+
"vite-plugin-vue-devtools": "^8.2.1",
|
|
37
|
+
"vue-eslint-parser": "^10.4.1",
|
|
38
|
+
"vue-tsc": "^3.3.11"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^22.18.0 || >=24.12.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
|
3
|
+
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
|
|
4
|
+
"exclude": ["src/**/__tests__/*"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
// Extra safety for array and object lookups, but may have false positives.
|
|
7
|
+
"noUncheckedIndexedAccess": true,
|
|
8
|
+
|
|
9
|
+
// Path mapping for cleaner imports.
|
|
10
|
+
"paths": {
|
|
11
|
+
"@/*": ["./src/*"]
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
// `vue-tsc --build` produces a .tsbuildinfo file for incremental type-checking.
|
|
15
|
+
// Specified here to keep it out of the root directory.
|
|
16
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// TSConfig for modules that run in Node.js environment via either transpilation or type-stripping.
|
|
2
|
+
{
|
|
3
|
+
"extends": "@tsconfig/node24/tsconfig.json",
|
|
4
|
+
"include": [
|
|
5
|
+
"vite.config.*",
|
|
6
|
+
"vitest.config.*",
|
|
7
|
+
"cypress.config.*",
|
|
8
|
+
"playwright.config.*",
|
|
9
|
+
"eslint.config.*"
|
|
10
|
+
],
|
|
11
|
+
"compilerOptions": {
|
|
12
|
+
// Most tools use transpilation instead of Node.js's native type-stripping.
|
|
13
|
+
// Bundler mode provides a smoother developer experience.
|
|
14
|
+
"module": "preserve",
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"allowImportingTsExtensions": true,
|
|
17
|
+
|
|
18
|
+
// Include Node.js types and avoid accidentally including other `@types/*` packages.
|
|
19
|
+
"types": ["node"],
|
|
20
|
+
|
|
21
|
+
// Disable emitting output during `vue-tsc --build`, which is used for type-checking only.
|
|
22
|
+
"noEmit": true,
|
|
23
|
+
|
|
24
|
+
// `vue-tsc --build` produces a .tsbuildinfo file for incremental type-checking.
|
|
25
|
+
// Specified here to keep it out of the root directory.
|
|
26
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from 'node:url'
|
|
2
|
+
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
import vue from '@vitejs/plugin-vue'
|
|
5
|
+
import vueDevTools from 'vite-plugin-vue-devtools'
|
|
6
|
+
|
|
7
|
+
// https://vite.dev/config/
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
plugins: [
|
|
10
|
+
vue(),
|
|
11
|
+
vueDevTools(),
|
|
12
|
+
],
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: {
|
|
15
|
+
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})
|
package/README.md
DELETED