@duxweb/dvha-template 1.2.6 → 1.2.7
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
CHANGED
|
@@ -9,6 +9,24 @@ import { bold, cyan, green, red, yellow } from 'kolorist'
|
|
|
9
9
|
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
11
11
|
|
|
12
|
+
function getUiConfigsDir() {
|
|
13
|
+
return path.resolve(__dirname, '..', 'template', 'ui-configs')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getAvailableUIs() {
|
|
17
|
+
return fs.readdirSync(getUiConfigsDir())
|
|
18
|
+
.filter(file => file.endsWith('.json'))
|
|
19
|
+
.map((file) => {
|
|
20
|
+
const config = fs.readJsonSync(path.join(getUiConfigsDir(), file))
|
|
21
|
+
return {
|
|
22
|
+
name: config.name,
|
|
23
|
+
display: config.display,
|
|
24
|
+
description: config.description,
|
|
25
|
+
value: config.name,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
// 获取版本号
|
|
13
31
|
function getVersion() {
|
|
14
32
|
const packagePath = path.resolve(__dirname, '..', 'package.json')
|
|
@@ -19,10 +37,12 @@ function getVersion() {
|
|
|
19
37
|
return '1.0.0'
|
|
20
38
|
}
|
|
21
39
|
|
|
22
|
-
async function createProject(projectName) {
|
|
23
|
-
console.log
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
export async function createProject(projectName, options = {}) {
|
|
41
|
+
const log = options.silent ? () => {} : console.log
|
|
42
|
+
|
|
43
|
+
log()
|
|
44
|
+
log(bold(cyan('欢迎使用 DVHA 项目创建工具! / Welcome to DVHA Project Creator!')))
|
|
45
|
+
log()
|
|
26
46
|
|
|
27
47
|
let targetDir = projectName
|
|
28
48
|
|
|
@@ -34,20 +54,20 @@ async function createProject(projectName) {
|
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
if (!targetDir) {
|
|
37
|
-
|
|
57
|
+
log(red('✖ 项目名称不能为空 / Project name cannot be empty'))
|
|
38
58
|
process.exit(1)
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
const root = path.resolve(targetDir)
|
|
42
62
|
|
|
43
63
|
if (fs.existsSync(root)) {
|
|
44
|
-
const overwrite = await confirm({
|
|
64
|
+
const overwrite = options.overwrite ?? await confirm({
|
|
45
65
|
message: `目录 ${targetDir} 已存在,是否覆盖? / Directory ${targetDir} already exists, overwrite?`,
|
|
46
66
|
default: false,
|
|
47
67
|
})
|
|
48
68
|
|
|
49
69
|
if (!overwrite) {
|
|
50
|
-
|
|
70
|
+
log(yellow('✖ 操作已取消 / Operation cancelled'))
|
|
51
71
|
process.exit(1)
|
|
52
72
|
}
|
|
53
73
|
|
|
@@ -55,25 +75,9 @@ async function createProject(projectName) {
|
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
// 读取可用的UI配置
|
|
58
|
-
const
|
|
59
|
-
const availableUIs = fs.readdirSync(uiConfigsDir)
|
|
60
|
-
.filter(dir => fs.statSync(path.join(uiConfigsDir, dir)).isDirectory())
|
|
61
|
-
.map((dir) => {
|
|
62
|
-
const configPath = path.join(uiConfigsDir, `${dir}.json`)
|
|
63
|
-
if (fs.existsSync(configPath)) {
|
|
64
|
-
const config = fs.readJsonSync(configPath)
|
|
65
|
-
return {
|
|
66
|
-
name: config.name,
|
|
67
|
-
display: config.display,
|
|
68
|
-
description: config.description,
|
|
69
|
-
value: config.name,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null
|
|
73
|
-
})
|
|
74
|
-
.filter(Boolean)
|
|
78
|
+
const availableUIs = getAvailableUIs()
|
|
75
79
|
|
|
76
|
-
const template = await select({
|
|
80
|
+
const template = options.template ?? await select({
|
|
77
81
|
message: '请选择一个模板 / Please select a template:',
|
|
78
82
|
choices: availableUIs.map(ui => ({
|
|
79
83
|
name: `${ui.display} - ${ui.description}`,
|
|
@@ -83,24 +87,30 @@ async function createProject(projectName) {
|
|
|
83
87
|
})
|
|
84
88
|
|
|
85
89
|
if (!template) {
|
|
86
|
-
|
|
90
|
+
log(red('✖ 请选择一个模板 / Please select a template'))
|
|
87
91
|
process.exit(1)
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
if (!availableUIs.some(ui => ui.value === template)) {
|
|
95
|
+
log(red(`✖ UI配置 ${template} 不存在 / UI config ${template} does not exist`))
|
|
96
|
+
process.exit(1)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
log(yellow(`\n正在创建项目 / Creating project: ${targetDir}...`))
|
|
91
100
|
|
|
92
101
|
// 基础模板目录
|
|
93
102
|
const baseTemplateDir = path.resolve(__dirname, '..', 'template', 'base')
|
|
94
|
-
const
|
|
95
|
-
const
|
|
103
|
+
const uiConfigsDir = getUiConfigsDir()
|
|
104
|
+
const uiConfigPath = path.resolve(uiConfigsDir, `${template}.json`)
|
|
105
|
+
const uiPagesDir = path.resolve(uiConfigsDir, template, 'pages')
|
|
96
106
|
|
|
97
107
|
if (!fs.existsSync(baseTemplateDir)) {
|
|
98
|
-
|
|
108
|
+
log(red(`✖ 基础模板不存在 / Base template does not exist`))
|
|
99
109
|
process.exit(1)
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
if (!fs.existsSync(uiConfigPath)) {
|
|
103
|
-
|
|
113
|
+
log(red(`✖ UI配置 ${template} 不存在 / UI config ${template} does not exist`))
|
|
104
114
|
process.exit(1)
|
|
105
115
|
}
|
|
106
116
|
|
|
@@ -231,19 +241,21 @@ async function createProject(projectName) {
|
|
|
231
241
|
fs.writeFileSync(mainTsPath, mainTsContent)
|
|
232
242
|
}
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
log(green('\n✓ 项目创建成功! / Project created successfully!'))
|
|
245
|
+
log()
|
|
246
|
+
log(bold('下一步 / Next steps:'))
|
|
247
|
+
log(cyan(` cd ${targetDir}`))
|
|
248
|
+
log(cyan(' bun install'))
|
|
249
|
+
log(cyan(' bun run dev'))
|
|
250
|
+
log()
|
|
251
|
+
log(bold('或者使用 npm / Or use npm:'))
|
|
252
|
+
log(cyan(` cd ${targetDir}`))
|
|
253
|
+
log(cyan(' npm install'))
|
|
254
|
+
log(cyan(' npm run dev'))
|
|
255
|
+
log()
|
|
256
|
+
log(green('🎉 开始你的 Dux Vue 之旅吧! / Start your Dux Vue journey!'))
|
|
257
|
+
|
|
258
|
+
return root
|
|
247
259
|
}
|
|
248
260
|
|
|
249
261
|
// 主程序
|
|
@@ -287,4 +299,6 @@ program
|
|
|
287
299
|
console.log()
|
|
288
300
|
})
|
|
289
301
|
|
|
290
|
-
|
|
302
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
303
|
+
program.parse()
|
|
304
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duxweb/dvha-template",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.7",
|
|
5
5
|
"description": "Create DVHA project from template",
|
|
6
6
|
"author": "DuxWeb",
|
|
7
7
|
"license": "MIT",
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"kolorist": "^1.8.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"test": "
|
|
46
|
+
"test": "node --test test/*.test.js",
|
|
47
|
+
"test:quick": "./scripts/test.sh",
|
|
48
|
+
"test:smoke": "node scripts/smoke.js",
|
|
47
49
|
"push": "./scripts/publish.sh",
|
|
48
50
|
"dev": "node bin/index.js",
|
|
49
51
|
"changeset": "changeset",
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"@duxweb/dvha-core": "latest",
|
|
7
7
|
"@duxweb/dvha-naiveui": "latest",
|
|
8
8
|
"@duxweb/dvha-pro": "latest",
|
|
9
|
-
"naive-ui": "^2.
|
|
10
|
-
"vue": "^3.5.
|
|
11
|
-
"vue-router": "^4.6.
|
|
9
|
+
"naive-ui": "^2.44.1",
|
|
10
|
+
"vue": "^3.5.31",
|
|
11
|
+
"vue-router": "^4.6.4"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {},
|
|
14
14
|
"excludeDependencies": [
|