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.
@@ -1 +1,340 @@
1
- const a17_0x128b89=a17_0x31b4;function a17_0x31b4(_0x49f3a9,_0x5938fb){const _0x229aa1=a17_0x229a();return a17_0x31b4=function(_0x31b424,_0xbf603c){_0x31b424=_0x31b424-0xed;let _0x1b6a75=_0x229aa1[_0x31b424];return _0x1b6a75;},a17_0x31b4(_0x49f3a9,_0x5938fb);}(function(_0x38b865,_0x1ca73a){const _0x5012ef=a17_0x31b4,_0x3c8989=_0x38b865();while(!![]){try{const _0xf9d018=-parseInt(_0x5012ef(0x111))/0x1*(-parseInt(_0x5012ef(0x11f))/0x2)+parseInt(_0x5012ef(0x123))/0x3*(-parseInt(_0x5012ef(0xf2))/0x4)+parseInt(_0x5012ef(0x10b))/0x5*(-parseInt(_0x5012ef(0x135))/0x6)+-parseInt(_0x5012ef(0xf0))/0x7*(parseInt(_0x5012ef(0x12b))/0x8)+-parseInt(_0x5012ef(0x122))/0x9+parseInt(_0x5012ef(0x108))/0xa*(parseInt(_0x5012ef(0x116))/0xb)+-parseInt(_0x5012ef(0x10a))/0xc*(-parseInt(_0x5012ef(0xfa))/0xd);if(_0xf9d018===_0x1ca73a)break;else _0x3c8989['push'](_0x3c8989['shift']());}catch(_0x160244){_0x3c8989['push'](_0x3c8989['shift']());}}}(a17_0x229a,0x7ba80));const fs=require('fs'),path=require(a17_0x128b89(0x124)),request=require(a17_0x128b89(0x121)),compressing=require(a17_0x128b89(0xf8)),{f_rm_rf,f_file_copy,f_content_replace,f_create_package_json,f_pull_git_repository,f_scan_jjb_config_json,f_scan_jjb_config_json_rules,f_update_project_package_json}=require(a17_0x128b89(0xf5)),{TEMPLATE_FOLDER,COMMON_CONTENT_SPA_REPLACE,CLI_DVA_ROUTER_PATH,CLI_DVA_REGISTER_PATH,CLI_DVA_ROUTER_SPA,CLI_DVA_REGISTER_SPA,CLI_DVA_ROUTER_SAAS,CLI_DVA_REGISTER_SAAS,COMMON_CONTENT_MICRO_REPLACE,COMMON_CONTENT_NOR_REPLACE,COMPONENTS_CONTENT_REPLACE}=require(a17_0x128b89(0x103)),start_time=Date[a17_0x128b89(0x10f)]();function a17_0x229a(){const _0x72a4bc=['installTarget','exports','projectType','_zip','react-admin-component','1.0.0','2768jXzlmW','vue-unisass-component','request','4471569QJLtxX','27YyREsz','path','compress','replace','exit','repository','writeFileSync','rmdirSync','132304aVEJQS','.idea','mkdirSync','index.js','package.json','resolve','log','src','jjb-common','createWriteStream','26430vMoHXX','includes','export\x20{\x20default\x20as\x20','forEach','119lbZhmD','spa','290828woJtKp','.gitignore','length','./tools','import_list','readFileSync','compressing','【Error】:安装失败,src目录不存在。','16003871ehVnAy','uncompress','push','readdirSync','map','zip','name','export\x20{\x20default\x20as\x20RouterContainer,\x20PATH\x20as\x20RouterContainerPATH\x20}\x20from\x20\x27./RouterContainer\x27;','toString','./config','unlinkSync','【Warning】:若安装在node_modules中,请确保projectType\x20=\x20micro-spa,并关闭webpack.config.js\x20rules限制。','join','【jjb-cmd】:install命令执行完成,用时','194090fJJwlL','node_modules','12VhXgJP','695XifRwl','filter','importList','RouterContainer','now','existsSync','477PpsNuA','src\x5c','\x20}\x20from\x20\x27./','【Error】:安装失败,node_modules目录不存在。','installResources','374BfhhzR','micro-spa','close'];a17_0x229a=function(){return _0x72a4bc;};return a17_0x229a();}module[a17_0x128b89(0x11a)]=()=>{const _0x9f0004=a17_0x128b89,_0x559100=path[_0x9f0004(0x130)]('./'),_0x142b66=[_0x559100,_0x9f0004(0x112)]['join']('\x5c'),_0x3b1a13=[_0x559100,'node_modules']['join']('\x5c'),_0x3ce4ed=[_0x559100,_0x9f0004(0x12f)][_0x9f0004(0x106)]('\x5c');if(f_scan_jjb_config_json(_0x559100)){const _0x56cb95=f_scan_jjb_config_json_rules(_0x559100);_0x56cb95[_0x9f0004(0x119)]==='node_modules'?!fs[_0x9f0004(0x110)](_0x3b1a13)?(console[_0x9f0004(0x131)](_0x9f0004(0x114)),process[_0x9f0004(0x127)](0x0)):console[_0x9f0004(0x131)](_0x9f0004(0x105)):!fs[_0x9f0004(0x110)](_0x142b66)&&(console[_0x9f0004(0x131)](_0x9f0004(0xf9)),process['exit'](0x0));fs[_0x9f0004(0x12d)](TEMPLATE_FOLDER),f_pull_git_repository(_0x56cb95[_0x9f0004(0x115)])[_0x9f0004(0xfe)](_0x53bf17=>{const _0x5af81d=_0x9f0004,_0x178c06=fs[_0x5af81d(0x134)](_0x53bf17['path']);request(_0x53bf17[_0x5af81d(0x128)])['pipe'](_0x178c06)['on'](_0x5af81d(0x118),()=>{const _0xa8b338=_0x5af81d;fs[_0xa8b338(0x12d)](_0x53bf17[_0xa8b338(0x125)]),compressing[_0xa8b338(0xff)][_0xa8b338(0xfb)](_0x53bf17[_0xa8b338(0x124)],_0x53bf17[_0xa8b338(0x125)]);});});const _0x132a89=setInterval(()=>{const _0x37972c=_0x9f0004,_0x5ace99=fs[_0x37972c(0xfd)](TEMPLATE_FOLDER),_0x1e5ca4=_0x5ace99['filter'](_0x3cbec1=>_0x56cb95[_0x37972c(0x115)][_0x37972c(0xfe)](_0x267299=>_0x267299[_0x37972c(0x100)]+_0x37972c(0x11c))[_0x37972c(0xed)](_0x3cbec1));if(_0x1e5ca4['length']===_0x56cb95['installResources'][_0x37972c(0xf4)]){clearInterval(_0x132a89);const _0x4eccf0=[];_0x1e5ca4[_0x37972c(0xef)](_0x44d7c3=>{const _0x1c41df=_0x37972c,_0x379b47=[TEMPLATE_FOLDER,_0x44d7c3]['join']('\x5c');fs['readdirSync'](_0x379b47)[_0x1c41df(0xef)](_0x25118b=>_0x4eccf0[_0x1c41df(0xfc)]({'name':_0x44d7c3,'path':[_0x379b47,_0x25118b][_0x1c41df(0x106)]('\x5c'),'pure_name':_0x44d7c3[_0x1c41df(0x126)](/_zip$/,''),'import_list':_0x56cb95[_0x1c41df(0x115)]['find'](_0x1356d3=>_0x1356d3[_0x1c41df(0x100)]+_0x1c41df(0x11c)===_0x44d7c3)[_0x1c41df(0x10d)]}));}),_0x4eccf0['forEach'](_0x5aba1b=>{const _0x391267=_0x37972c,_0x269440=_0x5aba1b['pure_name'],_0x4c1c4f=_0x5aba1b[_0x391267(0xf6)],_0x27a5f5=[_0x5aba1b[_0x391267(0x124)],_0x391267(0x12c)][_0x391267(0x106)]('//'),_0x53d24d=[_0x5aba1b[_0x391267(0x124)],_0x391267(0xf3)][_0x391267(0x106)]('//');fs[_0x391267(0x110)](_0x27a5f5)&&(f_rm_rf(_0x27a5f5),fs[_0x391267(0x12a)](_0x27a5f5));fs[_0x391267(0x110)](_0x53d24d)&&fs[_0x391267(0x104)](_0x53d24d);if(_0x4c1c4f[_0x391267(0xf4)]){fs[_0x391267(0xfd)](_0x5aba1b[_0x391267(0x124)])[_0x391267(0x10c)](_0x42134d=>!_0x4c1c4f[_0x391267(0xed)](_0x42134d)&&_0x42134d!=='index.js'&&_0x42134d!=='setting.json')[_0x391267(0xef)](_0x40404f=>{const _0x43c736=_0x391267,_0x356767=_0x5aba1b[_0x43c736(0x124)]+'\x5c'+_0x40404f;f_rm_rf(_0x356767),fs['rmdirSync'](_0x356767);});if(_0x269440==='react-admin-component'){const _0x5c2db7=[];fs['readdirSync'](_0x5aba1b[_0x391267(0x124)])[_0x391267(0x10c)](_0x23e581=>_0x23e581!==_0x391267(0x12e))[_0x391267(0xef)](_0x450e99=>{const _0x55b32b=_0x391267;_0x450e99===_0x55b32b(0x10e)?_0x5c2db7[_0x55b32b(0xfc)](_0x55b32b(0x101)):_0x5c2db7['push'](_0x55b32b(0xee)+_0x450e99+_0x55b32b(0x113)+_0x450e99+'\x27;');}),fs['writeFileSync'](_0x5aba1b[_0x391267(0x124)]+'\x5cindex.js',_0x5c2db7['join']('\x0a'));}}if(_0x269440===_0x391267(0x133)){const _0x4ef8b4=[_0x5aba1b[_0x391267(0x124)],'\x5cdva\x5cautomatic'][_0x391267(0x106)]('\x5c');if([_0x391267(0xf1),_0x391267(0x117)][_0x391267(0xed)](_0x56cb95[_0x391267(0x11b)]))fs[_0x391267(0x110)](_0x4ef8b4)&&(f_content_replace(_0x56cb95[_0x391267(0x11b)]===_0x391267(0xf1)?COMMON_CONTENT_SPA_REPLACE:[...COMMON_CONTENT_MICRO_REPLACE,...COMMON_CONTENT_NOR_REPLACE],_0x5aba1b['path']),fs[_0x391267(0x129)](_0x5aba1b[_0x391267(0x124)]+CLI_DVA_ROUTER_PATH,fs['readFileSync'](_0x56cb95[_0x391267(0x11b)]===_0x391267(0xf1)?CLI_DVA_ROUTER_SPA:CLI_DVA_ROUTER_SAAS)['toString']()),fs[_0x391267(0x129)](_0x5aba1b[_0x391267(0x124)]+CLI_DVA_REGISTER_PATH,fs[_0x391267(0xf7)](_0x56cb95[_0x391267(0x11b)]===_0x391267(0xf1)?CLI_DVA_REGISTER_SPA:CLI_DVA_REGISTER_SAAS)[_0x391267(0x102)]()));else _0x56cb95[_0x391267(0x11b)]==='multi'&&(fs[_0x391267(0x110)](_0x4ef8b4)&&(f_rm_rf(_0x4ef8b4),fs[_0x391267(0x12a)](_0x4ef8b4)));}else{if(_0x269440===_0x391267(0x11d))_0x56cb95[_0x391267(0x11b)]==='micro-spa'&&f_content_replace(COMPONENTS_CONTENT_REPLACE,_0x5aba1b[_0x391267(0x124)]);else{if(_0x269440===_0x391267(0x120)){}}}if(_0x56cb95[_0x391267(0x119)]===_0x391267(0x109)){const _0x5da26a=_0x269440;fs['existsSync'](_0x3b1a13+'\x5c'+_0x5da26a)?f_rm_rf(_0x3b1a13+'\x5c'+_0x5da26a):fs[_0x391267(0x12d)](_0x3b1a13+'\x5c'+_0x5da26a),f_file_copy(_0x5aba1b[_0x391267(0x124)],_0x3b1a13+'\x5c'+_0x5da26a),f_create_package_json(_0x3b1a13+'\x5c'+_0x5da26a,_0x5da26a,_0x391267(0x11e)),f_update_project_package_json(_0x3ce4ed,_0x5da26a,_0x391267(0x11e));}else{if(_0x56cb95[_0x391267(0x119)]===_0x391267(0x132)){const _0x2cd3a6=_0x391267(0x11d);fs['existsSync'](_0x142b66+_0x2cd3a6)?f_rm_rf(_0x142b66+_0x2cd3a6):fs[_0x391267(0x12d)](_0x142b66+_0x2cd3a6),f_file_copy(_0x5aba1b[_0x391267(0x124)],_0x142b66+_0x2cd3a6);}}}),setTimeout(()=>{const _0x190b06=_0x37972c;f_rm_rf(TEMPLATE_FOLDER),fs[_0x190b06(0x12a)](TEMPLATE_FOLDER);const _0x4fe28b=Date[_0x190b06(0x10f)]();console[_0x190b06(0x131)](_0x190b06(0x107)+(_0x4fe28b-start_time)/0x3e8+'s');},0x5dc);}},0x3e8);}else console[_0x9f0004(0x131)]('【Error】:执行失败,在您的项目根目录,需要一个jjb.config.json文件。');};
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 a18_0x2890b7=a18_0x58f1;(function(_0x219697,_0xcb42b2){const _0x3b8d7e=a18_0x58f1,_0x5bce5b=_0x219697();while(!![]){try{const _0xbe68d6=parseInt(_0x3b8d7e(0x11c))/0x1+-parseInt(_0x3b8d7e(0x126))/0x2+-parseInt(_0x3b8d7e(0x112))/0x3*(parseInt(_0x3b8d7e(0xfd))/0x4)+parseInt(_0x3b8d7e(0x10d))/0x5*(parseInt(_0x3b8d7e(0xe8))/0x6)+-parseInt(_0x3b8d7e(0xf0))/0x7+-parseInt(_0x3b8d7e(0xff))/0x8*(-parseInt(_0x3b8d7e(0xfc))/0x9)+-parseInt(_0x3b8d7e(0xfa))/0xa;if(_0xbe68d6===_0xcb42b2)break;else _0x5bce5b['push'](_0x5bce5b['shift']());}catch(_0x5ce2ed){_0x5bce5b['push'](_0x5bce5b['shift']());}}}(a18_0x2e4d,0x2e771));const fs=require('fs'),os=require('os'),{GIT_HOST,GIT_TEMP_DIR,CLOUD_PROJECT}=require(a18_0x2890b7(0x113));function a18_0x2e4d(){const _0x131d61=['/api/v4/projects/','f_create_package_json','547626TdHYrL','writeFileSync','f_pull_git_repository','\x22,\x22version\x22:\x22','6hpWbuK','jjb-dva-runtime','uniapp','isArray','installResources','f_update_project_package_json','react-admin-component','projectId','160356BYZKYp','spa','replace','/repository/archive.zip?private_token=','jjb-common-lib','【Error】:[jjb.config.json.projectType]配置无效,有效值<multi\x20|\x20spa\x20|\x20micro-spa\x20|\x20uniapp>。','f_rm_rf','src','log','statSync','2863060rgMBFH','isDirectory','774693qMxJEs','108RFvwIm','readFileSync','24okhqyo','dependencies','name','forEach','f_scan_jjb_config_json','token','jjb-common-decorator','exit','f_resolve_install_resources','【Error】:[jjb.config.json.installResources]配置无效,有效值<common\x20|\x20react-admin-component\x20|\x20vue-unisass-component\x20|\x20jjb-common-decorator\x20|\x20jjb-dva-runtime\x20|\x20jjb-common-lib>。','rmdirSync','readdirSync','toString','parse','978220xhfHoR','f_file_copy','path','multi','existsSync','984zTKmmu','./config','【Error】:[jjb.config.json]文件配置无效,需要installTarget属性。','&ref=master','vue-unisass-component','string','installTarget','f_scan_jjb_config_json_rules','node_modules','【Error】:[jjb.config.json.projectType]类型是一个string。','328329YLXOsT','map','length','projectType','【Error】:[jjb.config.json.installResources]类型是一个Array<string>。','\x5cjjb.config.json','filter','includes'];a18_0x2e4d=function(){return _0x131d61;};return a18_0x2e4d();}function a18_0x58f1(_0x4cf2ee,_0x495e0c){const _0x2e4d94=a18_0x2e4d();return a18_0x58f1=function(_0x58f1d3,_0x1f9591){_0x58f1d3=_0x58f1d3-0xe8;let _0x441a12=_0x2e4d94[_0x58f1d3];return _0x441a12;},a18_0x58f1(_0x4cf2ee,_0x495e0c);}exports[a18_0x2890b7(0xf6)]=function(_0x7080c0){const _0x1daef4=a18_0x2890b7;if(fs[_0x1daef4(0x111)](_0x7080c0)){const _0xf5a7eb=fs[_0x1daef4(0x10a)](_0x7080c0);for(let _0x345b74=0x0;_0x345b74<_0xf5a7eb['length'];_0x345b74++){const _0x3fe548=_0xf5a7eb[_0x345b74],_0xa84633=_0x7080c0+'/'+_0x3fe548;fs[_0x1daef4(0xf9)](_0xa84633)['isDirectory']()?(exports[_0x1daef4(0xf6)](_0xa84633),fs[_0x1daef4(0x109)](_0xa84633)):fs['unlinkSync'](_0xa84633);}}},exports[a18_0x2890b7(0x128)]=function(_0x9bf17c=[]){const _0x5069c4=a18_0x2890b7;return _0x9bf17c[_0x5069c4(0x11d)](_0x2a5300=>{const _0x118969=_0x5069c4,_0x22dca6=CLOUD_PROJECT[_0x2a5300[_0x118969(0x101)]]||undefined,_0x11fa92=os['tmpdir']();return{'path':_0x11fa92+'\x5c'+GIT_TEMP_DIR+'\x5c'+_0x2a5300[_0x118969(0x101)]+'.zip','compress':_0x11fa92+'\x5c'+GIT_TEMP_DIR+'\x5c'+_0x2a5300[_0x118969(0x101)]+'_zip','repository':GIT_HOST+_0x118969(0x124)+_0x22dca6[_0x118969(0xef)]+_0x118969(0xf3)+_0x22dca6[_0x118969(0x104)]+_0x118969(0x115)};});},exports[a18_0x2890b7(0x103)]=function(_0x59b9ed){const _0x559ca2=a18_0x2890b7;return fs['existsSync'](_0x59b9ed+_0x559ca2(0x121));},exports[a18_0x2890b7(0x119)]=function(_0x15f71d){const _0x27696e=a18_0x2890b7;let _0x5bf298={};try{_0x5bf298=JSON[_0x27696e(0x10c)](fs[_0x27696e(0xfe)](_0x15f71d+_0x27696e(0x121))[_0x27696e(0x10b)]());}catch(_0xd75897){console['log']('【Error】:[jjb.config.json]文件解析失败,请确认是否配置正确。'),process[_0x27696e(0x106)](0x0);}!(_0x27696e(0x11f)in _0x5bf298)&&(console[_0x27696e(0xf8)]('【Error】:[jjb.config.json]文件配置无效,需要projectType属性。'),process[_0x27696e(0x106)](0x0));!(_0x27696e(0x118)in _0x5bf298)&&(console[_0x27696e(0xf8)](_0x27696e(0x114)),process[_0x27696e(0x106)](0x0));!('installResources'in _0x5bf298)&&(console[_0x27696e(0xf8)]('【Error】:[jjb.config.json]文件配置无效,需要installResources属性。'),process[_0x27696e(0x106)](0x0));typeof _0x5bf298['projectType']!=='string'&&(console[_0x27696e(0xf8)](_0x27696e(0x11b)),process['exit'](0x0));![_0x27696e(0x110),_0x27696e(0xf1),_0x27696e(0xea),'micro-spa']['includes'](_0x5bf298['projectType'])&&(console['log'](_0x27696e(0xf5)),process[_0x27696e(0x106)](0x0));typeof _0x5bf298[_0x27696e(0x118)]!==_0x27696e(0x117)&&(console[_0x27696e(0xf8)]('【Error】:[jjb.config.json.installTarget]类型是一个string。'),process[_0x27696e(0x106)](0x0));![_0x27696e(0x11a),_0x27696e(0xf7)][_0x27696e(0x123)](_0x5bf298[_0x27696e(0x118)])&&(console[_0x27696e(0xf8)]('【Error】:[jjb.config.json.node_modules]配置无效,有效值<node_modules\x20|\x20src>。'),process[_0x27696e(0x106)](0x0));!Array['isArray'](_0x5bf298[_0x27696e(0xec)])&&(console[_0x27696e(0xf8)](_0x27696e(0x120)),process['exit'](0x0));_0x5bf298[_0x27696e(0xec)][_0x27696e(0x11e)]===0x0&&(console['log']('【Error】:[jjb.config.json.installResources]无资源。'),process[_0x27696e(0x106)](0x0));const _0x1586ea=exports['f_resolve_install_resources'](_0x5bf298[_0x27696e(0xec)]);return _0x1586ea[_0x27696e(0x11d)](_0x8492ef=>_0x8492ef[_0x27696e(0x101)])[_0x27696e(0x122)](_0x520ad9=>!['jjb-common',_0x27696e(0xe9),_0x27696e(0xf4),_0x27696e(0x105),_0x27696e(0xee),_0x27696e(0x116)]['includes'](_0x520ad9))[_0x27696e(0x11e)]!==0x0&&(console[_0x27696e(0xf8)](_0x27696e(0x108)),process[_0x27696e(0x106)](0x0)),_0x5bf298['installResources']=_0x1586ea,_0x5bf298;},exports[a18_0x2890b7(0x125)]=function(_0x2495af,_0x2c717e,_0x1726ca){const _0x47dbed=a18_0x2890b7;fs['writeFileSync'](_0x2495af+'\x5cpackage.json','{\x22name\x22:\x22'+_0x2c717e+_0x47dbed(0x129)+_0x1726ca+'\x22,\x22main\x22:\x20\x22index.js\x22}');},exports[a18_0x2890b7(0x107)]=function(_0x397d6f=[]){const _0x28d28f=a18_0x2890b7,_0x15848d=[];return Array[_0x28d28f(0xeb)](_0x397d6f)&&_0x397d6f[_0x28d28f(0x102)](_0xfb4f2c=>{const _0xc36d6a=_0x28d28f;if(Array[_0xc36d6a(0xeb)](_0xfb4f2c)){const [_0x601e68,_0x2843d2=[]]=_0xfb4f2c;_0x15848d['push']({'name':_0x601e68,'importList':_0x2843d2});}else _0x15848d['push']({'name':_0xfb4f2c,'importList':[]});}),_0x15848d;},exports[a18_0x2890b7(0xed)]=function(_0x3f4239,_0x54b963,_0x4c5b05){const _0x5d0425=a18_0x2890b7,_0x2215d4=JSON['parse'](fs[_0x5d0425(0xfe)](_0x3f4239)['toString']());_0x2215d4[_0x5d0425(0x100)][_0x54b963]=_0x4c5b05,fs[_0x5d0425(0x127)](_0x3f4239,JSON['stringify'](_0x2215d4,null,0x2));},exports[a18_0x2890b7(0x10e)]=function(_0x13509f,_0x448a34){const _0x46501e=a18_0x2890b7;fs[_0x46501e(0x10a)](_0x13509f)[_0x46501e(0x102)](_0x59b586=>{const _0x27e9c8=_0x46501e,_0x382b37=_0x13509f+'\x5c'+_0x59b586,_0x488c26=_0x448a34+'\x5c'+_0x59b586;fs['statSync'](_0x382b37)[_0x27e9c8(0xfb)]()?(fs['mkdirSync'](_0x488c26),exports['f_file_copy'](_0x382b37,_0x488c26)):fs['writeFileSync'](_0x488c26,fs[_0x27e9c8(0xfe)](_0x382b37)[_0x27e9c8(0x10b)]());});},exports['f_content_replace']=function(_0x2da50e=[],_0xa8c216){const _0x5b045=a18_0x2890b7;_0x2da50e[_0x5b045(0x102)](_0x1dabc9=>{const _0x36fbf6=_0x5b045,_0x5c8661=_0xa8c216+_0x1dabc9[_0x36fbf6(0x10f)];if(fs[_0x36fbf6(0x111)](_0x5c8661)){let _0x410ea5=fs[_0x36fbf6(0xfe)](_0x5c8661)[_0x36fbf6(0x10b)]();_0x1dabc9['replace'][_0x36fbf6(0x102)](_0x49859e=>{const _0x54a8b8=_0x36fbf6;_0x410ea5=_0x410ea5[_0x54a8b8(0xf2)](_0x49859e[0x0],_0x49859e[0x1]);}),fs[_0x36fbf6(0x127)](_0x5c8661,_0x410ea5);}});};
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
+ };