@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 +5 -1
- package/lib/generate.js +11 -1
- package/lib/options.js +3 -3
- package/package.json +1 -1
- package/templates/base/README.md +3 -3
- 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/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
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
|