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,80 @@
1
- const a19_0xa9f3a8=a19_0x7b90;function a19_0x7b90(_0x223ebd,_0x273879){const _0x26bd13=a19_0x26bd();return a19_0x7b90=function(_0x7b904b,_0x52b5dd){_0x7b904b=_0x7b904b-0x18b;let _0x5173f3=_0x26bd13[_0x7b904b];return _0x5173f3;},a19_0x7b90(_0x223ebd,_0x273879);}(function(_0x3b105e,_0x66696){const _0x437206=a19_0x7b90,_0x3a87aa=_0x3b105e();while(!![]){try{const _0x4c7807=parseInt(_0x437206(0x195))/0x1*(-parseInt(_0x437206(0x1b3))/0x2)+-parseInt(_0x437206(0x1ac))/0x3+parseInt(_0x437206(0x1a8))/0x4+-parseInt(_0x437206(0x19f))/0x5+parseInt(_0x437206(0x18c))/0x6+parseInt(_0x437206(0x1b1))/0x7*(-parseInt(_0x437206(0x1b2))/0x8)+-parseInt(_0x437206(0x1a2))/0x9*(-parseInt(_0x437206(0x1ad))/0xa);if(_0x4c7807===_0x66696)break;else _0x3a87aa['push'](_0x3a87aa['shift']());}catch(_0x4bb841){_0x3a87aa['push'](_0x3a87aa['shift']());}}}(a19_0x26bd,0x8b97c));function a19_0x26bd(){const _0x23edf0=['then','application','forEach','35iZMUVp','1385072HmWZeM','2074874kvXipQ','routerPath','5730504DZqfIs','resolve','fileType','toString','/application','parse','CreatePaths','\x27,\x20component:\x20()\x20=>\x20import(\x27','{\x20path:\x20\x27','1vIoFPz','length','join','map','exports','./vessel/src','./project','readFileSync','path','writeFileSync','5072710HkUZcx','file','region','18POwdMG','concat','split','items','pathAdr','\x27)\x20}','465584XjLUVW','router','DeepScanner','push','1408683kPCueb','14437510IRJfqk'];a19_0x26bd=function(){return _0x23edf0;};return a19_0x26bd();}const fs=require('fs'),path=require(a19_0xa9f3a8(0x19d)),utils=require('./util.js');let projectPath='',vesselPath='',commandArr=[];const fromFileData={},applicationJson={};module[a19_0xa9f3a8(0x199)]=(_0x2b8536,_0x2dab87)=>{const _0x16019e=a19_0xa9f3a8;commandArr=_0x2b8536[_0x16019e(0x1a4)](':'),projectPath=path['resolve'](_0x16019e(0x19b)),vesselPath=path[_0x16019e(0x18d)](_0x16019e(0x19a));let _0x13c8c6=vesselPath;_0x2dab87==='mp'&&(_0x13c8c6=vesselPath+_0x16019e(0x190),utils[_0x16019e(0x192)](vesselPath,[_0x16019e(0x1af)]));const _0x4557f2=commandArr[0x1],_0x2f8e0a=JSON[_0x16019e(0x191)](fs[_0x16019e(0x19c)](projectPath+'/'+_0x4557f2+'/setting.json')[_0x16019e(0x18f)]());TileItems(_0x2f8e0a[_0x16019e(0x1a5)],()=>{const _0x4be609=_0x16019e;fromFileData[_0x4be609(0x1a9)][_0x4be609(0x1b0)](_0x535f8c=>{const _0x51b761=_0x4be609,_0x4d7ae8=_0x535f8c[_0x51b761(0x1a6)][_0x51b761(0x1a4)](_0x535f8c[_0x51b761(0x1a1)]),_0x297a52=_0x4d7ae8[0x1][_0x51b761(0x1a4)]('/'),_0x3851c8=_0x297a52[0x1];!applicationJson[_0x3851c8]&&(applicationJson[_0x3851c8]={'routerConfig':[],'routerPath':[]});applicationJson[_0x3851c8]['routerConfig'][_0x51b761(0x1ab)](_0x51b761(0x194)+_0x535f8c['path']+_0x51b761(0x193)+_0x535f8c[_0x51b761(0x1a0)]+_0x51b761(0x1a7)),applicationJson[_0x3851c8][_0x51b761(0x18b)]['push'](_0x535f8c[_0x51b761(0x19d)]);let _0x4f67e5=_0x297a52[_0x51b761(0x197)]('/');const _0x9c2291=_0x4f67e5[_0x51b761(0x1a4)]('/');utils[_0x51b761(0x192)](_0x13c8c6,_0x9c2291['slice'](0x0,_0x9c2291[_0x51b761(0x196)]-0x1))[_0x51b761(0x1ae)](()=>{const _0x48cbe9=_0x51b761,_0x45f52e=fs[_0x48cbe9(0x19c)](_0x535f8c[_0x48cbe9(0x1a6)])[_0x48cbe9(0x18f)]();fs[_0x48cbe9(0x19e)](vesselPath+'/'+_0x4f67e5,_0x45f52e);});});});};function TileItems(_0x6b065f,_0x3c5159){const _0x3174ec=a19_0xa9f3a8;_0x6b065f[_0x3174ec(0x1b0)]((_0x137cd9,_0x4d2a6c)=>{const _0x2673bf=_0x3174ec,_0x397f25=_0x137cd9['region'];_0x137cd9['from'][_0x2673bf(0x1b0)]((_0x4774ad,_0x329e79)=>{const _0x47d245=_0x2673bf,_0x1e570=[];utils[_0x47d245(0x1aa)](projectPath+'/'+_0x397f25+'/'+_0x4774ad[_0x47d245(0x1a0)],_0x1e570);const _0xeb7cd9=_0x1e570[_0x47d245(0x198)](_0x53565d=>({'region':_0x397f25,'pathAdr':_0x53565d,..._0x4774ad}));!fromFileData[_0x4774ad[_0x47d245(0x18e)]]?fromFileData[_0x4774ad[_0x47d245(0x18e)]]=_0xeb7cd9:fromFileData[_0x4774ad['fileType']]=fromFileData[_0x4774ad['fileType']][_0x47d245(0x1a3)](_0xeb7cd9),_0x4d2a6c===_0x6b065f['length']-0x1&&_0x329e79===_0x137cd9['from'][_0x47d245(0x196)]-0x1&&_0x3c5159();});});}
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const utils = require('./util.js');
4
+
5
+ //项目路径
6
+ let projectPath = '';
7
+ //项目脚手架路径
8
+ let vesselPath = '';
9
+ //input传入参数 指令:地区:环境 start:chongqing:dev
10
+ let commandArr = [];
11
+ //application数据
12
+ const fromFileData = {};
13
+ const applicationJson = {};
14
+
15
+ /**
16
+ * input 指令:地区:环境 start:chongqing:dev
17
+ */
18
+ module.exports = (input, source) => {
19
+ commandArr = input.split(':');
20
+ projectPath = path.resolve('./project');
21
+ vesselPath = path.resolve('./vessel/src');
22
+ let applicationPath = vesselPath;
23
+ if (source === 'mp') {
24
+ applicationPath = vesselPath + '/application';
25
+ utils.CreatePaths(vesselPath, ['application']);
26
+ }
27
+ const inputRegion = commandArr[1];
28
+ const settingJson = JSON.parse(fs.readFileSync(`${projectPath}/${inputRegion}/setting.json`).toString());
29
+ TileItems(settingJson.items, () => {
30
+
31
+ fromFileData.router.forEach(fromItem => {
32
+ const itemPathArr = fromItem.pathAdr.split(fromItem.region);
33
+ const filePathArr = itemPathArr[1].split('/');
34
+ const application = filePathArr[1];
35
+ if (!applicationJson[application]) {
36
+ applicationJson[application] = {
37
+ routerConfig: [],
38
+ routerPath: []
39
+ };
40
+ }
41
+ applicationJson[application].routerConfig.push(`{ path: '${fromItem.path}', component: () => import('${fromItem.file}') }`);
42
+ applicationJson[application].routerPath.push(fromItem.path);
43
+
44
+ let applicationStr = filePathArr.join('/');
45
+
46
+ const strArr = applicationStr.split('/');
47
+ utils.CreatePaths(applicationPath, strArr.slice(0, strArr.length - 1)).then(() => {
48
+ const fileContent = fs.readFileSync(fromItem.pathAdr).toString();
49
+ fs.writeFileSync(`${vesselPath}/${applicationStr}`, fileContent);
50
+ });
51
+
52
+ });
53
+
54
+ });
55
+ };
56
+
57
+ /**
58
+ * 平铺,展开所有路径
59
+ * @param items
60
+ * @param cb
61
+ * @constructor
62
+ */
63
+ function TileItems (items, cb) {
64
+ items.forEach((item, index) => {
65
+ const region = item.region;
66
+ item.from.forEach((from, fromIndex) => {
67
+ const pathArr = [];
68
+ utils.DeepScanner(projectPath + '/' + region + '/' + from.file, pathArr);
69
+ const newPathArr = pathArr.map(pathItem => ({ region, pathAdr: pathItem, ...from }));
70
+ if (!fromFileData[from.fileType]) {
71
+ fromFileData[from.fileType] = newPathArr;
72
+ } else {
73
+ fromFileData[from.fileType] = fromFileData[from.fileType].concat(newPathArr);
74
+ }
75
+ if (index === items.length - 1 && fromIndex === item.from.length - 1) {
76
+ cb();
77
+ }
78
+ });
79
+ })
80
+ }
@@ -1 +1,94 @@
1
- 'use strict';function a20_0x1b14(){const _0x51b4a6=['application','15189636OpJdWx','/api/v4/projects/','-master-','unlinkSync','/repository/archive.zip?private_token=','8zGiFkk','common','jjbAssembly','return\x20process.env;','1395796JmPcIW','common\x5cdva\x5cautomatic\x5c','request','G4HJRsHr9D7Ssmixegw2','6POpelS','FT3pKzxpRynFkmddJ9Bs','http://192.168.1.242:10985','createWriteStream','existsSync','common\x5cdva\x5cautomatic','tmpdir','\x5csrc','3237920lSvNOz','uncompress','\x5ccli.dva.register.spa.txt','\x5ccli.dva.router.spa.txt','27mrbkJy','\x5ccommon\x5cdva\x5cautomatic\x5crouter.js','2UCGrdW','const\x20relation\x20=\x20require(\x27~/enumerate/menu\x27).default;','projectId','close','error','&ref=master','6859795qneotZ','path','log','CopyFolder','forEach','\x5ccommon\x5cdva\x5cautomatic\x5cregister.js','DeleteDirAllFile','writeFileSync','resolve','toString','token','then','./util','pipe','373345dExwvW','529476bSjVOi','readdirSync','return\x20__planA();','readFileSync','statSync','2686716stSLlM','localName','replace','zip','【Error】:\x20当前目录不存在src子目录,无法完成pull操作。','mkdirSync'];a20_0x1b14=function(){return _0x51b4a6;};return a20_0x1b14();}const a20_0x12055d=a20_0xb776;(function(_0x246af6,_0x4699ec){const _0x238f24=a20_0xb776,_0x4c4917=_0x246af6();while(!![]){try{const _0x5c7508=parseInt(_0x238f24(0x116))/0x1*(-parseInt(_0x238f24(0x12b))/0x2)+-parseInt(_0x238f24(0x108))/0x3*(-parseInt(_0x238f24(0x104))/0x4)+parseInt(_0x238f24(0x11c))/0x5+-parseInt(_0x238f24(0x130))/0x6+parseInt(_0x238f24(0x12a))/0x7*(parseInt(_0x238f24(0x13c))/0x8)+-parseInt(_0x238f24(0x114))/0x9*(-parseInt(_0x238f24(0x110))/0xa)+-parseInt(_0x238f24(0x137))/0xb;if(_0x5c7508===_0x4699ec)break;else _0x4c4917['push'](_0x4c4917['shift']());}catch(_0x117199){_0x4c4917['push'](_0x4c4917['shift']());}}}(a20_0x1b14,0xb3cae));const fs=require('fs'),os=require('os'),path=require(a20_0x12055d(0x11d)),utils=require(a20_0x12055d(0x128)),request=require(a20_0x12055d(0x106)),compressing=require('compressing'),GIT_TEMP_DIR=a20_0x12055d(0x102),GIT_HOST=a20_0x12055d(0x10a),CLOUD_PROJECT={'common':{'token':a20_0x12055d(0x107),'projectId':0x117,'localName':a20_0x12055d(0x101)},'react-admin-component':{'token':a20_0x12055d(0x109),'projectId':0x154,'localName':'components'}};function a20_0xb776(_0x5c6edc,_0x55056b){const _0x1b14d8=a20_0x1b14();return a20_0xb776=function(_0xb77699,_0x507d06){_0xb77699=_0xb77699-0x101;let _0x4ffcb4=_0x1b14d8[_0xb77699];return _0x4ffcb4;},a20_0xb776(_0x5c6edc,_0x55056b);}module['exports']=_0x48c10e=>{const _0x35841e=a20_0x12055d,_0xa90718=_0x48c10e,_0x132ff0=path[_0x35841e(0x124)]('./');try{if(fs[_0x35841e(0x12f)](_0x132ff0+'\x5csrc')){const _0x724ec7=_0x132ff0+_0x35841e(0x10f),_0x173058=CLOUD_PROJECT[_0xa90718]||undefined;if(_0x173058){const _0xe61726=os[_0x35841e(0x10e)](),_0x370cc8=_0xe61726+('/'+GIT_TEMP_DIR+'/'+_0xa90718+'.zip'),_0x905dd=_0xe61726+'/'+GIT_TEMP_DIR+'/unzip/';utils['DeleteDirAllFile'](_0xe61726+'/'+GIT_TEMP_DIR,()=>{const _0x59e187=_0x35841e;fs[_0x59e187(0x135)](_0xe61726+'/'+GIT_TEMP_DIR);let _0x56b7d2=fs[_0x59e187(0x10b)](_0x370cc8);request(GIT_HOST+_0x59e187(0x138)+_0x173058[_0x59e187(0x118)]+_0x59e187(0x13b)+_0x173058[_0x59e187(0x126)]+_0x59e187(0x11b))[_0x59e187(0x129)](_0x56b7d2)['on'](_0x59e187(0x119),()=>{const _0x26cfae=_0x59e187;fs[_0x26cfae(0x135)](_0x905dd),compressing[_0x26cfae(0x133)][_0x26cfae(0x111)](_0x370cc8,_0x905dd)[_0x26cfae(0x127)](()=>{setTimeout(()=>{const _0x36d8c6=a20_0xb776,_0x540a05=fs[_0x36d8c6(0x12c)](_0x905dd);_0x540a05[_0x36d8c6(0x120)](_0x315d60=>{const _0x3b20f5=_0x36d8c6;if(_0x315d60['indexOf'](_0x3b20f5(0x139))!==-0x1){const _0x70e0e3=_0x724ec7+'\x5c'+_0x173058[_0x3b20f5(0x131)];utils[_0x3b20f5(0x122)](_0x70e0e3,()=>{const _0x13fad6=_0x3b20f5;fs[_0x13fad6(0x135)](_0x70e0e3),utils[_0x13fad6(0x11f)](_0x905dd+_0x315d60,_0x70e0e3),setTimeout(()=>{const _0x3aa2c8=_0x13fad6,_0x507cc5=fs[_0x3aa2c8(0x10c)](_0x724ec7+'\x5c'+_0x3aa2c8(0x136));if(!_0x507cc5){const _0x41aa05=_0x724ec7+'\x5c'+'common\x5ctools\x5cindex.js',_0x30ce51=_0x724ec7+'\x5c'+'common\x5cwebsite\x5cindex.js';let _0x475c49=fs[_0x3aa2c8(0x12e)](_0x41aa05)[_0x3aa2c8(0x125)](),_0x464758=fs[_0x3aa2c8(0x12e)](_0x30ce51)[_0x3aa2c8(0x125)]();_0x475c49=_0x475c49[_0x3aa2c8(0x132)](_0x3aa2c8(0x12d),_0x3aa2c8(0x103)),_0x464758=_0x464758[_0x3aa2c8(0x132)](/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,_0x3aa2c8(0x117)),fs[_0x3aa2c8(0x123)](_0x41aa05,_0x475c49),fs[_0x3aa2c8(0x123)](_0x30ce51,_0x464758),fs[_0x3aa2c8(0x123)](_0x724ec7+_0x3aa2c8(0x115),fs[_0x3aa2c8(0x12e)](__dirname+_0x3aa2c8(0x113))['toString']()),fs[_0x3aa2c8(0x123)](_0x724ec7+_0x3aa2c8(0x121),fs[_0x3aa2c8(0x12e)](__dirname+_0x3aa2c8(0x112))[_0x3aa2c8(0x125)]());}else fs['exists'](_0x724ec7+'\x5c'+'common\x5cdva\x5cautomatic\x5cindex.js',_0x2d0760=>{const _0x364409=_0x3aa2c8;_0x2d0760&&(fs[_0x364409(0x12c)](_0x724ec7+'\x5c'+_0x364409(0x10d))[_0x364409(0x120)](_0x2331e7=>{const _0x482b6c=_0x364409;fs[_0x482b6c(0x13a)](_0x724ec7+'\x5c'+_0x482b6c(0x105)+_0x2331e7);}),fs['rmdirSync'](_0x724ec7+'\x5c'+'common\x5cdva\x5cautomatic'));});},0x3e8);});}}),console[_0x36d8c6(0x11e)](_0xa90718+'-文件下载完毕');},0x7d0);});});});}else console[_0x35841e(0x11a)]('【Error】:\x20未获取到项目\x20'+_0xa90718);}}catch(_0x52a4c7){console[_0x35841e(0x11a)](_0x35841e(0x134));}};
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const utils = require('./util');
7
+ const request = require('request');
8
+ const compressing = require('compressing');
9
+
10
+ //临时存放目录
11
+ const GIT_TEMP_DIR = 'jjbAssembly';
12
+ //GIT仓库
13
+ const GIT_HOST = 'http://192.168.1.242:10985';
14
+ //项目列表,后期可存库
15
+ const CLOUD_PROJECT = {
16
+ 'common': {
17
+ token: 'G4HJRsHr9D7Ssmixegw2',
18
+ projectId: 279,
19
+ localName: 'common'
20
+ },
21
+ 'react-admin-component': {
22
+ token: 'FT3pKzxpRynFkmddJ9Bs',
23
+ projectId: 340,
24
+ localName: 'components'
25
+ }
26
+ };
27
+
28
+ module.exports = input => {
29
+ const dirName = input;
30
+ const currDir = path.resolve('./');
31
+ try {
32
+ if (fs.statSync(currDir + '\\src')) {
33
+ const srcDir = currDir + '\\src';
34
+ const cloudObj = CLOUD_PROJECT[ dirName ] || undefined;
35
+ if (cloudObj) {
36
+ const tmpDir = os.tmpdir();
37
+ const dirPath = tmpDir + `/${GIT_TEMP_DIR}/${dirName}.zip`;
38
+ const dirUnzip = `${tmpDir}/${GIT_TEMP_DIR}/unzip/`;
39
+ utils.DeleteDirAllFile(`${tmpDir}/${GIT_TEMP_DIR}`, () => {
40
+ fs.mkdirSync(`${tmpDir}/${GIT_TEMP_DIR}`);
41
+ let stream = fs.createWriteStream(dirPath);
42
+ request(`${GIT_HOST}/api/v4/projects/${cloudObj.projectId}/repository/archive.zip?private_token=${cloudObj.token}&ref=master`).pipe(stream)
43
+ .on('close', () => {
44
+ fs.mkdirSync(dirUnzip);
45
+ compressing.zip.uncompress(dirPath, dirUnzip)
46
+ .then(() => {
47
+ setTimeout(() => {
48
+ const srcAll = fs.readdirSync(dirUnzip);
49
+ srcAll.forEach(dirName => {
50
+ if (dirName.indexOf('-master-') !== -1) {
51
+ const nowPath = srcDir + '\\' + cloudObj.localName;
52
+ utils.DeleteDirAllFile(nowPath, () => {
53
+ fs.mkdirSync(nowPath);
54
+ utils.CopyFolder(dirUnzip + dirName, nowPath);
55
+ setTimeout(() => {
56
+ const isMutilate = fs.existsSync(srcDir + '\\' + 'application');
57
+ if (!isMutilate) {
58
+ const commonToolsPath = srcDir + '\\' + 'common\\tools\\index.js';
59
+ const commonWebsitePath = srcDir + '\\' + 'common\\website\\index.js';
60
+ let commonToolsFile = fs.readFileSync(commonToolsPath).toString();
61
+ let commonWebsiteFile = fs.readFileSync(commonWebsitePath).toString();
62
+ commonToolsFile = commonToolsFile.replace('return __planA();', 'return process.env;');
63
+ commonWebsiteFile = commonWebsiteFile.replace(/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/, "const relation = require('~/enumerate/menu').default;");
64
+ fs.writeFileSync(commonToolsPath, commonToolsFile);
65
+ fs.writeFileSync(commonWebsitePath, commonWebsiteFile);
66
+ fs.writeFileSync(`${srcDir}\\common\\dva\\automatic\\router.js`, fs.readFileSync(`${__dirname}\\cli.dva.router.spa.txt`).toString());
67
+ fs.writeFileSync(`${srcDir}\\common\\dva\\automatic\\register.js`, fs.readFileSync(`${__dirname}\\cli.dva.register.spa.txt`).toString());
68
+ } else {
69
+ fs.exists(srcDir + '\\' + 'common\\dva\\automatic\\index.js', has => {
70
+ if (has) {
71
+ fs.readdirSync(srcDir + '\\' + 'common\\dva\\automatic').forEach(p => {
72
+ fs.unlinkSync(srcDir + '\\' + 'common\\dva\\automatic\\' + p);
73
+ });
74
+ fs.rmdirSync(srcDir + '\\' + 'common\\dva\\automatic');
75
+ }
76
+ });
77
+ }
78
+ }, 1000);
79
+ });
80
+ }
81
+ });
82
+ console.log(dirName + '-文件下载完毕');
83
+ }, 2000);
84
+ });
85
+ });
86
+ });
87
+ } else {
88
+ console.error('【Error】: 未获取到项目 ' + dirName);
89
+ }
90
+ }
91
+ } catch (e) {
92
+ console.error('【Error】: 当前目录不存在src子目录,无法完成pull操作。');
93
+ }
94
+ };
@@ -1 +1,377 @@
1
- 'use strict';const a21_0x837da3=a21_0x19fd;(function(_0x103fb9,_0x3c4519){const _0x337aec=a21_0x19fd,_0x455f1a=_0x103fb9();while(!![]){try{const _0x124c55=parseInt(_0x337aec(0x1b9))/0x1+parseInt(_0x337aec(0x191))/0x2+-parseInt(_0x337aec(0x19f))/0x3+-parseInt(_0x337aec(0x1b5))/0x4+parseInt(_0x337aec(0x169))/0x5+-parseInt(_0x337aec(0x1a4))/0x6+-parseInt(_0x337aec(0x166))/0x7*(-parseInt(_0x337aec(0x1a6))/0x8);if(_0x124c55===_0x3c4519)break;else _0x455f1a['push'](_0x455f1a['shift']());}catch(_0x2585be){_0x455f1a['push'](_0x455f1a['shift']());}}}(a21_0x11a7,0x8ba99));const fs=require('fs'),os=require('os'),path=require(a21_0x837da3(0x17b)),utils=require(a21_0x837da3(0x17f)),request=require(a21_0x837da3(0x17c)),compressing=require(a21_0x837da3(0x192)),GIT_HOST=a21_0x837da3(0x184),GIT_TEMP_DIR=a21_0x837da3(0x190),CLOUD_PROJECT={'common':{'token':a21_0x837da3(0x1b1),'projectId':0x117,'localName':a21_0x837da3(0x1ad)},'react-admin-component':{'token':'FT3pKzxpRynFkmddJ9Bs','projectId':0x154,'localName':'components'}},COMMON_CONTENT_NOR_REPLACE=[{'path':a21_0x837da3(0x193),'replace':[[a21_0x837da3(0x18a),'jjb-react-admin-component']]},{'path':a21_0x837da3(0x181),'replace':[[/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,a21_0x837da3(0x1ac)],[a21_0x837da3(0x18a),a21_0x837da3(0x198)]]}],COMMON_CONTENT_SPA_REPLACE=[{'path':a21_0x837da3(0x193),'replace':[['return\x20__planA();',a21_0x837da3(0x179)]]}],COMMON_CONTENT_MICRO_REPLACE=[{'path':a21_0x837da3(0x193),'replace':[['return\x20__planA();',a21_0x837da3(0x19b)]]}],COMPONENTS_CONTENT_REPLACE=[{'path':'\x5cEditor\x5cindex.js','replace':[[a21_0x837da3(0x1b6),'jjb-common/http'],[a21_0x837da3(0x196),a21_0x837da3(0x182)],[a21_0x837da3(0x160),a21_0x837da3(0x16a)]]},{'path':'\x5cRejectText\x5cindex.js','replace':[['common/color',a21_0x837da3(0x16e)]]},{'path':a21_0x837da3(0x16d),'replace':[[a21_0x837da3(0x160),'jjb-common/tools']]},{'path':a21_0x837da3(0x1a9),'replace':[[a21_0x837da3(0x1b6),a21_0x837da3(0x199)],[a21_0x837da3(0x160),a21_0x837da3(0x16a)]]},{'path':a21_0x837da3(0x180),'replace':[[a21_0x837da3(0x1b6),'jjb-common/http'],[a21_0x837da3(0x160),'jjb-common/tools']]},{'path':a21_0x837da3(0x161),'replace':[['common/http','jjb-common/http'],[a21_0x837da3(0x160),'jjb-common/tools']]},{'path':a21_0x837da3(0x163),'replace':[['common/color',a21_0x837da3(0x16e)]]},{'path':a21_0x837da3(0x15e),'replace':[[a21_0x837da3(0x160),a21_0x837da3(0x16a)]]},{'path':a21_0x837da3(0x18e),'replace':[[a21_0x837da3(0x1a3),a21_0x837da3(0x1b8)],['common/tools',a21_0x837da3(0x16a)]]}];function uid(){const _0x3de325=a21_0x837da3;return Math[_0x3de325(0x170)]()['toString']()[_0x3de325(0x1af)](0x2);}module[a21_0x837da3(0x195)]=_0x2fd886=>{const _0x4c71e2=a21_0x837da3,_0x5e2da3=path[_0x4c71e2(0x173)]('./'),_0x16c77c=_0x4c71e2(0x1b7)+_0x2fd886,_0x1900c9='1.0.0',_0x25bcc7=_0x5e2da3+_0x4c71e2(0x194),_0x4cbccd='template_'+uid(),_0x1ed9bd=__dirname+'\x5c'+_0x4cbccd,_0x3d9ca6=_0x5e2da3+'\x5cpackage.json',_0x55f565=_0x5e2da3+_0x4c71e2(0x17d)+_0x2fd886;try{if(fs[_0x4c71e2(0x1ab)](_0x25bcc7)){const _0x3b3888=CLOUD_PROJECT[_0x2fd886]||undefined;if(_0x3b3888){const _0x270c0c=os['tmpdir'](),_0xb94a05=_0x270c0c+'/'+GIT_TEMP_DIR+'/'+_0x2fd886+'.zip',_0x1a2361=_0x270c0c+'/'+GIT_TEMP_DIR+'/unzip/';utils['DeleteDirAllFile'](_0x270c0c+'/'+GIT_TEMP_DIR,()=>{const _0x3c3a36=_0x4c71e2;fs['mkdirSync'](_0x270c0c+'/'+GIT_TEMP_DIR);const _0x4231a4=fs[_0x3c3a36(0x18b)](_0xb94a05);request(GIT_HOST+_0x3c3a36(0x1ae)+_0x3b3888['projectId']+_0x3c3a36(0x1a1)+_0x3b3888[_0x3c3a36(0x1b4)]+'&ref=master')[_0x3c3a36(0x1a8)](_0x4231a4)['on'](_0x3c3a36(0x15f),()=>{const _0x207bd2=_0x3c3a36;fs[_0x207bd2(0x16b)](_0x1a2361),compressing[_0x207bd2(0x185)][_0x207bd2(0x186)](_0xb94a05,_0x1a2361)[_0x207bd2(0x19d)](()=>{setTimeout(()=>{const _0x1bd642=a21_0x19fd;fs[_0x1bd642(0x1a2)](_0x1a2361)[_0x1bd642(0x178)](_0x12dd99=>{const _0x37a7c7=_0x1bd642;_0x12dd99[_0x37a7c7(0x177)]('-master-')!==-0x1&&utils[_0x37a7c7(0x19a)](_0x25bcc7+'\x5c'+_0x3b3888[_0x37a7c7(0x16f)],()=>{const _0x3fd41c=_0x37a7c7;fs[_0x3fd41c(0x16b)](_0x1ed9bd),utils['CopyFolder'](_0x1a2361+_0x12dd99,_0x1ed9bd),setTimeout(()=>{const _0x1b7284=_0x3fd41c;if(_0x2fd886==='common'){const _0x467020=fs[_0x1b7284(0x1ab)](_0x25bcc7+'\x5capplication');if(_0x467020)rm_rf(_0x1ed9bd+_0x1b7284(0x1a5)),fs['rmdirSync'](_0x1ed9bd+_0x1b7284(0x1a5));else{if(get_project_type(_0x3d9ca6)===_0x1b7284(0x1a0))content_replace(COMMON_CONTENT_SPA_REPLACE,_0x1ed9bd),fs[_0x1b7284(0x188)](_0x1ed9bd+_0x1b7284(0x18d),fs['readFileSync'](__dirname+_0x1b7284(0x19e))[_0x1b7284(0x1a7)]()),fs[_0x1b7284(0x188)](_0x1ed9bd+_0x1b7284(0x18c),fs[_0x1b7284(0x164)](__dirname+'\x5ccli.dva.register.spa.txt')[_0x1b7284(0x1a7)]());else get_project_type(_0x3d9ca6)===_0x1b7284(0x1b2)&&(content_replace(COMMON_CONTENT_MICRO_REPLACE,_0x1ed9bd),fs[_0x1b7284(0x188)](_0x1ed9bd+'\x5cdva\x5cautomatic\x5crouter.js',fs[_0x1b7284(0x164)](__dirname+_0x1b7284(0x176))[_0x1b7284(0x1a7)]()),fs['writeFileSync'](_0x1ed9bd+_0x1b7284(0x18c),fs[_0x1b7284(0x164)](__dirname+_0x1b7284(0x168))[_0x1b7284(0x1a7)]()));}content_replace(COMMON_CONTENT_NOR_REPLACE,_0x1ed9bd);}_0x2fd886===_0x1b7284(0x1aa)&&content_replace(COMPONENTS_CONTENT_REPLACE,_0x1ed9bd),rm_rf(_0x1ed9bd+_0x1b7284(0x183)),fs[_0x1b7284(0x1ab)](_0x1ed9bd+_0x1b7284(0x183))&&fs[_0x1b7284(0x18f)](_0x1ed9bd+_0x1b7284(0x183)),fs[_0x1b7284(0x1ab)](_0x1ed9bd+_0x1b7284(0x175))&&fs['unlinkSync'](_0x1ed9bd+_0x1b7284(0x175)),!fs[_0x1b7284(0x1ab)](_0x55f565)?fs[_0x1b7284(0x16b)](_0x55f565):rm_rf(_0x55f565),utils[_0x1b7284(0x197)](_0x1ed9bd,_0x55f565,()=>{const _0x2051c8=_0x1b7284;rm_rf(_0x1ed9bd),fs[_0x2051c8(0x18f)](_0x1ed9bd),create_package_json(_0x55f565,_0x16c77c,_0x1900c9),update_project_package_json(_0x3d9ca6,_0x16c77c,_0x1900c9),console['log'](_0x2051c8(0x17a)+_0x16c77c+'\x20v'+_0x1900c9);});},0x3e8);});});},0x7d0);});});});}else console['error'](_0x4c71e2(0x171)+_0x2fd886);}}catch(_0x5af31a){console['error']('【Error】:\x20当前目录不存在src子目录,无法完成pull操作。');}};function a21_0x19fd(_0x221218,_0x333e16){const _0x11a71b=a21_0x11a7();return a21_0x19fd=function(_0x19fdd3,_0x4053d8){_0x19fdd3=_0x19fdd3-0x15e;let _0x2b99f4=_0x11a71b[_0x19fdd3];return _0x2b99f4;},a21_0x19fd(_0x221218,_0x333e16);}function rm_rf(_0x3416b3){const _0x295bbb=a21_0x837da3;if(fs['existsSync'](_0x3416b3)){const _0x2a9f55=fs[_0x295bbb(0x1a2)](_0x3416b3);for(let _0x34cf68=0x0;_0x34cf68<_0x2a9f55[_0x295bbb(0x187)];_0x34cf68++){const _0xf0ea7d=_0x2a9f55[_0x34cf68],_0x475ab7=_0x3416b3+'/'+_0xf0ea7d;fs[_0x295bbb(0x1b0)](_0x475ab7)[_0x295bbb(0x167)]()?(rm_rf(_0x475ab7),fs[_0x295bbb(0x18f)](_0x475ab7)):fs[_0x295bbb(0x19c)](_0x475ab7);}}}function create_package_json(_0x4ddea6,_0x32b479,_0x20ddd6){const _0x4a09ba=a21_0x837da3;fs[_0x4a09ba(0x188)](_0x4ddea6+'\x5cpackage.json',_0x4a09ba(0x165)+_0x32b479+_0x4a09ba(0x16c)+_0x20ddd6+_0x4a09ba(0x1b3));}function get_project_type(_0x54900e){const _0x593057=a21_0x837da3,_0x195e4e=JSON[_0x593057(0x172)](fs[_0x593057(0x164)](_0x54900e)['toString']());return _0x195e4e[_0x593057(0x17e)];}function update_project_package_json(_0x322a48,_0x4e9603,_0x378316){const _0x29c8b6=a21_0x837da3,_0x56ee63=JSON[_0x29c8b6(0x172)](fs[_0x29c8b6(0x164)](_0x322a48)[_0x29c8b6(0x1a7)]());_0x56ee63[_0x29c8b6(0x162)][_0x4e9603]=_0x378316,fs[_0x29c8b6(0x188)](_0x322a48,JSON[_0x29c8b6(0x174)](_0x56ee63,null,0x2));}function content_replace(_0x5f56bd=[],_0x1deea2){const _0x448671=a21_0x837da3;_0x5f56bd[_0x448671(0x178)](_0x1f79a4=>{const _0x56fe2c=_0x448671,_0x35f6dc=_0x1deea2+_0x1f79a4[_0x56fe2c(0x17b)];if(fs['existsSync'](_0x35f6dc)){let _0x2b5919=fs[_0x56fe2c(0x164)](_0x35f6dc)[_0x56fe2c(0x1a7)]();_0x1f79a4[_0x56fe2c(0x189)][_0x56fe2c(0x178)](_0x1ac5e8=>{_0x2b5919=_0x2b5919['replace'](_0x1ac5e8[0x0],_0x1ac5e8[0x1]);}),fs[_0x56fe2c(0x188)](_0x35f6dc,_0x2b5919);}});}function a21_0x11a7(){const _0x56edd4=['random','【Error】:\x20未获取到项目\x20','parse','resolve','stringify','\x5c.gitignore','\x5ccli.dva.router.saas.txt','indexOf','forEach','return\x20process.env;','【已安装】:','path','request','\x5cnode_modules\x5cjjb-','projectType','./util','\x5cImageCropper\x5cindex.js','\x5cwebsite\x5cindex.js','jjb-common/crypto','\x5c.idea','http://192.168.1.242:10985','zip','uncompress','length','writeFileSync','replace','components','createWriteStream','\x5cdva\x5cautomatic\x5cregister.js','\x5cdva\x5cautomatic\x5crouter.js','\x5cRouterContainer\x5ccomponents\x5cNavigationTab\x5cindex.js','rmdirSync','jjbAssembly','1266406GmxKcf','compressing','\x5ctools\x5cindex.js','\x5csrc','exports','common/crypto','CopyFolder','jjb-react-admin-component','jjb-common/http','DeleteDirAllFile','return\x20process.env.app;','unlinkSync','then','\x5ccli.dva.router.spa.txt','2255871SCIYkR','spa','/repository/archive.zip?private_token=','readdirSync','common/website','511866dbBibA','\x5cdva\x5cautomatic','7976LcJTBT','toString','pipe','\x5cFileUploader\x5cindex.js','react-admin-component','existsSync','const\x20relation\x20=\x20require(\x27~/enumerate/menu\x27).default;','common','/api/v4/projects/','substr','statSync','G4HJRsHr9D7Ssmixegw2','micro-spa','\x22,\x22main\x22:\x20\x22index.js\x22}','token','3082696WadECo','common/http','jjb-','jjb-common/website','1042189YhDqDX','\x5cRouterContainer\x5cindex.js','close','common/tools','\x5cImageUploader\x5cindex.js','dependencies','\x5cPageHeaderBar\x5cindex.js','readFileSync','{\x22name\x22:\x22','938IsgJKN','isDirectory','\x5ccli.dva.register.saas.txt','1855045HSalbN','jjb-common/tools','mkdirSync','\x22,\x22version\x22:\x22','\x5cRouterMenu\x5cindex.js','jjb-common/color','localName'];a21_0x11a7=function(){return _0x56edd4;};return a21_0x11a7();}
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const utils = require('./util');
7
+ const request = require('request');
8
+ const compressing = require('compressing');
9
+
10
+ // GIT仓库
11
+ const GIT_HOST = 'http://192.168.1.242:10985';
12
+ // 临时存放目录
13
+ const GIT_TEMP_DIR = 'jjbAssembly';
14
+ // 项目列表,后期可存库
15
+ const CLOUD_PROJECT = {
16
+ 'common': {
17
+ token: 'G4HJRsHr9D7Ssmixegw2',
18
+ projectId: 279,
19
+ localName: 'common'
20
+ },
21
+ 'react-admin-component': {
22
+ token: 'FT3pKzxpRynFkmddJ9Bs',
23
+ projectId: 340,
24
+ localName: 'components'
25
+ }
26
+ };
27
+ // common 需要替换的文本(常规应用)
28
+ const COMMON_CONTENT_NOR_REPLACE = [
29
+ {
30
+ path: `\\tools\\index.js`,
31
+ replace: [
32
+ [
33
+ 'components',
34
+ 'jjb-react-admin-component'
35
+ ]
36
+ ]
37
+ },
38
+ {
39
+ path: `\\website\\index.js`,
40
+ replace: [
41
+ [
42
+ /const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,
43
+ 'const relation = require(\'~/enumerate/menu\').default;'
44
+ ],
45
+ [
46
+ 'components',
47
+ 'jjb-react-admin-component'
48
+ ]
49
+ ]
50
+ }
51
+ ];
52
+ // common 需要替换的文本(单应用)
53
+ const COMMON_CONTENT_SPA_REPLACE = [
54
+ {
55
+ path: `\\tools\\index.js`,
56
+ replace: [
57
+ [
58
+ 'return __planA();',
59
+ 'return process.env;'
60
+ ]
61
+ ]
62
+ }
63
+ ];
64
+ // common 需要替换的文本(微应用)
65
+ const COMMON_CONTENT_MICRO_REPLACE = [
66
+ {
67
+ path: `\\tools\\index.js`,
68
+ replace: [
69
+ [
70
+ 'return __planA();',
71
+ 'return process.env.app;'
72
+ ]
73
+ ]
74
+ }
75
+ ];
76
+ // react-admin-component 需要替换的文本
77
+ const COMPONENTS_CONTENT_REPLACE = [
78
+ {
79
+ path: `\\Editor\\index.js`,
80
+ replace: [
81
+ [
82
+ 'common/http',
83
+ 'jjb-common/http'
84
+ ],
85
+ [
86
+ 'common/crypto',
87
+ 'jjb-common/crypto'
88
+ ],
89
+ [
90
+ 'common/tools',
91
+ 'jjb-common/tools'
92
+ ]
93
+ ]
94
+ },
95
+ {
96
+ path: `\\RejectText\\index.js`,
97
+ replace: [
98
+ [
99
+ 'common/color',
100
+ 'jjb-common/color'
101
+ ]
102
+ ]
103
+ },
104
+ {
105
+ path: `\\RouterMenu\\index.js`,
106
+ replace: [
107
+ [
108
+ 'common/tools',
109
+ 'jjb-common/tools'
110
+ ]
111
+ ]
112
+ },
113
+ {
114
+ path: `\\FileUploader\\index.js`,
115
+ replace: [
116
+ [
117
+ 'common/http',
118
+ 'jjb-common/http'
119
+ ],
120
+ [
121
+ 'common/tools',
122
+ 'jjb-common/tools'
123
+ ]
124
+ ]
125
+ },
126
+ {
127
+ path: `\\ImageCropper\\index.js`,
128
+ replace: [
129
+ [
130
+ 'common/http',
131
+ 'jjb-common/http'
132
+ ],
133
+ [
134
+ 'common/tools',
135
+ 'jjb-common/tools'
136
+ ]
137
+ ]
138
+ },
139
+ {
140
+ path: `\\ImageUploader\\index.js`,
141
+ replace: [
142
+ [
143
+ 'common/http',
144
+ 'jjb-common/http'
145
+ ],
146
+ [
147
+ 'common/tools',
148
+ 'jjb-common/tools'
149
+ ]
150
+ ]
151
+ },
152
+ {
153
+ path: `\\PageHeaderBar\\index.js`,
154
+ replace: [
155
+ [
156
+ 'common/color',
157
+ 'jjb-common/color'
158
+ ]
159
+ ]
160
+ },
161
+ {
162
+ path: `\\RouterContainer\\index.js`,
163
+ replace: [
164
+ [
165
+ 'common/tools',
166
+ 'jjb-common/tools'
167
+ ]
168
+ ]
169
+ },
170
+ {
171
+ path: `\\RouterContainer\\components\\NavigationTab\\index.js`,
172
+ replace: [
173
+ [
174
+ 'common/website',
175
+ 'jjb-common/website'
176
+ ],
177
+ [
178
+ 'common/tools',
179
+ 'jjb-common/tools'
180
+ ]
181
+ ]
182
+ }
183
+ ];
184
+
185
+ /**
186
+ * @description 生成UID
187
+ * @returns {string}
188
+ */
189
+ function uid () {
190
+ return Math.random().toString().substr(2);
191
+ }
192
+
193
+ module.exports = input => {
194
+ /* 下发项目路径 */
195
+ const root = path.resolve('./');
196
+ /* 下发包名 */
197
+ const packageName = `jjb-${input}`;
198
+ /* 下发包版本 */
199
+ const packageVerson = '1.0.0';
200
+ /* 下发项目src路径 */
201
+ const srcFolderPath = `${root}\\src`;
202
+ /* 临时文件名称 */
203
+ const templateFolderName = `template_${uid()}`;
204
+ /* 临时文件路径 */
205
+ const templateFolderPath = `${__dirname}\\${templateFolderName}`;
206
+ /* 下发安装包package.json */
207
+ const rootPackageJsonPath = `${root}\\package.json`;
208
+ /* 安装包路径 */
209
+ const rootNodeModulesPackagePath = `${root}\\node_modules\\jjb-${input}`;
210
+ try {
211
+ if (fs.existsSync(srcFolderPath)) {
212
+ const cloudObj = CLOUD_PROJECT[ input ] || undefined;
213
+ if (cloudObj) {
214
+ const tmpDir = os.tmpdir();
215
+ const zipPath = `${tmpDir}/${GIT_TEMP_DIR}/${input}.zip`;
216
+ const zipFolder = `${tmpDir}/${GIT_TEMP_DIR}/unzip/`;
217
+ utils.DeleteDirAllFile(`${tmpDir}/${GIT_TEMP_DIR}`, () => {
218
+ fs.mkdirSync(`${tmpDir}/${GIT_TEMP_DIR}`);
219
+ const stream = fs.createWriteStream(zipPath);
220
+ request(`${GIT_HOST}/api/v4/projects/${cloudObj.projectId}/repository/archive.zip?private_token=${cloudObj.token}&ref=master`)
221
+ .pipe(stream)
222
+ .on('close', () => {
223
+ fs.mkdirSync(zipFolder);
224
+ compressing.zip.uncompress(zipPath, zipFolder)
225
+ .then(() => {
226
+ setTimeout(() => {
227
+ fs.readdirSync(zipFolder).forEach(dirName => {
228
+ if (dirName.indexOf('-master-') !== -1) {
229
+ /* 删除下载的文件 */
230
+ utils.DeleteDirAllFile(`${srcFolderPath}\\${cloudObj.localName}`, () => {
231
+ /* 创建临时文件夹 */
232
+ fs.mkdirSync(templateFolderPath);
233
+ /* 拷贝解压后的文件到临时文件夹 */
234
+ utils.CopyFolder(zipFolder + dirName, templateFolderPath);
235
+ setTimeout(() => {
236
+ /* 如果输入文件名是common */
237
+ if (input === 'common') {
238
+ /* 判断是否为多应用 */
239
+ const isMutilate = fs.existsSync(`${srcFolderPath}\\application`);
240
+ if (isMutilate) {
241
+ /* 多应用模式下需要删除automatic文件夹 */
242
+ rm_rf(`${templateFolderPath}\\dva\\automatic`);
243
+ fs.rmdirSync(`${templateFolderPath}\\dva\\automatic`);
244
+ } else {
245
+ if (get_project_type(rootPackageJsonPath) === 'spa') {
246
+ /* 替换操作 */
247
+ content_replace(COMMON_CONTENT_SPA_REPLACE, templateFolderPath);
248
+ fs.writeFileSync(`${templateFolderPath}\\dva\\automatic\\router.js`, fs.readFileSync(`${__dirname}\\cli.dva.router.spa.txt`).toString());
249
+ fs.writeFileSync(`${templateFolderPath}\\dva\\automatic\\register.js`, fs.readFileSync(`${__dirname}\\cli.dva.register.spa.txt`).toString());
250
+ } else if (get_project_type(rootPackageJsonPath) === 'micro-spa') {
251
+ content_replace(COMMON_CONTENT_MICRO_REPLACE, templateFolderPath);
252
+ fs.writeFileSync(`${templateFolderPath}\\dva\\automatic\\router.js`, fs.readFileSync(`${__dirname}\\cli.dva.router.saas.txt`).toString());
253
+ fs.writeFileSync(`${templateFolderPath}\\dva\\automatic\\register.js`, fs.readFileSync(`${__dirname}\\cli.dva.register.saas.txt`).toString());
254
+ }
255
+ }
256
+ /* 替换操作 */
257
+ content_replace(COMMON_CONTENT_NOR_REPLACE, templateFolderPath);
258
+ }
259
+ /* 如果输入文件名是react-admin-component */
260
+ if (input === 'react-admin-component') {
261
+ /* 替换操作 */
262
+ content_replace(COMPONENTS_CONTENT_REPLACE, templateFolderPath);
263
+ }
264
+ rm_rf(`${templateFolderPath}\\.idea`);
265
+ if (fs.existsSync(`${templateFolderPath}\\.idea`)) {
266
+ fs.rmdirSync(`${templateFolderPath}\\.idea`);
267
+ }
268
+ if (fs.existsSync(`${templateFolderPath}\\.gitignore`)) {
269
+ fs.unlinkSync(`${templateFolderPath}\\.gitignore`);
270
+ }
271
+ /* 如果文件夹不存在 */
272
+ if (!fs.existsSync(rootNodeModulesPackagePath)) {
273
+ // 创建文件夹
274
+ fs.mkdirSync(rootNodeModulesPackagePath);
275
+ } else {
276
+ // 删除旧文件
277
+ rm_rf(rootNodeModulesPackagePath);
278
+ }
279
+ /* 复制文件到下发项目node_modules */
280
+ utils.CopyFolder(templateFolderPath, rootNodeModulesPackagePath, () => {
281
+ /* 删除所有临时文件 */
282
+ rm_rf(templateFolderPath);
283
+ /* 删除临时文件夹 */
284
+ fs.rmdirSync(templateFolderPath);
285
+ /* 创建下发包package.json */
286
+ create_package_json(rootNodeModulesPackagePath, packageName, packageVerson);
287
+ /* 下发完成更新下发项目package.json */
288
+ update_project_package_json(rootPackageJsonPath, packageName, packageVerson);
289
+ /* 完成操作 */
290
+ console.log(`【已安装】:${packageName} v${packageVerson}`);
291
+ });
292
+ }, 1000);
293
+ });
294
+ }
295
+ });
296
+ }, 2000);
297
+ });
298
+ });
299
+ });
300
+ } else {
301
+ console.error(`【Error】: 未获取到项目 ${input}`);
302
+ }
303
+ }
304
+ } catch (e) {
305
+ console.error('【Error】: 当前目录不存在src子目录,无法完成pull操作。');
306
+ }
307
+ };
308
+
309
+ /**
310
+ * @description 删除全部
311
+ * @param path
312
+ */
313
+ function rm_rf (path) {
314
+ if (fs.existsSync(path)) {
315
+ const list = fs.readdirSync(path);
316
+ for (let i = 0; i < list.length; i++) {
317
+ const item = list[ i ];
318
+ const vPath = `${path}/${item}`;
319
+ if (fs.statSync(vPath).isDirectory()) {
320
+ rm_rf(vPath);
321
+ fs.rmdirSync(vPath);
322
+ } else {
323
+ fs.unlinkSync(vPath);
324
+ }
325
+ }
326
+ }
327
+ }
328
+
329
+ /**
330
+ * @description 创建package.json
331
+ * @param path {string} 路径
332
+ * @param name {string} 包名
333
+ * @param version {string} 版本
334
+ */
335
+ function create_package_json (path, name, version) {
336
+ fs.writeFileSync(`${path}\\package.json`, `{"name":"${name}","version":"${version}","main": "index.js"}`);
337
+ }
338
+
339
+ /**
340
+ * @description 获取项目类型
341
+ * @param path {string} 路径
342
+ * @returns {string}
343
+ */
344
+ function get_project_type (path) {
345
+ const packageJSONFile = JSON.parse(fs.readFileSync(path).toString());
346
+ return packageJSONFile.projectType;
347
+ }
348
+
349
+ /**
350
+ * @description 更新项目package.json文件
351
+ * @param path {string} 路径
352
+ * @param name {string} 包名
353
+ * @param version {string} 版本
354
+ */
355
+ function update_project_package_json (path, name, version) {
356
+ const packageJSONFile = JSON.parse(fs.readFileSync(path).toString());
357
+ packageJSONFile.dependencies[ name ] = version;
358
+ fs.writeFileSync(path, JSON.stringify(packageJSONFile, null, 2));
359
+ }
360
+
361
+ /**
362
+ * @description 替换文件操作
363
+ * @param source {[]} 替换源
364
+ * @param root {string} 路径
365
+ */
366
+ function content_replace (source = [], root) {
367
+ source.forEach(item => {
368
+ const path = root + item.path;
369
+ if (fs.existsSync(path)) {
370
+ let content = fs.readFileSync(path).toString();
371
+ item.replace.forEach(rep => {
372
+ content = content.replace(rep[ 0 ], rep[ 1 ]);
373
+ });
374
+ fs.writeFileSync(path, content);
375
+ }
376
+ });
377
+ }