@ctzy-web-client/create-web-client 1.0.6 → 1.0.8
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/create-web-client.js +225 -169
- package/bin/utils/index.js +105 -73
- package/lib/download.js +184 -9
- package/lib/generator.js +142 -9
- package/package.json +30 -30
- package/templates/qiankun-subapp-vue-template/jsconfig.json +1 -1
- package/templates/qiankun-subapp-vue-template/mocks/test.js +1 -0
- package/templates/qiankun-subapp-vue-template/package.json +2 -1
- package/templates/qiankun-subapp-vue-template/src/interceptors/AppRequestInterceptors.js +2 -1
- package/templates/qiankun-subapp-vue-template/src/interceptors/AppRouterInterceptors.js +2 -1
- package/templates/qiankun-subapp-vue-template/src/main.js +2 -1
- package/templates/qiankun-subapp-vue-template/src/models/TestDataModel.js +2 -1
- package/templates/qiankun-subapp-vue-template/src/pages/form/index.vue +3 -2
- package/templates/qiankun-subapp-vue-template/src/pages/home/index.vue +2 -1
- package/templates/qiankun-subapp-vue-template/src/services/TestServices.js +2 -1
- package/templates/qiankun-subapp-vue-template/vite.config.ts +1 -1
- package/templates/qiankun-vue-template/jsconfig.json +1 -0
- package/templates/qiankun-vue-template/package.json +2 -1
- package/templates/qiankun-vue-template/src/main.js +3 -2
- package/templates/qiankun-vue-template/src/pages/app/index.vue +2 -1
- package/templates/qiankun-vue-template/src/services/ApplicaitionService.js +1 -0
- package/templates/qiankun-vue-template/src/services/UserService.js +1 -0
- package/templates/web-client-vue-template/package.json +1 -0
- package/lib/download2.js +0 -129
- package/lib/generator2.js +0 -80
package/bin/create-web-client.js
CHANGED
|
@@ -1,169 +1,225 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
name:
|
|
27
|
-
display:
|
|
28
|
-
color:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
name:
|
|
32
|
-
display:
|
|
33
|
-
color:
|
|
34
|
-
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
// import { fileURLToPath } from 'url';
|
|
4
|
+
import minimist from 'minimist';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import { blue, green, red, reset, yellow } from 'kolorist';
|
|
7
|
+
import {
|
|
8
|
+
formatTargetDir,
|
|
9
|
+
copy,
|
|
10
|
+
isValidPackageName,
|
|
11
|
+
toValidPackageName,
|
|
12
|
+
isEmpty,
|
|
13
|
+
emptyDir,
|
|
14
|
+
pkgFromUserAgent,
|
|
15
|
+
} from './utils/index.js';
|
|
16
|
+
|
|
17
|
+
//参数列表
|
|
18
|
+
const argv = minimist(process.argv.slice(2), { string: ['_'] });
|
|
19
|
+
|
|
20
|
+
//命令行
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
|
|
23
|
+
//模板列表
|
|
24
|
+
const templates = [
|
|
25
|
+
{
|
|
26
|
+
name: 'web-base-client-vue',
|
|
27
|
+
display: '单体web客户端应用(web-client-app)',
|
|
28
|
+
color: yellow,
|
|
29
|
+
// variants: [
|
|
30
|
+
// {
|
|
31
|
+
// name: 'vue-app',
|
|
32
|
+
// display: 'JavaScript',
|
|
33
|
+
// color: yellow
|
|
34
|
+
// }
|
|
35
|
+
// ]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'qiankun-subapp-vue',
|
|
39
|
+
display: 'VUE版本微前端子项目',
|
|
40
|
+
color: blue,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'qiankun-vue',
|
|
44
|
+
display: '乾坤+VUE基座项目',
|
|
45
|
+
color: green,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
//模板名称
|
|
49
|
+
const templateNames = templates
|
|
50
|
+
.map((f) => (f.variants && f.variants.map((v) => v.name)) || [f.name])
|
|
51
|
+
.reduce((a, b) => a.concat(b), []);
|
|
52
|
+
//默认项目名称
|
|
53
|
+
const defaultTargetDir = 'web-client-app';
|
|
54
|
+
//renameFiles
|
|
55
|
+
const renameFiles = {
|
|
56
|
+
_gitignore: '.gitignore',
|
|
57
|
+
};
|
|
58
|
+
//初始化
|
|
59
|
+
async function init() {
|
|
60
|
+
const argTargetDir = formatTargetDir(argv._[0]);
|
|
61
|
+
|
|
62
|
+
const argTemplate = argv.template || argv.t;
|
|
63
|
+
|
|
64
|
+
let targetDir = argTargetDir || defaultTargetDir;
|
|
65
|
+
|
|
66
|
+
//获取项目名称
|
|
67
|
+
const getProjectName = () =>
|
|
68
|
+
targetDir === '.' ? path.basename(path.resolve()) : targetDir;
|
|
69
|
+
|
|
70
|
+
let result;
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
result = await prompts(
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
type: argTargetDir ? null : 'text',
|
|
77
|
+
name: 'projectName',
|
|
78
|
+
message: reset('Project name:'),
|
|
79
|
+
initial: defaultTargetDir,
|
|
80
|
+
onState: (state) => {
|
|
81
|
+
targetDir = formatTargetDir(state.value) || defaultTargetDir;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: () =>
|
|
86
|
+
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
|
|
87
|
+
name: 'overwrite',
|
|
88
|
+
message: () =>
|
|
89
|
+
(targetDir === '.'
|
|
90
|
+
? 'Current directory'
|
|
91
|
+
: `Target directory "${targetDir}"`) +
|
|
92
|
+
` is not empty. Remove existing files and continue?`,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
type: (_, { overwrite }) => {
|
|
96
|
+
if (overwrite === false) {
|
|
97
|
+
throw new Error(red('✖') + ' Operation cancelled');
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
},
|
|
101
|
+
name: 'overwriteChecker',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: () => (isValidPackageName(getProjectName()) ? null : 'text'),
|
|
105
|
+
name: 'packageName',
|
|
106
|
+
message: reset('Package name:'),
|
|
107
|
+
initial: () => toValidPackageName(getProjectName()),
|
|
108
|
+
validate: (dir) =>
|
|
109
|
+
isValidPackageName(dir) || 'Invalid package.json name',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type:
|
|
113
|
+
argTemplate && templateNames.includes(argTemplate)
|
|
114
|
+
? null
|
|
115
|
+
: 'select',
|
|
116
|
+
name: 'template',
|
|
117
|
+
message:
|
|
118
|
+
typeof argTemplate === 'string' &&
|
|
119
|
+
!templateNames.includes(argTemplate)
|
|
120
|
+
? reset(
|
|
121
|
+
`"${argTemplate}" isn't a valid template. Please choose from below: `
|
|
122
|
+
)
|
|
123
|
+
: reset('Select a template:'),
|
|
124
|
+
initial: 0,
|
|
125
|
+
choices: templates.map((template) => {
|
|
126
|
+
const color = template.color;
|
|
127
|
+
return {
|
|
128
|
+
title: color(template.display || template.name),
|
|
129
|
+
value: template,
|
|
130
|
+
};
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
type: (template) => (template && template.variants ? 'select' : null),
|
|
135
|
+
name: 'variant',
|
|
136
|
+
message: reset('Select a variant:'),
|
|
137
|
+
choices: (template) =>
|
|
138
|
+
template.variants.map((variant) => {
|
|
139
|
+
const variantColor = variant.color;
|
|
140
|
+
return {
|
|
141
|
+
title: variantColor(variant.display || variant.name),
|
|
142
|
+
value: variant.name,
|
|
143
|
+
};
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
{
|
|
148
|
+
onCancel: () => {
|
|
149
|
+
throw new Error(red('✖') + ' Operation cancelled');
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
} catch (cancelled) {
|
|
154
|
+
console.log(cancelled.message);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// user choice associated with prompts
|
|
159
|
+
const { template, overwrite, packageName, variant } = result;
|
|
160
|
+
|
|
161
|
+
const root = path.join(cwd, targetDir);
|
|
162
|
+
|
|
163
|
+
if (overwrite) {
|
|
164
|
+
emptyDir(root);
|
|
165
|
+
} else if (!fs.existsSync(root)) {
|
|
166
|
+
fs.mkdirSync(root, { recursive: true });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// determine template
|
|
170
|
+
const installTemplate = variant || (template && template.name) || argTemplate;
|
|
171
|
+
|
|
172
|
+
const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
|
|
173
|
+
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
174
|
+
|
|
175
|
+
// 该提示不输出
|
|
176
|
+
// console.log(`\nScaffolding project in ${root}...`)
|
|
177
|
+
|
|
178
|
+
const templateDir = path.resolve(
|
|
179
|
+
// fileURLToPath(__dirname),
|
|
180
|
+
__dirname,
|
|
181
|
+
'../templates',
|
|
182
|
+
`${installTemplate}-template`
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const write = (file, content) => {
|
|
186
|
+
const targetPath = path.join(root, renameFiles[file] ?? file);
|
|
187
|
+
if (content) {
|
|
188
|
+
fs.writeFileSync(targetPath, content);
|
|
189
|
+
} else {
|
|
190
|
+
copy(path.join(templateDir, file), targetPath);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const files = fs.readdirSync(templateDir);
|
|
195
|
+
for (const file of files.filter((f) => f !== 'package.json')) {
|
|
196
|
+
write(file);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const pkg = JSON.parse(
|
|
200
|
+
fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8')
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
pkg.name = packageName || getProjectName();
|
|
204
|
+
|
|
205
|
+
write('package.json', JSON.stringify(pkg, null, 2));
|
|
206
|
+
|
|
207
|
+
console.log(`\nDone. Now run:\n`);
|
|
208
|
+
if (root !== cwd) {
|
|
209
|
+
console.log(` cd ${path.relative(cwd, root)}`);
|
|
210
|
+
}
|
|
211
|
+
switch (pkgManager) {
|
|
212
|
+
case 'yarn':
|
|
213
|
+
console.log(' yarn');
|
|
214
|
+
console.log(' yarn dev');
|
|
215
|
+
break;
|
|
216
|
+
default:
|
|
217
|
+
console.log(` ${pkgManager} install`);
|
|
218
|
+
console.log(` ${pkgManager} run dev`);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
console.log();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//初始化
|
|
225
|
+
init().catch((e) => console.error(e));
|
package/bin/utils/index.js
CHANGED
|
@@ -1,73 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* 格式化目标目录
|
|
5
|
+
* @param {*} targetDir
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const formatTargetDir = function formatTargetDir(targetDir) {
|
|
9
|
+
return targetDir?.trim().replace(/\/+$/g, '');
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 拷贝
|
|
14
|
+
* @param {*} src
|
|
15
|
+
* @param {*} dest
|
|
16
|
+
*/
|
|
17
|
+
export const copy = function copy(src, dest) {
|
|
18
|
+
const stat = fs.statSync(src);
|
|
19
|
+
if (stat.isDirectory()) {
|
|
20
|
+
copyDir(src, dest);
|
|
21
|
+
} else {
|
|
22
|
+
fs.copyFileSync(src, dest);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 检测项目名称是否有效
|
|
28
|
+
* @param {*} projectName
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export const isValidPackageName = function isValidPackageName(projectName) {
|
|
32
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
33
|
+
projectName
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 将项目名称处理成有效的名称
|
|
39
|
+
* @param {*} projectName
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export const toValidPackageName = function toValidPackageName(projectName) {
|
|
43
|
+
return projectName
|
|
44
|
+
.trim()
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.replace(/\s+/g, '-')
|
|
47
|
+
.replace(/^[._]/, '')
|
|
48
|
+
.replace(/[^a-z0-9-~]+/g, '-');
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 拷贝目录
|
|
53
|
+
* @param {*} srcDir
|
|
54
|
+
* @param {*} destDir
|
|
55
|
+
*/
|
|
56
|
+
export const copyDir = function copyDir(srcDir, destDir) {
|
|
57
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
58
|
+
for (const file of fs.readdirSync(srcDir)) {
|
|
59
|
+
const srcFile = path.resolve(srcDir, file);
|
|
60
|
+
const destFile = path.resolve(destDir, file);
|
|
61
|
+
copy(srcFile, destFile);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 是否是空目录
|
|
67
|
+
* @param {*} path
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
export const isEmpty = function isEmpty(path) {
|
|
71
|
+
const files = fs.readdirSync(path);
|
|
72
|
+
return files.length === 0 || (files.length === 1 && files[0] === '.git');
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 是否是空目录
|
|
77
|
+
* @param {*} dir
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
export const emptyDir = function emptyDir(dir) {
|
|
81
|
+
if (!fs.existsSync(dir)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
for (const file of fs.readdirSync(dir)) {
|
|
85
|
+
if (file === '.git') {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 更新packagejson
|
|
94
|
+
* @param {*} userAgent
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
export const pkgFromUserAgent = function pkgFromUserAgent(userAgent) {
|
|
98
|
+
if (!userAgent) return undefined;
|
|
99
|
+
const pkgSpec = userAgent.split(' ')[0];
|
|
100
|
+
const pkgSpecArr = pkgSpec.split('/');
|
|
101
|
+
return {
|
|
102
|
+
name: pkgSpecArr[0],
|
|
103
|
+
version: pkgSpecArr[1],
|
|
104
|
+
};
|
|
105
|
+
};
|