@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 CHANGED
@@ -8,4 +8,12 @@
8
8
 
9
9
  ### v0.0.2 (2026-10-22)
10
10
 
11
- * 修复文本相同但文件不匹配问题
11
+ * 修复文本相同但文件不匹配问题
12
+
13
+ ### v0.0.3 (2026-10-22)
14
+
15
+ * 新增JSX功能,优化代码
16
+
17
+ ### v0.0.4 (2026-10-22)
18
+
19
+ * 代码优化
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, featureLabels, normalizeOptions } from './options.js'
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', `${readme.replace('# base', `# ${name}`).trimEnd()}\n\n已选功能:${options.features.map(f => featureLabels[f]).join('、') || '无'}\n`)
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 || '.', features: Object.keys(featureLabels).filter(f => features.includes(f)), install: Boolean(input.install) }
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: '.', hint: '输入 my-vue-app:新建项目文件夹;输入 .:在当前目录创建;支持相对或绝对路径' }) || '.'
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dengzhibo/create-vue-template",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "private": false,
6
6
  "description": "Vue + Vite 应用脚手架,可选代码规范、单元测试和端到端测试",
7
7
  "main": "bin/index.js",
@@ -1,4 +1,4 @@
1
- # base
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
- pnpm exec playwright install
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 e2e/vue.spec.ts
66
+ pnpm test:e2e tests/example.spec.ts
67
67
  # Runs the tests in debug mode
68
68
  pnpm test:e2e --debug
69
69
  ```
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "base",
3
- "version": "0.0.0",
2
+ "name": "vue-project",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -0,0 +1,5 @@
1
+ {
2
+ "devDependencies": {
3
+ "@vitejs/plugin-vue-jsx": "^5.1.6"
4
+ }
5
+ }