@dengzhibo/create-vue-template 0.0.2 → 0.0.4
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/CHANGELOG.md +9 -1
- package/README.md +2 -0
- package/lib/generate.js +12 -7
- package/lib/options.js +5 -5
- package/lib/prompts.js +1 -1
- package/package.json +1 -1
- package/templates/base/README.md +3 -3
- package/templates/base/package.json +2 -2
- package/templates/features/JSX/package.fragment.json +5 -0
- /package/templates/features/{unit-test → Vitest}/package.fragment.json +0 -0
- /package/templates/features/{unit-test → Vitest}/src/components/__tests__/HelloWorld.spec.ts +0 -0
- /package/templates/features/{unit-test → Vitest}/tsconfig.vitest.json +0 -0
- /package/templates/features/{unit-test → Vitest}/vitest.config.ts +0 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -61,3 +61,5 @@ node scripts/check-package.mjs
|
|
|
61
61
|
## 发布文件范围
|
|
62
62
|
|
|
63
63
|
`bin/`、`lib/`、`templates/`、README、CHANGELOG、LICENSE 与 package.json 随 npm 包发布。测试、预检脚本、AGENTS.md 和本地缓存仅用于仓库维护,不需要上传 npm。`_gitignore` 在生成项目时恢复为 `.gitignore`。
|
|
64
|
+
|
|
65
|
+
未指定目录时默认创建 `vue-project`;指定目录时使用目录名作为包名。生成项目版本与本脚手架根 package.json 的版本一致。
|
package/lib/generate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import { assertTarget,
|
|
4
|
+
import { assertTarget, normalizeOptions } from './options.js'
|
|
5
5
|
|
|
6
6
|
const templateDir = fileURLToPath(new URL('../templates/', import.meta.url))
|
|
7
7
|
const skip = new Set(['node_modules', 'dist', '.npmignore', '.git', '.DS_Store', 'pnpm-lock.yaml', '.turbo'])
|
|
@@ -38,7 +38,7 @@ export function createPlan(input = {}, cwd = process.cwd()) {
|
|
|
38
38
|
const parse = file => JSON.parse(files.get(file).toString())
|
|
39
39
|
const pkg = parse('package.json')
|
|
40
40
|
for (const feature of options.features) {
|
|
41
|
-
const directory = path.join(templateDir, 'features', feature)
|
|
41
|
+
const directory = path.join(templateDir, 'features', ({ 'unit-test': 'Vitest', 'jsx': 'JSX' })[feature] || feature)
|
|
42
42
|
add(directory)
|
|
43
43
|
const fragment = JSON.parse(fs.readFileSync(path.join(directory, 'package.fragment.json'), 'utf8'))
|
|
44
44
|
for (const field of ['scripts', 'dependencies', 'devDependencies']) {
|
|
@@ -50,6 +50,10 @@ export function createPlan(input = {}, cwd = process.cwd()) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
if (has('jsx')) {
|
|
54
|
+
const vite = files.get('vite.config.ts').toString().replace(/\r\n/g, '\n').replace('import vue from \'@vitejs/plugin-vue\'', 'import vue from \'@vitejs/plugin-vue\'\nimport vueJsx from \'@vitejs/plugin-vue-jsx\'').replace(' vue(),', ' vue(),\n vueJsx(),')
|
|
55
|
+
files.set('vite.config.ts', vite)
|
|
56
|
+
}
|
|
53
57
|
const extensions = parse('.vscode/extensions.json')
|
|
54
58
|
if (has('unit-test')) {
|
|
55
59
|
const tsconfig = parse('tsconfig.json')
|
|
@@ -69,16 +73,17 @@ export function createPlan(input = {}, cwd = process.cwd()) {
|
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
files.set('eslint.config.ts', eslint)
|
|
72
|
-
const oxlint = parse('.oxlintrc.json')
|
|
73
|
-
if (!has('unit-test'))
|
|
74
|
-
oxlint.plugins = oxlint.plugins.filter(p => p !== 'vitest')
|
|
75
|
-
files.set('.oxlintrc.json', encode(oxlint))
|
|
76
76
|
const settings = JSON.parse(fs.readFileSync(path.join(templateDir, 'features/code-quality/settings.fragment.json'), 'utf8'))
|
|
77
77
|
files.set('.vscode/settings.json', encode({ ...parse('.vscode/settings.json'), ...settings }))
|
|
78
78
|
extensions.recommendations.push('dbaeumer.vscode-eslint', 'EditorConfig.EditorConfig', 'oxc.oxc-vscode')
|
|
79
79
|
}
|
|
80
80
|
files.set('.vscode/extensions.json', encode(extensions))
|
|
81
81
|
pkg.name = name
|
|
82
|
+
pkg.version = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
83
|
+
const scriptOrder = ['dev', 'build', 'preview', 'test:unit', 'test:e2e', 'build-only', 'type-check', 'lint', 'lint:oxlint', 'lint:eslint', 'format']
|
|
84
|
+
pkg.scripts = Object.fromEntries(scriptOrder.filter(key => Object.hasOwn(pkg.scripts, key)).map(key => [key, pkg.scripts[key]]))
|
|
85
|
+
for (const field of ['dependencies', 'devDependencies'])
|
|
86
|
+
pkg[field] = Object.fromEntries(Object.entries(pkg[field]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))
|
|
82
87
|
files.set('package.json', encode(pkg))
|
|
83
88
|
let readme = files.get('README.md').toString().replace(/\r\n/g, '\n')
|
|
84
89
|
const sections = [['unit-test', 'Run Unit Tests'], ['e2e', 'Run End-to-End Tests'], ['code-quality', 'Lint with']]
|
|
@@ -86,7 +91,7 @@ export function createPlan(input = {}, cwd = process.cwd()) {
|
|
|
86
91
|
if (!has(feature))
|
|
87
92
|
readme = readme.replace(new RegExp(`### ${title}[\\s\\S]*?(?=\\n### |$)`), '')
|
|
88
93
|
}
|
|
89
|
-
files.set('README.md',
|
|
94
|
+
files.set('README.md', readme.replace('# base', `# ${name}`))
|
|
90
95
|
return { target, options, files }
|
|
91
96
|
}
|
|
92
97
|
export function writePlan(plan) {
|
package/lib/options.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
|
-
export const featureLabels = { 'code-quality': '代码规范', 'unit-test': '单元测试', 'e2e': '端到端测试' }
|
|
4
|
+
export const featureLabels = { 'code-quality': '代码规范', 'unit-test': '单元测试', 'e2e': '端到端测试', 'jsx': 'JSX 支持' }
|
|
5
5
|
export function normalizeOptions(input = {}) {
|
|
6
6
|
const features = input.features ?? []
|
|
7
7
|
if (!Array.isArray(features) || features.some(f => !Object.hasOwn(featureLabels, f)))
|
|
8
|
-
throw new Error('功能仅支持 code-quality、unit-test、e2e')
|
|
9
|
-
return { location: input.location || '
|
|
8
|
+
throw new Error('功能仅支持 code-quality、unit-test、e2e、jsx')
|
|
9
|
+
return { location: input.location || 'vue-project', features: Object.keys(featureLabels).filter(f => features.includes(f)), install: Boolean(input.install) }
|
|
10
10
|
}
|
|
11
11
|
export function assertTarget(target) {
|
|
12
12
|
let current = target
|
|
@@ -24,7 +24,7 @@ export function assertTarget(target) {
|
|
|
24
24
|
|
|
25
25
|
export const help = `用法:create-vue-template [目录] [选项]
|
|
26
26
|
--yes, -y 非交互创建
|
|
27
|
-
--features=code-quality,unit-test,e2e 选择功能,默认全部不选
|
|
27
|
+
--features=code-quality,unit-test,e2e,jsx 选择功能,默认全部不选
|
|
28
28
|
--features= 全部不选
|
|
29
29
|
--install 安装依赖,默认不安装
|
|
30
30
|
--help, -h 帮助
|
|
@@ -48,6 +48,6 @@ export function parseArgs(args) {
|
|
|
48
48
|
}
|
|
49
49
|
if (locations.length > 1)
|
|
50
50
|
throw new Error('只能指定一个创建目录')
|
|
51
|
-
options.location = locations[0] || '
|
|
51
|
+
options.location = locations[0] || 'vue-project'
|
|
52
52
|
return { options: normalizeOptions(options), yes }
|
|
53
53
|
}
|
package/lib/prompts.js
CHANGED
|
@@ -303,7 +303,7 @@ export function prompt({ title, choices, multiple = false, initial, defaultValue
|
|
|
303
303
|
|
|
304
304
|
export async function collectOptions(previous = {}, ask = prompt) {
|
|
305
305
|
const options = normalizeOptions(previous)
|
|
306
|
-
options.location = await ask({ title: '项目创建位置', initial: options.location === '.' ? '' : options.location, defaultValue: '
|
|
306
|
+
options.location = await ask({ title: '项目创建位置', initial: options.location === '.' ? '' : options.location, defaultValue: 'vue-project', hint: '输入 my-vue-app:新建项目文件夹;输入 .:在当前目录创建;支持相对或绝对路径' }) || 'vue-project'
|
|
307
307
|
options.features = await ask({ title: '选择可选功能', multiple: true, choices: Object.entries(featureLabels).map(([value, label]) => ({ value, label })), initial: options.features, hint: 'Space 勾选,Enter 确认;可全部不选或全部选择' })
|
|
308
308
|
options.install = await ask({ title: '是否立即安装依赖?', choices: [{ value: false, label: '暂不安装' }, { value: true, label: '立即安装' }], initial: options.install })
|
|
309
309
|
console.log(summary(options))
|
package/package.json
CHANGED
package/templates/base/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vue-project
|
|
2
2
|
|
|
3
3
|
This template should help get you started developing with Vue 3 in Vite.
|
|
4
4
|
|
|
@@ -53,7 +53,7 @@ pnpm test:unit
|
|
|
53
53
|
|
|
54
54
|
```sh
|
|
55
55
|
# Install browsers for the first run
|
|
56
|
-
|
|
56
|
+
npx playwright install
|
|
57
57
|
|
|
58
58
|
# When testing on CI, must build the project first
|
|
59
59
|
pnpm build
|
|
@@ -63,7 +63,7 @@ pnpm test:e2e
|
|
|
63
63
|
# Runs the tests only on Chromium
|
|
64
64
|
pnpm test:e2e --project=chromium
|
|
65
65
|
# Runs the tests of a specific file
|
|
66
|
-
pnpm test:e2e
|
|
66
|
+
pnpm test:e2e tests/example.spec.ts
|
|
67
67
|
# Runs the tests in debug mode
|
|
68
68
|
pnpm test:e2e --debug
|
|
69
69
|
```
|
|
File without changes
|
/package/templates/features/{unit-test → Vitest}/src/components/__tests__/HelloWorld.spec.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|