@4399ywkf/cli 0.0.1 → 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/bin/cli.js +62 -33
- package/package.json +2 -3
package/bin/cli.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const program = require("commander")
|
|
3
3
|
const inquirer = require("inquirer")
|
|
4
4
|
const path = require("path")
|
|
5
|
-
const downloadGitRepo = require('download-git-repo')
|
|
6
5
|
const ora = require('ora') // 引入ora
|
|
7
6
|
const fs = require('fs-extra')
|
|
8
7
|
const { exec } = require('child_process');
|
|
@@ -11,7 +10,6 @@ const { exec } = require('child_process');
|
|
|
11
10
|
const { getGitReposList } = require('./api.js')
|
|
12
11
|
const package = require("../package.json")
|
|
13
12
|
|
|
14
|
-
|
|
15
13
|
function cloneRepository(repoUrl, destination) {
|
|
16
14
|
return new Promise((resolve, reject) => {
|
|
17
15
|
const command = `git clone ${repoUrl} ${destination}`;
|
|
@@ -25,7 +23,6 @@ function cloneRepository(repoUrl, destination) {
|
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
29
26
|
program
|
|
30
27
|
.command("create [projectName]")
|
|
31
28
|
.description("创建模版")
|
|
@@ -34,21 +31,41 @@ program
|
|
|
34
31
|
const getRepoLoading = ora('获取模版列表...')
|
|
35
32
|
getRepoLoading.start()
|
|
36
33
|
// const templates = await getGitReposList('Emma-Alpha')
|
|
37
|
-
const templates =
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const templates = {
|
|
35
|
+
webpack: {
|
|
36
|
+
main: [
|
|
37
|
+
{
|
|
38
|
+
value: "https://ywgit.gz4399.com/ywkf/webpack-mainApplicate_demo.git",
|
|
39
|
+
name: "webpack-mainApplicate_demo"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
sub: [
|
|
43
|
+
{
|
|
44
|
+
value: "https://ywgit.gz4399.com/ywkf/webpack-subApplicate_demo.git",
|
|
45
|
+
name: "webpack-subApplicate_demo"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
vite: {
|
|
50
|
+
main: [
|
|
51
|
+
{
|
|
52
|
+
value: "https://ywgit.gz4399.com/ywkf/vite-mainApplicate_demo.git",
|
|
53
|
+
name: "vite-mainApplicate_demo"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
sub: [
|
|
57
|
+
{
|
|
58
|
+
value: "https://ywgit.gz4399.com/ywkf/vite-subApplicate_demo",
|
|
59
|
+
name: "vite-subApplicate_demo"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
41
62
|
}
|
|
42
|
-
|
|
63
|
+
}
|
|
43
64
|
|
|
44
65
|
getRepoLoading.succeed('获取模版列表成功!')
|
|
45
|
-
// 1. 从模版列表中找到对应的模版
|
|
46
|
-
let project = templates.find(template => template.name === options.template)
|
|
47
|
-
// 2. 如果匹配到模版就赋值,没有匹配到就是undefined
|
|
48
|
-
let projectTemplate = project ? project.value : undefined
|
|
49
66
|
|
|
50
|
-
//
|
|
51
|
-
if(!projectName) {
|
|
67
|
+
// 1. 如果用户没有传入名称就交互式输入
|
|
68
|
+
if (!projectName) {
|
|
52
69
|
const { name } = await inquirer.prompt({
|
|
53
70
|
type: "input",
|
|
54
71
|
name: "name",
|
|
@@ -58,22 +75,45 @@ program
|
|
|
58
75
|
}
|
|
59
76
|
console.log('项目名称:', projectName)
|
|
60
77
|
|
|
61
|
-
//
|
|
62
|
-
|
|
78
|
+
// 2. 选择工具类型
|
|
79
|
+
const { toolType } = await inquirer.prompt({
|
|
80
|
+
type: 'list',
|
|
81
|
+
name: 'toolType',
|
|
82
|
+
message: '请选择工具类型:',
|
|
83
|
+
choices: ['webpack', 'vite']
|
|
84
|
+
})
|
|
85
|
+
console.log('工具类型:', toolType)
|
|
86
|
+
|
|
87
|
+
// 3. 选择应用方向
|
|
88
|
+
const { appDirection } = await inquirer.prompt({
|
|
89
|
+
type: 'list',
|
|
90
|
+
name: 'appDirection',
|
|
91
|
+
message: '请选择应用方向:',
|
|
92
|
+
choices: ['main', 'sub']
|
|
93
|
+
})
|
|
94
|
+
console.log('应用方向:', appDirection)
|
|
95
|
+
|
|
96
|
+
// 4. 选择模版
|
|
97
|
+
let projectTemplate;
|
|
98
|
+
if (options.template) {
|
|
99
|
+
projectTemplate = templates[toolType][appDirection].find(template => template.name === options.template)?.value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!projectTemplate) {
|
|
63
103
|
const { template } = await inquirer.prompt({
|
|
64
104
|
type: 'list',
|
|
65
105
|
name: 'template',
|
|
66
106
|
message: '请选择模版:',
|
|
67
|
-
choices: templates
|
|
107
|
+
choices: templates[toolType][appDirection]
|
|
68
108
|
})
|
|
69
|
-
projectTemplate = template //
|
|
109
|
+
projectTemplate = template; // 赋值选择的项目模板
|
|
70
110
|
}
|
|
71
111
|
console.log('模版:', projectTemplate)
|
|
72
112
|
|
|
73
113
|
// 获取目标文件夹路径
|
|
74
114
|
const dest = path.join(process.cwd(), projectName)
|
|
75
115
|
// 判断文件夹是否存在,存在就交互询问用户是否覆盖
|
|
76
|
-
if(fs.existsSync(dest)) {
|
|
116
|
+
if (fs.existsSync(dest)) {
|
|
77
117
|
const { force } = await inquirer.prompt({
|
|
78
118
|
type: 'confirm',
|
|
79
119
|
name: 'force',
|
|
@@ -91,25 +131,14 @@ program
|
|
|
91
131
|
const result = await cloneRepository(projectTemplate, dest);
|
|
92
132
|
loading.succeed('创建模版成功!') // 成功loading
|
|
93
133
|
console.log(`\ncd ${projectName}`)
|
|
94
|
-
console.log('
|
|
95
|
-
console.log('
|
|
134
|
+
console.log('pnpm i')
|
|
135
|
+
console.log('pnpm start\n')
|
|
96
136
|
} catch (error) {
|
|
97
137
|
loading.fail('创建模版失败:' + error) // 失败loading
|
|
98
138
|
}
|
|
99
|
-
|
|
100
|
-
// downloadGitRepo(projectTemplate, dest, (err) => {
|
|
101
|
-
// if (err) {
|
|
102
|
-
// loading.fail('创建模版失败:' + err) // 失败loading
|
|
103
|
-
// } else {
|
|
104
|
-
// loading.succeed('创建模版成功!') // 成功loading
|
|
105
|
-
// console.log(`\ncd ${projectName}`)
|
|
106
|
-
// console.log('npm i')
|
|
107
|
-
// console.log('npm start\n')
|
|
108
|
-
// }
|
|
109
|
-
// })
|
|
110
139
|
})
|
|
111
140
|
|
|
112
141
|
// 定义当前版本
|
|
113
142
|
program.version(`v${package.version}`)
|
|
114
|
-
program.on('--help', () => {}) // 添加--help
|
|
143
|
+
program.on('--help', () => { }) // 添加--help
|
|
115
144
|
program.parse(process.argv)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4399ywkf/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "运维开发部脚手架",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
|
-
"type": "git"
|
|
17
|
-
"url": "git+https://github.com/Emma-Alpha/ywkf-cli.git"
|
|
16
|
+
"type": "git"
|
|
18
17
|
},
|
|
19
18
|
"keywords": [],
|
|
20
19
|
"author": "",
|