jjb-cmd 2.2.2 → 2.2.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/README.md +4 -0
- package/build.js +15 -0
- package/obf.config.json +3 -0
- package/package.json +1 -1
- package/src/new/cmd.auth/index.js +26 -1
- package/src/new/cmd.init/index.js +116 -1
- package/src/new/cmd.install/config.js +70 -1
- package/src/new/cmd.install/index.js +262 -1
- package/src/new/cmd.install/tools.js +230 -1
- package/src/new/cmd.install.app/index.js +27 -1
- package/src/new/cmd.jenkins/index.js +72 -1
- package/src/new/cmd.publish/index.js +197 -1
- package/src/new/cmd.push/index.js +76 -1
- package/src/new/cmd.push/java.js +148 -1
- package/src/new/cmd.push-set/index.js +205 -1
- package/src/new/cmd.refresh/index.js +65 -1
- package/src/new/cmd.reglist/index.js +23 -1
- package/src/new/cmd.rm-rf/index.js +58 -1
- package/src/new/cmd.version/index.js +35 -1
- package/src/old/cli.dva.register.saas.txt +40 -0
- package/src/old/cli.dva.register.spa.txt +22 -0
- package/src/old/cli.dva.router.saas.txt +210 -0
- package/src/old/cli.dva.router.spa.txt +119 -0
- package/src/old/cli.init.js +26 -1
- package/src/old/cli.install/config.js +206 -1
- package/src/old/cli.install/index.js +340 -1
- package/src/old/cli.install/tools.js +230 -1
- package/src/old/cli.merge.js +80 -1
- package/src/old/cli.pull.js +94 -1
- package/src/old/cli.pull2.js +377 -1
- package/src/old/cli.rm-rf.js +88 -1
- package/src/old/progress-bar.js +23 -1
- package/src/old/util.js +149 -1
@@ -1 +1,340 @@
|
|
1
|
-
const
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
const request = require('request');
|
4
|
+
const compressing = require('compressing');
|
5
|
+
const {
|
6
|
+
f_rm_rf,
|
7
|
+
f_file_copy,
|
8
|
+
f_content_replace,
|
9
|
+
f_create_package_json,
|
10
|
+
f_pull_git_repository,
|
11
|
+
f_scan_jjb_config_json,
|
12
|
+
f_scan_jjb_config_json_rules,
|
13
|
+
f_update_project_package_json
|
14
|
+
} = require('./tools');
|
15
|
+
const {
|
16
|
+
TEMPLATE_FOLDER,
|
17
|
+
COMMON_CONTENT_SPA_REPLACE,
|
18
|
+
CLI_DVA_ROUTER_PATH,
|
19
|
+
CLI_DVA_REGISTER_PATH,
|
20
|
+
CLI_DVA_ROUTER_SPA,
|
21
|
+
CLI_DVA_REGISTER_SPA,
|
22
|
+
CLI_DVA_ROUTER_SAAS,
|
23
|
+
CLI_DVA_REGISTER_SAAS,
|
24
|
+
COMMON_CONTENT_MICRO_REPLACE,
|
25
|
+
COMMON_CONTENT_NOR_REPLACE,
|
26
|
+
COMPONENTS_CONTENT_REPLACE
|
27
|
+
} = require('./config');
|
28
|
+
const start_time = Date.now();
|
29
|
+
|
30
|
+
module.exports = () => {
|
31
|
+
/**
|
32
|
+
* 下发数据根路径
|
33
|
+
* @type {string}
|
34
|
+
*/
|
35
|
+
const root_path = path.resolve('./');
|
36
|
+
/**
|
37
|
+
* 下发数据src路径
|
38
|
+
* @type {string}
|
39
|
+
*/
|
40
|
+
const target_src = [
|
41
|
+
root_path,
|
42
|
+
'src\\'
|
43
|
+
].join('\\');
|
44
|
+
/**
|
45
|
+
* 下发数据node_modules路径
|
46
|
+
* @type {string}
|
47
|
+
*/
|
48
|
+
const target_node_modules = [
|
49
|
+
root_path,
|
50
|
+
'node_modules'
|
51
|
+
].join('\\');
|
52
|
+
/**
|
53
|
+
* 下发数据package.json路径
|
54
|
+
* @type {string}
|
55
|
+
*/
|
56
|
+
const target_package_json = [
|
57
|
+
root_path,
|
58
|
+
'package.json'
|
59
|
+
].join('\\');
|
60
|
+
if (f_scan_jjb_config_json(root_path)) {
|
61
|
+
/**
|
62
|
+
* 检查配置规则
|
63
|
+
*/
|
64
|
+
const jjb_config = f_scan_jjb_config_json_rules(root_path);
|
65
|
+
/**
|
66
|
+
* 检查项目是否存在node_modules
|
67
|
+
*/
|
68
|
+
if (jjb_config.installTarget === 'node_modules') {
|
69
|
+
if (!fs.existsSync(target_node_modules)) {
|
70
|
+
console.log('【Error】:安装失败,node_modules目录不存在。');
|
71
|
+
process.exit(0);
|
72
|
+
} else {
|
73
|
+
console.log('【Warning】:若安装在node_modules中,请确保projectType = micro-spa,并关闭webpack.config.js rules限制。');
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
if (!fs.existsSync(target_src)) {
|
77
|
+
console.log('【Error】:安装失败,src目录不存在。');
|
78
|
+
process.exit(0);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
/**
|
82
|
+
* 文件操作:定义一个临时文件夹
|
83
|
+
*/
|
84
|
+
fs.mkdirSync(TEMPLATE_FOLDER);
|
85
|
+
/**
|
86
|
+
* 拉取数据
|
87
|
+
*/
|
88
|
+
f_pull_git_repository(jjb_config.installResources).map(item => {
|
89
|
+
const stream = fs.createWriteStream(item.path);
|
90
|
+
/**
|
91
|
+
* 流操作:下载git仓库
|
92
|
+
*/
|
93
|
+
request(item.repository).pipe(stream).on('close', () => {
|
94
|
+
fs.mkdirSync(item.compress);
|
95
|
+
/**
|
96
|
+
* 流操作:解压
|
97
|
+
*/
|
98
|
+
compressing.zip.uncompress(item.path, item.compress);
|
99
|
+
});
|
100
|
+
});
|
101
|
+
const timer = setInterval(() => {
|
102
|
+
/**
|
103
|
+
* 文件操作:扫描临时文件夹
|
104
|
+
*/
|
105
|
+
const folder_list = fs.readdirSync(TEMPLATE_FOLDER);
|
106
|
+
/**
|
107
|
+
* 文件操作:抓取临时文件夹中的内容
|
108
|
+
*/
|
109
|
+
const match_folder = folder_list.filter(item => jjb_config.installResources.map(item => `${item.name}_zip`).includes(item));
|
110
|
+
/**
|
111
|
+
* 文件操作:判断是否已解压完成
|
112
|
+
*/
|
113
|
+
if (match_folder.length === jjb_config.installResources.length) {
|
114
|
+
/**
|
115
|
+
* 解压完成关闭定时器
|
116
|
+
*/
|
117
|
+
clearInterval(timer);
|
118
|
+
const resource_folder = [];
|
119
|
+
match_folder.forEach(name => {
|
120
|
+
/**
|
121
|
+
* 文件操作:定义解压包路径
|
122
|
+
*/
|
123
|
+
const unzip = [
|
124
|
+
TEMPLATE_FOLDER,
|
125
|
+
name
|
126
|
+
].join('\\');
|
127
|
+
/**
|
128
|
+
* 文件操作:抓取解压包中的文件
|
129
|
+
*/
|
130
|
+
fs.readdirSync(unzip).forEach(dir => resource_folder.push({
|
131
|
+
name: name,
|
132
|
+
path: [
|
133
|
+
unzip,
|
134
|
+
dir
|
135
|
+
].join('\\'),
|
136
|
+
pure_name: name.replace(/_zip$/, ''),
|
137
|
+
import_list: jjb_config.installResources.find(item => `${item.name}_zip` === name).importList
|
138
|
+
}));
|
139
|
+
});
|
140
|
+
resource_folder.forEach(item => {
|
141
|
+
/**
|
142
|
+
* 文件操作:依赖名称
|
143
|
+
*/
|
144
|
+
const folder_name = item.pure_name;
|
145
|
+
/**
|
146
|
+
* 文件操作:按需加载
|
147
|
+
*/
|
148
|
+
const folder_import_list = item.import_list;
|
149
|
+
/**
|
150
|
+
* 文件操作:组装路径
|
151
|
+
*/
|
152
|
+
const folder_idea_path = [
|
153
|
+
item.path,
|
154
|
+
'.idea'
|
155
|
+
].join('//');
|
156
|
+
/**
|
157
|
+
* 文件操作:组装路径
|
158
|
+
*/
|
159
|
+
const folder_git_ignore_path = [
|
160
|
+
item.path,
|
161
|
+
'.gitignore'
|
162
|
+
].join('//');
|
163
|
+
/**
|
164
|
+
* 特殊处理:删除.idea文件夹
|
165
|
+
*/
|
166
|
+
if (fs.existsSync(folder_idea_path)) {
|
167
|
+
f_rm_rf(folder_idea_path);
|
168
|
+
fs.rmdirSync(folder_idea_path);
|
169
|
+
}
|
170
|
+
/**
|
171
|
+
* 特殊处理:删除.gitignore文件
|
172
|
+
*/
|
173
|
+
if (fs.existsSync(folder_git_ignore_path)) {
|
174
|
+
fs.unlinkSync(folder_git_ignore_path);
|
175
|
+
}
|
176
|
+
/**
|
177
|
+
* 文件操作:按需加载
|
178
|
+
*/
|
179
|
+
if (folder_import_list.length) {
|
180
|
+
/**
|
181
|
+
* 文件操作:根据jjb.config.json中的importList获取需要的文件
|
182
|
+
*/
|
183
|
+
fs.readdirSync(item.path).filter(item => !folder_import_list.includes(item) && item !== 'index.js' && item !== 'setting.json').forEach(dir => {
|
184
|
+
/**
|
185
|
+
* 文件操作:组装路径
|
186
|
+
*/
|
187
|
+
const dirPath = `${item.path}\\${dir}`;
|
188
|
+
/**
|
189
|
+
* 文件操作:删除不需要的文件夹内容
|
190
|
+
*/
|
191
|
+
f_rm_rf(dirPath);
|
192
|
+
/**
|
193
|
+
* 文件操作:删除不需要的文件夹
|
194
|
+
*/
|
195
|
+
fs.rmdirSync(dirPath);
|
196
|
+
});
|
197
|
+
if (folder_name === 'react-admin-component') {
|
198
|
+
const codeList = [];
|
199
|
+
fs.readdirSync(item.path).filter(dir => dir !== 'index.js').forEach(dir => {
|
200
|
+
if (dir === 'RouterContainer') {
|
201
|
+
codeList.push(`export { default as RouterContainer, PATH as RouterContainerPATH } from './RouterContainer';`);
|
202
|
+
} else {
|
203
|
+
codeList.push(`export { default as ${dir} } from './${dir}';`);
|
204
|
+
}
|
205
|
+
});
|
206
|
+
fs.writeFileSync(`${item.path}\\index.js`, codeList.join('\n'));
|
207
|
+
}
|
208
|
+
}
|
209
|
+
if (folder_name === 'jjb-common') {
|
210
|
+
/**
|
211
|
+
* 组装dva/automatic路径
|
212
|
+
*/
|
213
|
+
const automaticPath = [
|
214
|
+
item.path,
|
215
|
+
'\\dva\\automatic'
|
216
|
+
].join('\\');
|
217
|
+
if ([
|
218
|
+
'spa',
|
219
|
+
'micro-spa'
|
220
|
+
].includes(jjb_config.projectType)) {
|
221
|
+
/**
|
222
|
+
* 特殊处理:由于micro-spa模式下需要使用react-router-dom自动化技术,spa模式下使用基于dva/router的自动化技术,两者有差异,需要做替换操作
|
223
|
+
*/
|
224
|
+
if (fs.existsSync(automaticPath)) {
|
225
|
+
/**
|
226
|
+
* 文件操作:常规替换
|
227
|
+
*/
|
228
|
+
f_content_replace(jjb_config.projectType === 'spa'
|
229
|
+
? COMMON_CONTENT_SPA_REPLACE
|
230
|
+
: [
|
231
|
+
...COMMON_CONTENT_MICRO_REPLACE,
|
232
|
+
...COMMON_CONTENT_NOR_REPLACE
|
233
|
+
], item.path);
|
234
|
+
/**
|
235
|
+
* 文件操作:替换dva/automatic/router.js
|
236
|
+
*/
|
237
|
+
fs.writeFileSync(item.path + CLI_DVA_ROUTER_PATH, fs.readFileSync(jjb_config.projectType === 'spa'
|
238
|
+
? CLI_DVA_ROUTER_SPA
|
239
|
+
: CLI_DVA_ROUTER_SAAS).toString());
|
240
|
+
/**
|
241
|
+
* 文件操作:替换dva/automatic/register.js
|
242
|
+
*/
|
243
|
+
fs.writeFileSync(item.path + CLI_DVA_REGISTER_PATH, fs.readFileSync(jjb_config.projectType === 'spa'
|
244
|
+
? CLI_DVA_REGISTER_SPA
|
245
|
+
: CLI_DVA_REGISTER_SAAS).toString());
|
246
|
+
}
|
247
|
+
} else if (jjb_config.projectType === 'multi') {
|
248
|
+
/**
|
249
|
+
* 特殊处理:由于multi模式下不需要使用自动化技术,需要删除dva/automatic文件夹
|
250
|
+
*/
|
251
|
+
if (fs.existsSync(automaticPath)) {
|
252
|
+
f_rm_rf(automaticPath);
|
253
|
+
fs.rmdirSync(automaticPath);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
} else if (folder_name === 'react-admin-component') {
|
257
|
+
/**
|
258
|
+
* 特殊处理:仅限micro-spa模式下允许react-admin-component使用node_modules/jjb-common,其他模式使用src/components,目的是兼容老项目
|
259
|
+
*/
|
260
|
+
if (jjb_config.projectType === 'micro-spa') {
|
261
|
+
f_content_replace(COMPONENTS_CONTENT_REPLACE, item.path);
|
262
|
+
}
|
263
|
+
} else if (folder_name === 'vue-unisass-component') {
|
264
|
+
|
265
|
+
}
|
266
|
+
if (jjb_config.installTarget === 'node_modules') {
|
267
|
+
/**
|
268
|
+
* 特殊处理:为了避免与node_modules其他依赖重名,添加一个标识符"jjb-"
|
269
|
+
*/
|
270
|
+
const package_name = folder_name;
|
271
|
+
/**
|
272
|
+
* 文件操作:判断node_modules目录下是否已存在
|
273
|
+
*/
|
274
|
+
if (fs.existsSync(`${target_node_modules}\\${package_name}`)) {
|
275
|
+
/**
|
276
|
+
* 文件操作:删除node_modules目录下文件内容(保留文件夹)
|
277
|
+
*/
|
278
|
+
f_rm_rf(`${target_node_modules}\\${package_name}`);
|
279
|
+
} else {
|
280
|
+
/**
|
281
|
+
* 文件操作:如果不存在,定义一个新的文件夹
|
282
|
+
*/
|
283
|
+
fs.mkdirSync(`${target_node_modules}\\${package_name}`);
|
284
|
+
}
|
285
|
+
/**
|
286
|
+
* 文件操作:复制文件到node_modules中
|
287
|
+
*/
|
288
|
+
f_file_copy(item.path, `${target_node_modules}\\${package_name}`);
|
289
|
+
/**
|
290
|
+
* 文件操作:创建package.json
|
291
|
+
*/
|
292
|
+
f_create_package_json(`${target_node_modules}\\${package_name}`, package_name, '1.0.0');
|
293
|
+
/**
|
294
|
+
* 文件操作:在src/package.json中定义一个组件依赖
|
295
|
+
*/
|
296
|
+
f_update_project_package_json(target_package_json, package_name, '1.0.0');
|
297
|
+
} else if (jjb_config.installTarget === 'src') {
|
298
|
+
/**
|
299
|
+
* 特殊处理:由于老项目问题,此处要将react-admin-component转换为components(仅限src模式)
|
300
|
+
*/
|
301
|
+
const t_name = 'react-admin-component';
|
302
|
+
/**
|
303
|
+
* 文件操作:判断src目录下是否已存在
|
304
|
+
*/
|
305
|
+
if (fs.existsSync(target_src + t_name)) {
|
306
|
+
/**
|
307
|
+
* 文件操作:删除src目录下文件内容(保留文件夹)
|
308
|
+
*/
|
309
|
+
f_rm_rf(target_src + t_name);
|
310
|
+
} else {
|
311
|
+
/**
|
312
|
+
* 文件操作:如果不存在,定义一个新的文件夹
|
313
|
+
*/
|
314
|
+
fs.mkdirSync(target_src + t_name);
|
315
|
+
}
|
316
|
+
/**
|
317
|
+
* 文件操作:复制文件到src中
|
318
|
+
*/
|
319
|
+
f_file_copy(item.path, target_src + t_name);
|
320
|
+
}
|
321
|
+
});
|
322
|
+
setTimeout(() => {
|
323
|
+
/**
|
324
|
+
* 文件操作:删除临时文件夹内容
|
325
|
+
*/
|
326
|
+
f_rm_rf(TEMPLATE_FOLDER);
|
327
|
+
/**
|
328
|
+
* 文件操作:删除临时文件夹
|
329
|
+
*/
|
330
|
+
fs.rmdirSync(TEMPLATE_FOLDER);
|
331
|
+
const end_time = Date.now();
|
332
|
+
console.log(`【jjb-cmd】:install命令执行完成,用时${(end_time - start_time) / 1000}s`);
|
333
|
+
}, 1500);
|
334
|
+
}
|
335
|
+
}, 1000);
|
336
|
+
} else {
|
337
|
+
console.log('【Error】:执行失败,在您的项目根目录,需要一个jjb.config.json文件。');
|
338
|
+
}
|
339
|
+
};
|
340
|
+
|
@@ -1 +1,230 @@
|
|
1
|
-
const
|
1
|
+
const fs = require('fs');
|
2
|
+
const os = require('os');
|
3
|
+
const {
|
4
|
+
GIT_HOST,
|
5
|
+
GIT_TEMP_DIR,
|
6
|
+
CLOUD_PROJECT
|
7
|
+
} = require('./config');
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @description 删除全部
|
11
|
+
* @param path {string} 路径
|
12
|
+
*/
|
13
|
+
exports.f_rm_rf = function (path) {
|
14
|
+
if (fs.existsSync(path)) {
|
15
|
+
const list = fs.readdirSync(path);
|
16
|
+
for (let i = 0; i < list.length; i++) {
|
17
|
+
const item = list[ i ];
|
18
|
+
const vPath = `${path}/${item}`;
|
19
|
+
if (fs.statSync(vPath).isDirectory()) {
|
20
|
+
exports.f_rm_rf(vPath);
|
21
|
+
fs.rmdirSync(vPath);
|
22
|
+
} else {
|
23
|
+
fs.unlinkSync(vPath);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @typedef {object} GitResource
|
31
|
+
* @property {string} path
|
32
|
+
* @property {string} compress
|
33
|
+
* @property {string} repository
|
34
|
+
*/
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @description 拉取git资源
|
38
|
+
* @param installResources {Resource[]} 资源名称
|
39
|
+
* @return {GitResource[]}
|
40
|
+
*/
|
41
|
+
exports.f_pull_git_repository = function (installResources = []) {
|
42
|
+
return installResources.map(item => {
|
43
|
+
const resource = CLOUD_PROJECT[ item.name ] || undefined;
|
44
|
+
const template = os.tmpdir();
|
45
|
+
return {
|
46
|
+
path: `${template}\\${GIT_TEMP_DIR}\\${item.name}.zip`,
|
47
|
+
compress: `${template}\\${GIT_TEMP_DIR}\\${item.name}_zip`,
|
48
|
+
repository: `${GIT_HOST}/api/v4/projects/${resource.projectId}/repository/archive.zip?private_token=${resource.token}&ref=master`
|
49
|
+
};
|
50
|
+
});
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @description 扫描是否存在jjb.config.json
|
55
|
+
* @param root 路径
|
56
|
+
* @returns {boolean}
|
57
|
+
*/
|
58
|
+
exports.f_scan_jjb_config_json = function (root) {
|
59
|
+
return fs.existsSync(`${root}\\jjb.config.json`);
|
60
|
+
};
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @typedef {object} JJB_CONFIG_JSON
|
64
|
+
* @property {string} projectType
|
65
|
+
* @property {string} installTarget
|
66
|
+
* @property {Resource[]} installResources
|
67
|
+
*/
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @description 验证规则
|
71
|
+
* @param root {string} 路径
|
72
|
+
* @return {JJB_CONFIG_JSON}
|
73
|
+
*/
|
74
|
+
exports.f_scan_jjb_config_json_rules = function (root) {
|
75
|
+
let jjb_config_json = {};
|
76
|
+
try {
|
77
|
+
jjb_config_json = JSON.parse(fs.readFileSync(`${root}\\jjb.config.json`).toString());
|
78
|
+
} catch (e) {
|
79
|
+
console.log('【Error】:[jjb.config.json]文件解析失败,请确认是否配置正确。');
|
80
|
+
process.exit(0);
|
81
|
+
}
|
82
|
+
if (!('projectType' in jjb_config_json)) {
|
83
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要projectType属性。');
|
84
|
+
process.exit(0);
|
85
|
+
}
|
86
|
+
if (!('installTarget' in jjb_config_json)) {
|
87
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要installTarget属性。');
|
88
|
+
process.exit(0);
|
89
|
+
}
|
90
|
+
if (!('installResources' in jjb_config_json)) {
|
91
|
+
console.log('【Error】:[jjb.config.json]文件配置无效,需要installResources属性。');
|
92
|
+
process.exit(0);
|
93
|
+
}
|
94
|
+
if (typeof jjb_config_json.projectType !== 'string') {
|
95
|
+
console.log('【Error】:[jjb.config.json.projectType]类型是一个string。');
|
96
|
+
process.exit(0);
|
97
|
+
}
|
98
|
+
if (![
|
99
|
+
'multi',
|
100
|
+
'spa',
|
101
|
+
'uniapp',
|
102
|
+
'micro-spa'
|
103
|
+
].includes(jjb_config_json.projectType)) {
|
104
|
+
console.log('【Error】:[jjb.config.json.projectType]配置无效,有效值<multi | spa | micro-spa | uniapp>。');
|
105
|
+
process.exit(0);
|
106
|
+
}
|
107
|
+
if (typeof jjb_config_json.installTarget !== 'string') {
|
108
|
+
console.log('【Error】:[jjb.config.json.installTarget]类型是一个string。');
|
109
|
+
process.exit(0);
|
110
|
+
}
|
111
|
+
if (![
|
112
|
+
'node_modules',
|
113
|
+
'src'
|
114
|
+
].includes(jjb_config_json.installTarget)) {
|
115
|
+
console.log('【Error】:[jjb.config.json.node_modules]配置无效,有效值<node_modules | src>。');
|
116
|
+
process.exit(0);
|
117
|
+
}
|
118
|
+
if (!Array.isArray(jjb_config_json.installResources)) {
|
119
|
+
console.log('【Error】:[jjb.config.json.installResources]类型是一个Array<string>。');
|
120
|
+
process.exit(0);
|
121
|
+
}
|
122
|
+
if (jjb_config_json.installResources.length === 0) {
|
123
|
+
console.log('【Error】:[jjb.config.json.installResources]无资源。');
|
124
|
+
process.exit(0);
|
125
|
+
}
|
126
|
+
const resources = exports.f_resolve_install_resources(jjb_config_json.installResources);
|
127
|
+
if (resources.map(item => item.name).filter(v => ![
|
128
|
+
'jjb-common',
|
129
|
+
'jjb-dva-runtime',
|
130
|
+
'jjb-common-lib',
|
131
|
+
'jjb-common-decorator',
|
132
|
+
'react-admin-component',
|
133
|
+
'vue-unisass-component'
|
134
|
+
].includes(v)).length !== 0) {
|
135
|
+
console.log('【Error】:[jjb.config.json.installResources]配置无效,有效值<common | react-admin-component | vue-unisass-component | jjb-common-decorator | jjb-dva-runtime | jjb-common-lib>。');
|
136
|
+
process.exit(0);
|
137
|
+
}
|
138
|
+
jjb_config_json.installResources = resources;
|
139
|
+
return jjb_config_json;
|
140
|
+
};
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @description 创建package.json
|
144
|
+
* @param path {string} 路径
|
145
|
+
* @param name {string} 包名
|
146
|
+
* @param version {string} 版本
|
147
|
+
*/
|
148
|
+
exports.f_create_package_json = function (path, name, version) {
|
149
|
+
fs.writeFileSync(`${path}\\package.json`, `{"name":"${name}","version":"${version}","main": "index.js"}`);
|
150
|
+
};
|
151
|
+
|
152
|
+
/**
|
153
|
+
* @typedef {object} Resource
|
154
|
+
* @property {string} name
|
155
|
+
* @property {string[]} importList
|
156
|
+
*/
|
157
|
+
|
158
|
+
/**
|
159
|
+
* @description 分析resources
|
160
|
+
* @param installResources
|
161
|
+
* @return {Resource[]}
|
162
|
+
*/
|
163
|
+
exports.f_resolve_install_resources = function (installResources = []) {
|
164
|
+
const resources = [];
|
165
|
+
if (Array.isArray(installResources)) {
|
166
|
+
installResources.forEach(resource => {
|
167
|
+
if (Array.isArray(resource)) {
|
168
|
+
const [ name, importList = [] ] = resource;
|
169
|
+
resources.push({
|
170
|
+
name,
|
171
|
+
importList
|
172
|
+
});
|
173
|
+
} else {
|
174
|
+
resources.push({
|
175
|
+
name: resource,
|
176
|
+
importList: []
|
177
|
+
});
|
178
|
+
}
|
179
|
+
});
|
180
|
+
}
|
181
|
+
return resources;
|
182
|
+
};
|
183
|
+
|
184
|
+
/**
|
185
|
+
* @description 更新项目package.json文件
|
186
|
+
* @param path {string} 路径
|
187
|
+
* @param name {string} 包名
|
188
|
+
* @param version {string} 版本
|
189
|
+
*/
|
190
|
+
exports.f_update_project_package_json = function (path, name, version) {
|
191
|
+
const packageJSONFile = JSON.parse(fs.readFileSync(path).toString());
|
192
|
+
packageJSONFile.dependencies[ name ] = version;
|
193
|
+
fs.writeFileSync(path, JSON.stringify(packageJSONFile, null, 2));
|
194
|
+
};
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @description 复制文件
|
198
|
+
* @param originSrc
|
199
|
+
* @param targetSrc
|
200
|
+
*/
|
201
|
+
exports.f_file_copy = function (originSrc, targetSrc) {
|
202
|
+
fs.readdirSync(originSrc).forEach(dir => {
|
203
|
+
const oPath = `${originSrc}\\${dir}`;
|
204
|
+
const tPath = `${targetSrc}\\${dir}`;
|
205
|
+
if (fs.statSync(oPath).isDirectory()) {
|
206
|
+
fs.mkdirSync(tPath);
|
207
|
+
exports.f_file_copy(oPath, tPath);
|
208
|
+
} else {
|
209
|
+
fs.writeFileSync(tPath, fs.readFileSync(oPath).toString());
|
210
|
+
}
|
211
|
+
});
|
212
|
+
};
|
213
|
+
|
214
|
+
/**
|
215
|
+
* @description 替换文件操作
|
216
|
+
* @param source {[]} 替换源
|
217
|
+
* @param root {string} 路径
|
218
|
+
*/
|
219
|
+
exports.f_content_replace = function (source = [], root) {
|
220
|
+
source.forEach(item => {
|
221
|
+
const path = root + item.path;
|
222
|
+
if (fs.existsSync(path)) {
|
223
|
+
let content = fs.readFileSync(path).toString();
|
224
|
+
item.replace.forEach(rep => {
|
225
|
+
content = content.replace(rep[ 0 ], rep[ 1 ]);
|
226
|
+
});
|
227
|
+
fs.writeFileSync(path, content);
|
228
|
+
}
|
229
|
+
});
|
230
|
+
};
|