@ctzy-web-client/create-web-client 1.0.8 → 1.0.20
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 +169 -225
- package/bin/utils/index.js +73 -105
- package/lib/download.js +9 -184
- package/lib/download2.js +129 -0
- package/lib/generator.js +9 -142
- package/lib/generator2.js +80 -0
- package/package.json +1 -1
package/bin/create-web-client.js
CHANGED
|
@@ -1,225 +1,169 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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));
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var minimist = require('minimist');
|
|
6
|
+
var prompts = require('prompts');
|
|
7
|
+
var kolorist = require('kolorist');
|
|
8
|
+
var index = require('./utils/index.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
13
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
14
|
+
var minimist__default = /*#__PURE__*/_interopDefaultLegacy(minimist);
|
|
15
|
+
var prompts__default = /*#__PURE__*/_interopDefaultLegacy(prompts);
|
|
16
|
+
|
|
17
|
+
const argv = minimist__default["default"](process.argv.slice(2), { string: ["_"] });
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const templates = [
|
|
20
|
+
{
|
|
21
|
+
name: "web-base-client-vue",
|
|
22
|
+
display: "\u5355\u4F53web\u5BA2\u6237\u7AEF\u5E94\u7528(web-client-app)",
|
|
23
|
+
color: kolorist.yellow
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "qiankun-subapp-vue",
|
|
27
|
+
display: "VUE\u7248\u672C\u5FAE\u524D\u7AEF\u5B50\u9879\u76EE",
|
|
28
|
+
color: kolorist.blue
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "qiankun-vue",
|
|
32
|
+
display: "\u4E7E\u5764+VUE\u57FA\u5EA7\u9879\u76EE",
|
|
33
|
+
color: kolorist.green
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
const templateNames = templates.map((f) => f.variants && f.variants.map((v) => v.name) || [f.name]).reduce((a, b) => a.concat(b), []);
|
|
37
|
+
const defaultTargetDir = "web-client-app";
|
|
38
|
+
const renameFiles = {
|
|
39
|
+
_gitignore: ".gitignore"
|
|
40
|
+
};
|
|
41
|
+
async function init() {
|
|
42
|
+
const argTargetDir = index.formatTargetDir(argv._[0]);
|
|
43
|
+
const argTemplate = argv.template || argv.t;
|
|
44
|
+
let targetDir = argTargetDir || defaultTargetDir;
|
|
45
|
+
const getProjectName = () => targetDir === "." ? path__default["default"].basename(path__default["default"].resolve()) : targetDir;
|
|
46
|
+
let result;
|
|
47
|
+
try {
|
|
48
|
+
result = await prompts__default["default"](
|
|
49
|
+
[
|
|
50
|
+
{
|
|
51
|
+
type: argTargetDir ? null : "text",
|
|
52
|
+
name: "projectName",
|
|
53
|
+
message: kolorist.reset("Project name:"),
|
|
54
|
+
initial: defaultTargetDir,
|
|
55
|
+
onState: (state) => {
|
|
56
|
+
targetDir = index.formatTargetDir(state.value) || defaultTargetDir;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: () => !fs__default["default"].existsSync(targetDir) || index.isEmpty(targetDir) ? null : "confirm",
|
|
61
|
+
name: "overwrite",
|
|
62
|
+
message: () => (targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`) + ` is not empty. Remove existing files and continue?`
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: (_, { overwrite: overwrite2 }) => {
|
|
66
|
+
if (overwrite2 === false) {
|
|
67
|
+
throw new Error(kolorist.red("\u2716") + " Operation cancelled");
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
},
|
|
71
|
+
name: "overwriteChecker"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: () => index.isValidPackageName(getProjectName()) ? null : "text",
|
|
75
|
+
name: "packageName",
|
|
76
|
+
message: kolorist.reset("Package name:"),
|
|
77
|
+
initial: () => index.toValidPackageName(getProjectName()),
|
|
78
|
+
validate: (dir) => index.isValidPackageName(dir) || "Invalid package.json name"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: argTemplate && templateNames.includes(argTemplate) ? null : "select",
|
|
82
|
+
name: "template",
|
|
83
|
+
message: typeof argTemplate === "string" && !templateNames.includes(argTemplate) ? kolorist.reset(
|
|
84
|
+
`"${argTemplate}" isn't a valid template. Please choose from below: `
|
|
85
|
+
) : kolorist.reset("Select a template:"),
|
|
86
|
+
initial: 0,
|
|
87
|
+
choices: templates.map((template2) => {
|
|
88
|
+
const color = template2.color;
|
|
89
|
+
return {
|
|
90
|
+
title: color(template2.display || template2.name),
|
|
91
|
+
value: template2
|
|
92
|
+
};
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: (template2) => template2 && template2.variants ? "select" : null,
|
|
97
|
+
name: "variant",
|
|
98
|
+
message: kolorist.reset("Select a variant:"),
|
|
99
|
+
choices: (template2) => template2.variants.map((variant2) => {
|
|
100
|
+
const variantColor = variant2.color;
|
|
101
|
+
return {
|
|
102
|
+
title: variantColor(variant2.display || variant2.name),
|
|
103
|
+
value: variant2.name
|
|
104
|
+
};
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
{
|
|
109
|
+
onCancel: () => {
|
|
110
|
+
throw new Error(kolorist.red("\u2716") + " Operation cancelled");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
} catch (cancelled) {
|
|
115
|
+
console.log(cancelled.message);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const { template, overwrite, packageName, variant } = result;
|
|
119
|
+
const root = path__default["default"].join(cwd, targetDir);
|
|
120
|
+
if (overwrite) {
|
|
121
|
+
index.emptyDir(root);
|
|
122
|
+
} else if (!fs__default["default"].existsSync(root)) {
|
|
123
|
+
fs__default["default"].mkdirSync(root, { recursive: true });
|
|
124
|
+
}
|
|
125
|
+
const installTemplate = variant || template && template.name || argTemplate;
|
|
126
|
+
const pkgInfo = index.pkgFromUserAgent(process.env.npm_config_user_agent);
|
|
127
|
+
const pkgManager = pkgInfo ? pkgInfo.name : "npm";
|
|
128
|
+
const templateDir = path__default["default"].resolve(
|
|
129
|
+
__dirname,
|
|
130
|
+
"../templates",
|
|
131
|
+
`${installTemplate}-template`
|
|
132
|
+
);
|
|
133
|
+
const write = (file, content) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const targetPath = path__default["default"].join(root, (_a = renameFiles[file]) != null ? _a : file);
|
|
136
|
+
if (content) {
|
|
137
|
+
fs__default["default"].writeFileSync(targetPath, content);
|
|
138
|
+
} else {
|
|
139
|
+
index.copy(path__default["default"].join(templateDir, file), targetPath);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const files = fs__default["default"].readdirSync(templateDir);
|
|
143
|
+
for (const file of files.filter((f) => f !== "package.json")) {
|
|
144
|
+
write(file);
|
|
145
|
+
}
|
|
146
|
+
const pkg = JSON.parse(
|
|
147
|
+
fs__default["default"].readFileSync(path__default["default"].join(templateDir, `package.json`), "utf-8")
|
|
148
|
+
);
|
|
149
|
+
pkg.name = packageName || getProjectName();
|
|
150
|
+
write("package.json", JSON.stringify(pkg, null, 2));
|
|
151
|
+
console.log(`
|
|
152
|
+
Done. Now run:
|
|
153
|
+
`);
|
|
154
|
+
if (root !== cwd) {
|
|
155
|
+
console.log(` cd ${path__default["default"].relative(cwd, root)}`);
|
|
156
|
+
}
|
|
157
|
+
switch (pkgManager) {
|
|
158
|
+
case "yarn":
|
|
159
|
+
console.log(" yarn");
|
|
160
|
+
console.log(" yarn dev");
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
console.log(` ${pkgManager} install`);
|
|
164
|
+
console.log(` ${pkgManager} run dev`);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
console.log();
|
|
168
|
+
}
|
|
169
|
+
init().catch((e) => console.error(e));
|
package/bin/utils/index.js
CHANGED
|
@@ -1,105 +1,73 @@
|
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
12
|
+
|
|
13
|
+
const formatTargetDir = function formatTargetDir2(targetDir) {
|
|
14
|
+
return targetDir == null ? void 0 : targetDir.trim().replace(/\/+$/g, "");
|
|
15
|
+
};
|
|
16
|
+
const copy = function copy2(src, dest) {
|
|
17
|
+
const stat = fs__default["default"].statSync(src);
|
|
18
|
+
if (stat.isDirectory()) {
|
|
19
|
+
copyDir(src, dest);
|
|
20
|
+
} else {
|
|
21
|
+
fs__default["default"].copyFileSync(src, dest);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const isValidPackageName = function isValidPackageName2(projectName) {
|
|
25
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
26
|
+
projectName
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
const toValidPackageName = function toValidPackageName2(projectName) {
|
|
30
|
+
return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
|
|
31
|
+
};
|
|
32
|
+
const copyDir = function copyDir2(srcDir, destDir) {
|
|
33
|
+
fs__default["default"].mkdirSync(destDir, { recursive: true });
|
|
34
|
+
for (const file of fs__default["default"].readdirSync(srcDir)) {
|
|
35
|
+
const srcFile = path__default["default"].resolve(srcDir, file);
|
|
36
|
+
const destFile = path__default["default"].resolve(destDir, file);
|
|
37
|
+
copy(srcFile, destFile);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const isEmpty = function isEmpty2(path2) {
|
|
41
|
+
const files = fs__default["default"].readdirSync(path2);
|
|
42
|
+
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
43
|
+
};
|
|
44
|
+
const emptyDir = function emptyDir2(dir) {
|
|
45
|
+
if (!fs__default["default"].existsSync(dir)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (const file of fs__default["default"].readdirSync(dir)) {
|
|
49
|
+
if (file === ".git") {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
fs__default["default"].rmSync(path__default["default"].resolve(dir, file), { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const pkgFromUserAgent = function pkgFromUserAgent2(userAgent) {
|
|
56
|
+
if (!userAgent)
|
|
57
|
+
return void 0;
|
|
58
|
+
const pkgSpec = userAgent.split(" ")[0];
|
|
59
|
+
const pkgSpecArr = pkgSpec.split("/");
|
|
60
|
+
return {
|
|
61
|
+
name: pkgSpecArr[0],
|
|
62
|
+
version: pkgSpecArr[1]
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.copy = copy;
|
|
67
|
+
exports.copyDir = copyDir;
|
|
68
|
+
exports.emptyDir = emptyDir;
|
|
69
|
+
exports.formatTargetDir = formatTargetDir;
|
|
70
|
+
exports.isEmpty = isEmpty;
|
|
71
|
+
exports.isValidPackageName = isValidPackageName;
|
|
72
|
+
exports.pkgFromUserAgent = pkgFromUserAgent;
|
|
73
|
+
exports.toValidPackageName = toValidPackageName;
|
package/lib/download.js
CHANGED
|
@@ -1,184 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Download `repo` to `dest` and callback `fn(err)`.
|
|
13
|
-
*
|
|
14
|
-
* @param {String} repo
|
|
15
|
-
* @param {String} dest
|
|
16
|
-
* @param {Object} opts
|
|
17
|
-
* @param {Function} fn
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function download(repo, dest, opts, fn) {
|
|
21
|
-
if (typeof opts === 'function') {
|
|
22
|
-
fn = opts;
|
|
23
|
-
opts = null;
|
|
24
|
-
}
|
|
25
|
-
opts = opts || {};
|
|
26
|
-
var clone = opts.clone || false;
|
|
27
|
-
|
|
28
|
-
repo = normalize(repo);
|
|
29
|
-
|
|
30
|
-
var url = repo.url || getUrl(repo, clone);
|
|
31
|
-
|
|
32
|
-
if (clone) {
|
|
33
|
-
gitclone(
|
|
34
|
-
url,
|
|
35
|
-
dest,
|
|
36
|
-
{
|
|
37
|
-
checkout: repo.checkout,
|
|
38
|
-
shallow: repo.checkout === 'master',
|
|
39
|
-
},
|
|
40
|
-
function (err) {
|
|
41
|
-
if (err === undefined) {
|
|
42
|
-
rm(dest + '/.git');
|
|
43
|
-
fn();
|
|
44
|
-
} else {
|
|
45
|
-
fn(err);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
} else {
|
|
50
|
-
downloadUrl(url, dest, {
|
|
51
|
-
extract: true,
|
|
52
|
-
strip: 1,
|
|
53
|
-
mode: '666',
|
|
54
|
-
headers: {
|
|
55
|
-
accept: 'application/zip',
|
|
56
|
-
},
|
|
57
|
-
})
|
|
58
|
-
.then(function (data) {
|
|
59
|
-
fn();
|
|
60
|
-
})
|
|
61
|
-
.catch(function (err) {
|
|
62
|
-
fn(err);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Normalize a repo string.
|
|
69
|
-
*
|
|
70
|
-
* @param {String} repo
|
|
71
|
-
* @return {Object}
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
function normalize(repo) {
|
|
75
|
-
var regex = /^(?:(direct):([^#]+)(?:#(.+))?)$/;
|
|
76
|
-
var match = regex.exec(repo);
|
|
77
|
-
|
|
78
|
-
if (match) {
|
|
79
|
-
var url = match[2];
|
|
80
|
-
var checkout = match[3] || 'master';
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
type: 'direct',
|
|
84
|
-
url: url,
|
|
85
|
-
checkout: checkout,
|
|
86
|
-
};
|
|
87
|
-
} else {
|
|
88
|
-
regex =
|
|
89
|
-
/^(?:(github|gitlab|bitbucket):)?(?:(.+):)?([^\/]+)\/([^#]+)(?:#(.+))?$/;
|
|
90
|
-
match = regex.exec(repo);
|
|
91
|
-
var type = match[1] || 'baswebapp';
|
|
92
|
-
var origin = match[2] || null;
|
|
93
|
-
var owner = match[3];
|
|
94
|
-
var name = match[4];
|
|
95
|
-
var checkout = match[5] || 'master';
|
|
96
|
-
|
|
97
|
-
if (origin == null) {
|
|
98
|
-
if (type === 'github') origin = 'github.com';
|
|
99
|
-
else if (type === 'gitlab') origin = 'gitlab.com';
|
|
100
|
-
else if (type === 'bitbucket') origin = 'bitbucket.com';
|
|
101
|
-
else if (type === 'baswebapp') origin = 'gitlab.baswebapp.cn';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
type: type,
|
|
106
|
-
origin: origin,
|
|
107
|
-
owner: owner,
|
|
108
|
-
name: name,
|
|
109
|
-
checkout: checkout,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Adds protocol to url in none specified
|
|
116
|
-
*
|
|
117
|
-
* @param {String} url
|
|
118
|
-
* @return {String}
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
function addProtocol(origin, clone) {
|
|
122
|
-
if (!/^(f|ht)tps?:\/\//i.test(origin)) {
|
|
123
|
-
if (clone) origin = 'git@' + origin;
|
|
124
|
-
else origin = 'https://' + origin;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return origin;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Return a zip or git url for a given `repo`.
|
|
132
|
-
*
|
|
133
|
-
* @param {Object} repo
|
|
134
|
-
* @return {String}
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
function getUrl(repo, clone) {
|
|
138
|
-
var url;
|
|
139
|
-
|
|
140
|
-
// Get origin with protocol and add trailing slash or colon (for ssh)
|
|
141
|
-
var origin = addProtocol(repo.origin, clone);
|
|
142
|
-
if (/^git\@/i.test(origin)) origin = origin + ':';
|
|
143
|
-
else origin = origin + '/';
|
|
144
|
-
|
|
145
|
-
// Build url
|
|
146
|
-
if (clone) {
|
|
147
|
-
url = origin + repo.owner + '/' + repo.name + '.git';
|
|
148
|
-
} else {
|
|
149
|
-
if (repo.type === 'github')
|
|
150
|
-
url =
|
|
151
|
-
origin +
|
|
152
|
-
repo.owner +
|
|
153
|
-
'/' +
|
|
154
|
-
repo.name +
|
|
155
|
-
'/archive/' +
|
|
156
|
-
repo.checkout +
|
|
157
|
-
'.zip';
|
|
158
|
-
else if (repo.type === 'gitlab')
|
|
159
|
-
url =
|
|
160
|
-
origin +
|
|
161
|
-
repo.owner +
|
|
162
|
-
'/' +
|
|
163
|
-
repo.name +
|
|
164
|
-
'/repository/archive.zip?ref=' +
|
|
165
|
-
repo.checkout;
|
|
166
|
-
else if (repo.type === 'baswebapp')
|
|
167
|
-
url =
|
|
168
|
-
'http://gitlab.baswebapp.cn/bwa//' +
|
|
169
|
-
repo.name +
|
|
170
|
-
'/repository/archive.zip?ref=' +
|
|
171
|
-
repo.checkout;
|
|
172
|
-
else if (repo.type === 'bitbucket')
|
|
173
|
-
url =
|
|
174
|
-
origin +
|
|
175
|
-
repo.owner +
|
|
176
|
-
'/' +
|
|
177
|
-
repo.name +
|
|
178
|
-
'/get/' +
|
|
179
|
-
repo.checkout +
|
|
180
|
-
'.zip';
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return url;
|
|
184
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var download = require('./download2.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports["default"] = download["default"];
|
package/lib/download2.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var require$$0 = require('download');
|
|
6
|
+
var require$$1 = require('git-clone');
|
|
7
|
+
var require$$2 = require('rimraf');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
12
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
13
|
+
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
14
|
+
|
|
15
|
+
var downloadUrl = require$$0__default["default"];
|
|
16
|
+
var gitclone = require$$1__default["default"];
|
|
17
|
+
var rm = require$$2__default["default"].sync;
|
|
18
|
+
var download_1 = download;
|
|
19
|
+
function download(repo, dest, opts, fn) {
|
|
20
|
+
if (typeof opts === "function") {
|
|
21
|
+
fn = opts;
|
|
22
|
+
opts = null;
|
|
23
|
+
}
|
|
24
|
+
opts = opts || {};
|
|
25
|
+
var clone = opts.clone || false;
|
|
26
|
+
repo = normalize(repo);
|
|
27
|
+
var url = repo.url || getUrl(repo, clone);
|
|
28
|
+
if (clone) {
|
|
29
|
+
gitclone(
|
|
30
|
+
url,
|
|
31
|
+
dest,
|
|
32
|
+
{
|
|
33
|
+
checkout: repo.checkout,
|
|
34
|
+
shallow: repo.checkout === "master"
|
|
35
|
+
},
|
|
36
|
+
function(err) {
|
|
37
|
+
if (err === void 0) {
|
|
38
|
+
rm(dest + "/.git");
|
|
39
|
+
fn();
|
|
40
|
+
} else {
|
|
41
|
+
fn(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
} else {
|
|
46
|
+
downloadUrl(url, dest, {
|
|
47
|
+
extract: true,
|
|
48
|
+
strip: 1,
|
|
49
|
+
mode: "666",
|
|
50
|
+
headers: {
|
|
51
|
+
accept: "application/zip"
|
|
52
|
+
}
|
|
53
|
+
}).then(function(data) {
|
|
54
|
+
fn();
|
|
55
|
+
}).catch(function(err) {
|
|
56
|
+
fn(err);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function normalize(repo) {
|
|
61
|
+
var regex = /^(?:(direct):([^#]+)(?:#(.+))?)$/;
|
|
62
|
+
var match = regex.exec(repo);
|
|
63
|
+
if (match) {
|
|
64
|
+
var url = match[2];
|
|
65
|
+
var checkout = match[3] || "master";
|
|
66
|
+
return {
|
|
67
|
+
type: "direct",
|
|
68
|
+
url,
|
|
69
|
+
checkout
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
regex = /^(?:(github|gitlab|bitbucket):)?(?:(.+):)?([^\/]+)\/([^#]+)(?:#(.+))?$/;
|
|
73
|
+
match = regex.exec(repo);
|
|
74
|
+
var type = match[1] || "baswebapp";
|
|
75
|
+
var origin = match[2] || null;
|
|
76
|
+
var owner = match[3];
|
|
77
|
+
var name = match[4];
|
|
78
|
+
var checkout = match[5] || "master";
|
|
79
|
+
if (origin == null) {
|
|
80
|
+
if (type === "github")
|
|
81
|
+
origin = "github.com";
|
|
82
|
+
else if (type === "gitlab")
|
|
83
|
+
origin = "gitlab.com";
|
|
84
|
+
else if (type === "bitbucket")
|
|
85
|
+
origin = "bitbucket.com";
|
|
86
|
+
else if (type === "baswebapp")
|
|
87
|
+
origin = "gitlab.baswebapp.cn";
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type,
|
|
91
|
+
origin,
|
|
92
|
+
owner,
|
|
93
|
+
name,
|
|
94
|
+
checkout
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function addProtocol(origin, clone) {
|
|
99
|
+
if (!/^(f|ht)tps?:\/\//i.test(origin)) {
|
|
100
|
+
if (clone)
|
|
101
|
+
origin = "git@" + origin;
|
|
102
|
+
else
|
|
103
|
+
origin = "https://" + origin;
|
|
104
|
+
}
|
|
105
|
+
return origin;
|
|
106
|
+
}
|
|
107
|
+
function getUrl(repo, clone) {
|
|
108
|
+
var url;
|
|
109
|
+
var origin = addProtocol(repo.origin, clone);
|
|
110
|
+
if (/^git\@/i.test(origin))
|
|
111
|
+
origin = origin + ":";
|
|
112
|
+
else
|
|
113
|
+
origin = origin + "/";
|
|
114
|
+
if (clone) {
|
|
115
|
+
url = origin + repo.owner + "/" + repo.name + ".git";
|
|
116
|
+
} else {
|
|
117
|
+
if (repo.type === "github")
|
|
118
|
+
url = origin + repo.owner + "/" + repo.name + "/archive/" + repo.checkout + ".zip";
|
|
119
|
+
else if (repo.type === "gitlab")
|
|
120
|
+
url = origin + repo.owner + "/" + repo.name + "/repository/archive.zip?ref=" + repo.checkout;
|
|
121
|
+
else if (repo.type === "baswebapp")
|
|
122
|
+
url = "http://gitlab.baswebapp.cn/bwa//" + repo.name + "/repository/archive.zip?ref=" + repo.checkout;
|
|
123
|
+
else if (repo.type === "bitbucket")
|
|
124
|
+
url = origin + repo.owner + "/" + repo.name + "/get/" + repo.checkout + ".zip";
|
|
125
|
+
}
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
exports["default"] = download_1;
|
package/lib/generator.js
CHANGED
|
@@ -1,142 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @param {String} dir 目录
|
|
11
|
-
* @param {*} files
|
|
12
|
-
* @param {*} base
|
|
13
|
-
* @param {*} rootOptions
|
|
14
|
-
*/
|
|
15
|
-
async function generate(dir, files, base = '', rootOptions = {}) {
|
|
16
|
-
const glob = require('glob');
|
|
17
|
-
|
|
18
|
-
glob
|
|
19
|
-
.sync('**/*', {
|
|
20
|
-
cwd: dir,
|
|
21
|
-
nodir: true,
|
|
22
|
-
})
|
|
23
|
-
.forEach((rawPath) => {
|
|
24
|
-
const sourcePath = path.resolve(dir, rawPath);
|
|
25
|
-
|
|
26
|
-
const filename = path.join(base, rawPath);
|
|
27
|
-
|
|
28
|
-
//是否是二进制文件
|
|
29
|
-
if (isBinary.sync(sourcePath)) {
|
|
30
|
-
//如果是直接返回流
|
|
31
|
-
files[filename] = fs.readFileSync(sourcePath); // return buffer
|
|
32
|
-
} else {
|
|
33
|
-
//读取文件内容
|
|
34
|
-
let content = fs.readFileSync(sourcePath, 'utf-8');
|
|
35
|
-
|
|
36
|
-
if (path.basename(filename) === 'manifest.json') {
|
|
37
|
-
content = content.replace('{{name}}', rootOptions.projectName || '');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//_aaa.js => aaa.js
|
|
41
|
-
if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
|
|
42
|
-
files[`.${filename.slice(1)}`] = content;
|
|
43
|
-
}
|
|
44
|
-
//__aaa.js => _aaa.js
|
|
45
|
-
else if (filename.charAt(0) === '_' && filename.charAt(1) === '_') {
|
|
46
|
-
files[`${filename.slice(1)}`] = content;
|
|
47
|
-
}
|
|
48
|
-
//原模原样拷贝
|
|
49
|
-
else {
|
|
50
|
-
files[filename] = content;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = (api, options, rootOptions) => {
|
|
57
|
-
//扩展package配置
|
|
58
|
-
// api.extendPackage(pkg => {
|
|
59
|
-
// return {
|
|
60
|
-
// dependencies: {
|
|
61
|
-
// "axios": "^0.19.2",
|
|
62
|
-
// "core-js": "^3.6.5",
|
|
63
|
-
// "vue": "^2.6.11",
|
|
64
|
-
// "vue-router": "^3.2.0",
|
|
65
|
-
// "vuex": "^3.4.0"
|
|
66
|
-
// },
|
|
67
|
-
// devDependencies: {
|
|
68
|
-
// "@vue/cli-plugin-babel": "^4.5.0",
|
|
69
|
-
// "@vue/cli-service": "^4.5.0",
|
|
70
|
-
// "babel-plugin-import": "^1.13.0",
|
|
71
|
-
// "less": "^3.0.4",
|
|
72
|
-
// "less-loader": "^5.0.0",
|
|
73
|
-
// "vue-template-compiler": "^2.6.11"
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
// });
|
|
77
|
-
|
|
78
|
-
// if (options.template === 'bwa/bwa-template-h5') {
|
|
79
|
-
// api.extendPackage(pkg => {
|
|
80
|
-
// return {
|
|
81
|
-
// dependencies: {
|
|
82
|
-
// "vant": "^2.10.3"
|
|
83
|
-
// },
|
|
84
|
-
// devDependencies: {
|
|
85
|
-
|
|
86
|
-
// }
|
|
87
|
-
// }
|
|
88
|
-
// })
|
|
89
|
-
// }
|
|
90
|
-
// else if (options.template === 'bwa/bwa-template-news') {
|
|
91
|
-
// api.extendPackage(pkg => {
|
|
92
|
-
// return {
|
|
93
|
-
// dependencies: {
|
|
94
|
-
// "vue-i18n": "^8.18.2"
|
|
95
|
-
// },
|
|
96
|
-
// devDependencies: {
|
|
97
|
-
|
|
98
|
-
// }
|
|
99
|
-
// }
|
|
100
|
-
// })
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
api.render(async function (files) {
|
|
104
|
-
Object.keys(files).forEach((name) => {
|
|
105
|
-
delete files[name];
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
let _template = options.repo || options.template;
|
|
109
|
-
let _base = '';
|
|
110
|
-
|
|
111
|
-
//获取公共模版内容
|
|
112
|
-
// await generate(path.resolve(__dirname, './template/common'), files);
|
|
113
|
-
|
|
114
|
-
let _spinner = ora('模板下载中...');
|
|
115
|
-
|
|
116
|
-
//下载到根目录
|
|
117
|
-
let _tmpDir = path.join(
|
|
118
|
-
home,
|
|
119
|
-
'.bwa-app/templates',
|
|
120
|
-
_template.replace(/[/:]/g, '-')
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
_spinner.start();
|
|
124
|
-
|
|
125
|
-
await new Promise((resolve, reject) => {
|
|
126
|
-
//http://gitlab.baswebapp.cn/bwa/bwa-template-h5.git
|
|
127
|
-
//开始下载 /bwa/bwa-template-h5/repository/archive.zip?ref=master
|
|
128
|
-
download(_template, _tmpDir, (err) => {
|
|
129
|
-
//下载完成
|
|
130
|
-
_spinner.stop();
|
|
131
|
-
|
|
132
|
-
if (err) {
|
|
133
|
-
return reject(err);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
resolve();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
await generate(_tmpDir, files, _base);
|
|
141
|
-
});
|
|
142
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var generator = require('./generator2.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports["default"] = generator["default"];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs$1 = require('fs');
|
|
6
|
+
var path$1 = require('path');
|
|
7
|
+
var require$$2 = require('isbinaryfile');
|
|
8
|
+
var require$$3 = require('ora');
|
|
9
|
+
var require$$4 = require('user-home');
|
|
10
|
+
var download$1 = require('./download2.js');
|
|
11
|
+
var require$$6 = require('glob');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
|
|
16
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
|
|
17
|
+
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
18
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
19
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
20
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
21
|
+
|
|
22
|
+
const fs = fs__default["default"];
|
|
23
|
+
const path = path__default["default"];
|
|
24
|
+
const isBinary = require$$2__default["default"];
|
|
25
|
+
const ora = require$$3__default["default"];
|
|
26
|
+
const home = require$$4__default["default"];
|
|
27
|
+
const download = download$1["default"];
|
|
28
|
+
async function generate(dir, files, base = "", rootOptions = {}) {
|
|
29
|
+
const glob = require$$6__default["default"];
|
|
30
|
+
glob.sync("**/*", {
|
|
31
|
+
cwd: dir,
|
|
32
|
+
nodir: true
|
|
33
|
+
}).forEach((rawPath) => {
|
|
34
|
+
const sourcePath = path.resolve(dir, rawPath);
|
|
35
|
+
const filename = path.join(base, rawPath);
|
|
36
|
+
if (isBinary.sync(sourcePath)) {
|
|
37
|
+
files[filename] = fs.readFileSync(sourcePath);
|
|
38
|
+
} else {
|
|
39
|
+
let content = fs.readFileSync(sourcePath, "utf-8");
|
|
40
|
+
if (path.basename(filename) === "manifest.json") {
|
|
41
|
+
content = content.replace("{{name}}", rootOptions.projectName || "");
|
|
42
|
+
}
|
|
43
|
+
if (filename.charAt(0) === "_" && filename.charAt(1) !== "_") {
|
|
44
|
+
files[`.${filename.slice(1)}`] = content;
|
|
45
|
+
} else if (filename.charAt(0) === "_" && filename.charAt(1) === "_") {
|
|
46
|
+
files[`${filename.slice(1)}`] = content;
|
|
47
|
+
} else {
|
|
48
|
+
files[filename] = content;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
var generator = (api, options, rootOptions) => {
|
|
54
|
+
api.render(async function(files) {
|
|
55
|
+
Object.keys(files).forEach((name) => {
|
|
56
|
+
delete files[name];
|
|
57
|
+
});
|
|
58
|
+
let _template = options.repo || options.template;
|
|
59
|
+
let _base = "";
|
|
60
|
+
let _spinner = ora("\u6A21\u677F\u4E0B\u8F7D\u4E2D...");
|
|
61
|
+
let _tmpDir = path.join(
|
|
62
|
+
home,
|
|
63
|
+
".bwa-app/templates",
|
|
64
|
+
_template.replace(/[/:]/g, "-")
|
|
65
|
+
);
|
|
66
|
+
_spinner.start();
|
|
67
|
+
await new Promise((resolve, reject) => {
|
|
68
|
+
download(_template, _tmpDir, (err) => {
|
|
69
|
+
_spinner.stop();
|
|
70
|
+
if (err) {
|
|
71
|
+
return reject(err);
|
|
72
|
+
}
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
await generate(_tmpDir, files, _base);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports["default"] = generator;
|