@dengzhibo/create-vue-template 0.0.2 → 0.0.3

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,8 @@
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功能,优化代码
package/lib/generate.js CHANGED
@@ -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,12 @@ 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
+ const tsconfig = files.get('tsconfig.app.json').toString().replace('"compilerOptions": {', '"compilerOptions": {\n "jsx": "preserve",\n "jsxImportSource": "vue",')
57
+ files.set('tsconfig.app.json', tsconfig)
58
+ }
53
59
  const extensions = parse('.vscode/extensions.json')
54
60
  if (has('unit-test')) {
55
61
  const tsconfig = parse('tsconfig.json')
@@ -79,6 +85,10 @@ export function createPlan(input = {}, cwd = process.cwd()) {
79
85
  }
80
86
  files.set('.vscode/extensions.json', encode(extensions))
81
87
  pkg.name = name
88
+ const scriptOrder = ['dev', 'build', 'preview', 'test:unit', 'test:e2e', 'build-only', 'type-check', 'lint', 'lint:oxlint', 'lint:eslint', 'format']
89
+ pkg.scripts = Object.fromEntries(scriptOrder.filter(key => Object.hasOwn(pkg.scripts, key)).map(key => [key, pkg.scripts[key]]))
90
+ for (const field of ['dependencies', 'devDependencies'])
91
+ pkg[field] = Object.fromEntries(Object.entries(pkg[field]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))
82
92
  files.set('package.json', encode(pkg))
83
93
  let readme = files.get('README.md').toString().replace(/\r\n/g, '\n')
84
94
  const sections = [['unit-test', 'Run Unit Tests'], ['e2e', 'Run End-to-End Tests'], ['code-quality', 'Lint with']]
package/lib/options.js CHANGED
@@ -1,11 +1,11 @@
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')
8
+ throw new Error('功能仅支持 code-quality、unit-test、e2e、jsx')
9
9
  return { location: input.location || '.', features: Object.keys(featureLabels).filter(f => features.includes(f)), install: Boolean(input.install) }
10
10
  }
11
11
  export function assertTarget(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 帮助
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.3",
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
  ```
@@ -0,0 +1,5 @@
1
+ {
2
+ "devDependencies": {
3
+ "@vitejs/plugin-vue-jsx": "^5.1.6"
4
+ }
5
+ }