jjb-cmd 2.2.1 → 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
- function a19_0x8276(_0xe79271,_0xa1cbfa){const _0x4ab47f=a19_0x4ab4();return a19_0x8276=function(_0x827641,_0x4d9d91){_0x827641=_0x827641-0x18d;let _0x9d612d=_0x4ab47f[_0x827641];return _0x9d612d;},a19_0x8276(_0xe79271,_0xa1cbfa);}const a19_0x13ad0d=a19_0x8276;function a19_0x4ab4(){const _0x1d6254=['split','parse','1374544ebYbym','routerConfig','fileType','writeFileSync','3766565RGFXLh','./util.js','146342iCKYki','slice','application','join','toString','router','then','file','{\x20path:\x20\x27','1946856zvkeyf','pathAdr','readFileSync','from','length','/application','790CdgqCr','73674JAqGSK','6IIiujc','./vessel/src','exports','\x27)\x20}','path','resolve','1435350OErimQ','./project','region','32ZBOoCE','items','forEach','push','map','CreatePaths','552937NASbGC'];a19_0x4ab4=function(){return _0x1d6254;};return a19_0x4ab4();}(function(_0x188234,_0x32fa48){const _0x2fcb91=a19_0x8276,_0x1c839c=_0x188234();while(!![]){try{const _0x3e9ba2=parseInt(_0x2fcb91(0x1b2))/0x1+-parseInt(_0x2fcb91(0x192))/0x2*(parseInt(_0x2fcb91(0x1a3))/0x3)+parseInt(_0x2fcb91(0x1b5))/0x4+-parseInt(_0x2fcb91(0x190))/0x5+parseInt(_0x2fcb91(0x19b))/0x6+-parseInt(_0x2fcb91(0x1a9))/0x7*(-parseInt(_0x2fcb91(0x1ac))/0x8)+-parseInt(_0x2fcb91(0x1a2))/0x9*(parseInt(_0x2fcb91(0x1a1))/0xa);if(_0x3e9ba2===_0x32fa48)break;else _0x1c839c['push'](_0x1c839c['shift']());}catch(_0x4c75d7){_0x1c839c['push'](_0x1c839c['shift']());}}}(a19_0x4ab4,0x78d34));const fs=require('fs'),path=require(a19_0x13ad0d(0x1a7)),utils=require(a19_0x13ad0d(0x191));let projectPath='',vesselPath='',commandArr=[];const fromFileData={},applicationJson={};module[a19_0x13ad0d(0x1a5)]=(_0x3a0348,_0x35bdca)=>{const _0x5b857c=a19_0x13ad0d;commandArr=_0x3a0348['split'](':'),projectPath=path[_0x5b857c(0x1a8)](_0x5b857c(0x1aa)),vesselPath=path[_0x5b857c(0x1a8)](_0x5b857c(0x1a4));let _0x375e40=vesselPath;_0x35bdca==='mp'&&(_0x375e40=vesselPath+_0x5b857c(0x1a0),utils[_0x5b857c(0x1b1)](vesselPath,[_0x5b857c(0x194)]));const _0x1ded62=commandArr[0x1],_0x154ca7=JSON[_0x5b857c(0x1b4)](fs[_0x5b857c(0x19d)](projectPath+'/'+_0x1ded62+'/setting.json')[_0x5b857c(0x196)]());TileItems(_0x154ca7[_0x5b857c(0x1ad)],()=>{const _0x1c5768=_0x5b857c;fromFileData[_0x1c5768(0x197)][_0x1c5768(0x1ae)](_0x4fb1e7=>{const _0xa1a1ff=_0x1c5768,_0xe4c7ed=_0x4fb1e7[_0xa1a1ff(0x19c)][_0xa1a1ff(0x1b3)](_0x4fb1e7[_0xa1a1ff(0x1ab)]),_0x225a55=_0xe4c7ed[0x1][_0xa1a1ff(0x1b3)]('/'),_0x4fb0c8=_0x225a55[0x1];!applicationJson[_0x4fb0c8]&&(applicationJson[_0x4fb0c8]={'routerConfig':[],'routerPath':[]});applicationJson[_0x4fb0c8][_0xa1a1ff(0x18d)][_0xa1a1ff(0x1af)](_0xa1a1ff(0x19a)+_0x4fb1e7['path']+'\x27,\x20component:\x20()\x20=>\x20import(\x27'+_0x4fb1e7[_0xa1a1ff(0x199)]+_0xa1a1ff(0x1a6)),applicationJson[_0x4fb0c8]['routerPath']['push'](_0x4fb1e7[_0xa1a1ff(0x1a7)]);let _0x37e098=_0x225a55[_0xa1a1ff(0x195)]('/');const _0x4b2c67=_0x37e098['split']('/');utils[_0xa1a1ff(0x1b1)](_0x375e40,_0x4b2c67[_0xa1a1ff(0x193)](0x0,_0x4b2c67[_0xa1a1ff(0x19f)]-0x1))[_0xa1a1ff(0x198)](()=>{const _0x59c586=_0xa1a1ff,_0xbbb1cd=fs[_0x59c586(0x19d)](_0x4fb1e7[_0x59c586(0x19c)])[_0x59c586(0x196)]();fs[_0x59c586(0x18f)](vesselPath+'/'+_0x37e098,_0xbbb1cd);});});});};function TileItems(_0xe5c86f,_0x4c81e7){const _0xe56d43=a19_0x13ad0d;_0xe5c86f[_0xe56d43(0x1ae)]((_0xcabcbc,_0x2db69a)=>{const _0x2cdaee=_0xe56d43,_0x3b70f8=_0xcabcbc[_0x2cdaee(0x1ab)];_0xcabcbc[_0x2cdaee(0x19e)][_0x2cdaee(0x1ae)]((_0x1ab917,_0x12f9b7)=>{const _0x369039=_0x2cdaee,_0x5665e7=[];utils['DeepScanner'](projectPath+'/'+_0x3b70f8+'/'+_0x1ab917[_0x369039(0x199)],_0x5665e7);const _0x45b258=_0x5665e7[_0x369039(0x1b0)](_0xf568aa=>({'region':_0x3b70f8,'pathAdr':_0xf568aa,..._0x1ab917}));!fromFileData[_0x1ab917['fileType']]?fromFileData[_0x1ab917[_0x369039(0x18e)]]=_0x45b258:fromFileData[_0x1ab917[_0x369039(0x18e)]]=fromFileData[_0x1ab917['fileType']]['concat'](_0x45b258),_0x2db69a===_0xe5c86f['length']-0x1&&_0x12f9b7===_0xcabcbc[_0x369039(0x19e)][_0x369039(0x19f)]-0x1&&_0x4c81e7();});});}
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';const a20_0x1de7dc=a20_0xf283;function a20_0xf283(_0x286cc5,_0x53046a){const _0x60c145=a20_0x60c1();return a20_0xf283=function(_0xf28316,_0x11bff7){_0xf28316=_0xf28316-0x83;let _0x20e1b6=_0x60c145[_0xf28316];return _0x20e1b6;},a20_0xf283(_0x286cc5,_0x53046a);}function a20_0x60c1(){const _0x1951f8=['/unzip/','tmpdir','unlinkSync','-文件下载完毕','components','error','242286ONSiEk','resolve','createWriteStream','replace','close','\x5ccli.dva.register.spa.txt','log','mkdirSync','&ref=master','jjbAssembly','rmdirSync','699024IUBwwz','readdirSync','forEach','readFileSync','.zip','2330678NPbRSr','application','path','zip','37104yLYKfk','writeFileSync','existsSync','token','7709696ZpdNML','\x5ccli.dva.router.spa.txt','/repository/archive.zip?private_token=','common\x5cdva\x5cautomatic','const\x20relation\x20=\x20require(\x27~/enumerate/menu\x27).default;','uncompress','503300OYvVPc','exists','indexOf','85VVqdmd','\x5csrc','common\x5cdva\x5cautomatic\x5c','return\x20process.env;','/api/v4/projects/','16030zjsjkF','then','common','./util','【Error】:\x20当前目录不存在src子目录,无法完成pull操作。','DeleteDirAllFile','\x5ccommon\x5cdva\x5cautomatic\x5crouter.js','http://192.168.1.242:10985','CopyFolder','exports','request','projectId','localName','toString','-master-','pipe','G4HJRsHr9D7Ssmixegw2'];a20_0x60c1=function(){return _0x1951f8;};return a20_0x60c1();}(function(_0x2b723f,_0x7edb99){const _0x332310=a20_0xf283,_0x1a4557=_0x2b723f();while(!![]){try{const _0x35607c=parseInt(_0x332310(0xb8))/0x1+-parseInt(_0x332310(0x92))/0x2+-parseInt(_0x332310(0x9d))/0x3+-parseInt(_0x332310(0xb0))/0x4+-parseInt(_0x332310(0xb3))/0x5*(-parseInt(_0x332310(0xa6))/0x6)+-parseInt(_0x332310(0xa2))/0x7+parseInt(_0x332310(0xaa))/0x8;if(_0x35607c===_0x7edb99)break;else _0x1a4557['push'](_0x1a4557['shift']());}catch(_0xc746b4){_0x1a4557['push'](_0x1a4557['shift']());}}}(a20_0x60c1,0x42644));const fs=require('fs'),os=require('os'),path=require(a20_0x1de7dc(0xa4)),utils=require(a20_0x1de7dc(0xbb)),request=require(a20_0x1de7dc(0x85)),compressing=require('compressing'),GIT_TEMP_DIR=a20_0x1de7dc(0x9b),GIT_HOST=a20_0x1de7dc(0xbf),CLOUD_PROJECT={'common':{'token':a20_0x1de7dc(0x8b),'projectId':0x117,'localName':a20_0x1de7dc(0xba)},'react-admin-component':{'token':'FT3pKzxpRynFkmddJ9Bs','projectId':0x154,'localName':a20_0x1de7dc(0x90)}};module[a20_0x1de7dc(0x84)]=_0x4b91bc=>{const _0x62e6b8=a20_0x1de7dc,_0x19152b=_0x4b91bc,_0x4e308a=path[_0x62e6b8(0x93)]('./');try{if(fs['statSync'](_0x4e308a+'\x5csrc')){const _0xb63556=_0x4e308a+_0x62e6b8(0xb4),_0x5519f7=CLOUD_PROJECT[_0x19152b]||undefined;if(_0x5519f7){const _0x2077a9=os[_0x62e6b8(0x8d)](),_0x130dca=_0x2077a9+('/'+GIT_TEMP_DIR+'/'+_0x19152b+_0x62e6b8(0xa1)),_0x4952e9=_0x2077a9+'/'+GIT_TEMP_DIR+_0x62e6b8(0x8c);utils[_0x62e6b8(0xbd)](_0x2077a9+'/'+GIT_TEMP_DIR,()=>{const _0x2c8a34=_0x62e6b8;fs[_0x2c8a34(0x99)](_0x2077a9+'/'+GIT_TEMP_DIR);let _0x36c6db=fs[_0x2c8a34(0x94)](_0x130dca);request(GIT_HOST+_0x2c8a34(0xb7)+_0x5519f7[_0x2c8a34(0x86)]+_0x2c8a34(0xac)+_0x5519f7[_0x2c8a34(0xa9)]+_0x2c8a34(0x9a))[_0x2c8a34(0x8a)](_0x36c6db)['on'](_0x2c8a34(0x96),()=>{const _0x2438b9=_0x2c8a34;fs[_0x2438b9(0x99)](_0x4952e9),compressing[_0x2438b9(0xa5)][_0x2438b9(0xaf)](_0x130dca,_0x4952e9)[_0x2438b9(0xb9)](()=>{setTimeout(()=>{const _0x2811f7=a20_0xf283,_0x208eb8=fs[_0x2811f7(0x9e)](_0x4952e9);_0x208eb8['forEach'](_0x8c25bb=>{const _0xfa924f=_0x2811f7;if(_0x8c25bb[_0xfa924f(0xb2)](_0xfa924f(0x89))!==-0x1){const _0x4c57e1=_0xb63556+'\x5c'+_0x5519f7[_0xfa924f(0x87)];utils['DeleteDirAllFile'](_0x4c57e1,()=>{const _0x16f5e6=_0xfa924f;fs[_0x16f5e6(0x99)](_0x4c57e1),utils[_0x16f5e6(0x83)](_0x4952e9+_0x8c25bb,_0x4c57e1),setTimeout(()=>{const _0x53bfa1=_0x16f5e6,_0x370661=fs[_0x53bfa1(0xa8)](_0xb63556+'\x5c'+_0x53bfa1(0xa3));if(!_0x370661){const _0x4e00f6=_0xb63556+'\x5c'+'common\x5ctools\x5cindex.js',_0x4ebdd4=_0xb63556+'\x5c'+'common\x5cwebsite\x5cindex.js';let _0x196989=fs[_0x53bfa1(0xa0)](_0x4e00f6)[_0x53bfa1(0x88)](),_0x2b5c6c=fs[_0x53bfa1(0xa0)](_0x4ebdd4)[_0x53bfa1(0x88)]();_0x196989=_0x196989[_0x53bfa1(0x95)]('return\x20__planA();',_0x53bfa1(0xb6)),_0x2b5c6c=_0x2b5c6c[_0x53bfa1(0x95)](/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,_0x53bfa1(0xae)),fs['writeFileSync'](_0x4e00f6,_0x196989),fs[_0x53bfa1(0xa7)](_0x4ebdd4,_0x2b5c6c),fs[_0x53bfa1(0xa7)](_0xb63556+_0x53bfa1(0xbe),fs['readFileSync'](__dirname+_0x53bfa1(0xab))[_0x53bfa1(0x88)]()),fs[_0x53bfa1(0xa7)](_0xb63556+'\x5ccommon\x5cdva\x5cautomatic\x5cregister.js',fs[_0x53bfa1(0xa0)](__dirname+_0x53bfa1(0x97))[_0x53bfa1(0x88)]());}else fs[_0x53bfa1(0xb1)](_0xb63556+'\x5c'+'common\x5cdva\x5cautomatic\x5cindex.js',_0x439491=>{const _0x1ddce4=_0x53bfa1;_0x439491&&(fs[_0x1ddce4(0x9e)](_0xb63556+'\x5c'+_0x1ddce4(0xad))[_0x1ddce4(0x9f)](_0x45b411=>{const _0x262103=_0x1ddce4;fs[_0x262103(0x8e)](_0xb63556+'\x5c'+_0x262103(0xb5)+_0x45b411);}),fs[_0x1ddce4(0x9c)](_0xb63556+'\x5c'+_0x1ddce4(0xad)));});},0x3e8);});}}),console[_0x2811f7(0x98)](_0x19152b+_0x2811f7(0x8f));},0x7d0);});});});}else console[_0x62e6b8(0x91)]('【Error】:\x20未获取到项目\x20'+_0x19152b);}}catch(_0x534767){console['error'](_0x62e6b8(0xbc));}};
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_0x102601=a21_0x4ef4;(function(_0x37d8e4,_0x1624b4){const _0x339b2e=a21_0x4ef4,_0x2ca027=_0x37d8e4();while(!![]){try{const _0x2e4921=-parseInt(_0x339b2e(0xcc))/0x1*(parseInt(_0x339b2e(0xaf))/0x2)+parseInt(_0x339b2e(0xa6))/0x3+-parseInt(_0x339b2e(0xf6))/0x4*(-parseInt(_0x339b2e(0xc3))/0x5)+parseInt(_0x339b2e(0xd8))/0x6+-parseInt(_0x339b2e(0xa4))/0x7+parseInt(_0x339b2e(0x9e))/0x8*(parseInt(_0x339b2e(0xcb))/0x9)+parseInt(_0x339b2e(0xf2))/0xa;if(_0x2e4921===_0x1624b4)break;else _0x2ca027['push'](_0x2ca027['shift']());}catch(_0x1d0d71){_0x2ca027['push'](_0x2ca027['shift']());}}}(a21_0x4f6c,0x842fd));const fs=require('fs'),os=require('os'),path=require(a21_0x102601(0xf3)),utils=require(a21_0x102601(0xd1)),request=require(a21_0x102601(0xed)),compressing=require(a21_0x102601(0xc8)),GIT_HOST=a21_0x102601(0xba),GIT_TEMP_DIR=a21_0x102601(0xc1),CLOUD_PROJECT={'common':{'token':a21_0x102601(0xf5),'projectId':0x117,'localName':a21_0x102601(0xa0)},'react-admin-component':{'token':'FT3pKzxpRynFkmddJ9Bs','projectId':0x154,'localName':a21_0x102601(0xb0)}},COMMON_CONTENT_NOR_REPLACE=[{'path':a21_0x102601(0xdc),'replace':[[a21_0x102601(0xb0),a21_0x102601(0xb6)]]},{'path':a21_0x102601(0xaa),'replace':[[/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/,a21_0x102601(0xad)],[a21_0x102601(0xb0),a21_0x102601(0xb6)]]}],COMMON_CONTENT_SPA_REPLACE=[{'path':a21_0x102601(0xdc),'replace':[[a21_0x102601(0x9b),'return\x20process.env;']]}],COMMON_CONTENT_MICRO_REPLACE=[{'path':'\x5ctools\x5cindex.js','replace':[[a21_0x102601(0x9b),'return\x20process.env.app;']]}],COMPONENTS_CONTENT_REPLACE=[{'path':a21_0x102601(0xb7),'replace':[[a21_0x102601(0xda),a21_0x102601(0xc0)],['common/crypto',a21_0x102601(0xb9)],['common/tools',a21_0x102601(0xca)]]},{'path':a21_0x102601(0x9f),'replace':[[a21_0x102601(0xe7),a21_0x102601(0xeb)]]},{'path':a21_0x102601(0xd0),'replace':[[a21_0x102601(0x9c),a21_0x102601(0xca)]]},{'path':a21_0x102601(0xc7),'replace':[[a21_0x102601(0xda),a21_0x102601(0xc0)],[a21_0x102601(0x9c),'jjb-common/tools']]},{'path':a21_0x102601(0xc4),'replace':[[a21_0x102601(0xda),'jjb-common/http'],[a21_0x102601(0x9c),a21_0x102601(0xca)]]},{'path':a21_0x102601(0xa1),'replace':[[a21_0x102601(0xda),a21_0x102601(0xc0)],[a21_0x102601(0x9c),'jjb-common/tools']]},{'path':'\x5cPageHeaderBar\x5cindex.js','replace':[[a21_0x102601(0xe7),'jjb-common/color']]},{'path':a21_0x102601(0xdd),'replace':[[a21_0x102601(0x9c),a21_0x102601(0xca)]]},{'path':a21_0x102601(0xd6),'replace':[[a21_0x102601(0xae),'jjb-common/website'],['common/tools',a21_0x102601(0xca)]]}];function uid(){const _0xa38ac9=a21_0x102601;return Math['random']()['toString']()[_0xa38ac9(0xc9)](0x2);}function a21_0x4f6c(){const _0xc18ec9=['common/website','181218hCvdKJ','components','createWriteStream','token','readdirSync','\x5cnode_modules\x5cjjb-','/repository/archive.zip?private_token=','jjb-react-admin-component','\x5cEditor\x5cindex.js','rmdirSync','jjb-common/crypto','http://192.168.1.242:10985','tmpdir','\x5cpackage.json','\x5ccli.dva.router.spa.txt','\x5cdva\x5cautomatic\x5crouter.js','projectId','jjb-common/http','jjbAssembly','【已安装】:','1611985Fzcdqf','\x5cImageCropper\x5cindex.js','stringify','【Error】:\x20当前目录不存在src子目录,无法完成pull操作。','\x5cFileUploader\x5cindex.js','compressing','substr','jjb-common/tools','1503YcPfZQ','7wkiwDQ','\x5capplication','unlinkSync','then','\x5cRouterMenu\x5cindex.js','./util','-master-','\x22,\x22version\x22:\x22','zip','writeFileSync','\x5cRouterContainer\x5ccomponents\x5cNavigationTab\x5cindex.js','/api/v4/projects/','2818578uKtAiP','\x5csrc','common/http','\x5ccli.dva.router.saas.txt','\x5ctools\x5cindex.js','\x5cRouterContainer\x5cindex.js','readFileSync','toString','length','【Error】:\x20未获取到项目\x20','error','micro-spa','\x5c.idea','template_','\x5cdva\x5cautomatic','common/color','react-admin-component','/unzip/','mkdirSync','jjb-common/color','replace','request','.zip','forEach','CopyFolder','resolve','5311090zGHQsd','path','close','G4HJRsHr9D7Ssmixegw2','4IAnfpT','1.0.0','spa','return\x20__planA();','common/tools','\x5cdva\x5cautomatic\x5cregister.js','7688QWVLOe','\x5cRejectText\x5cindex.js','common','\x5cImageUploader\x5cindex.js','isDirectory','existsSync','3155495QaCvVG','parse','428187PHFGkq','exports','\x5ccli.dva.register.spa.txt','\x5c.gitignore','\x5cwebsite\x5cindex.js','{\x22name\x22:\x22','DeleteDirAllFile','const\x20relation\x20=\x20require(\x27~/enumerate/menu\x27).default;'];a21_0x4f6c=function(){return _0xc18ec9;};return a21_0x4f6c();}module[a21_0x102601(0xa7)]=_0x1720ff=>{const _0x16dcdb=a21_0x102601,_0x38b346=path[_0x16dcdb(0xf1)]('./'),_0x2a1d75='jjb-'+_0x1720ff,_0x17ce50=_0x16dcdb(0xf7),_0x11026a=_0x38b346+_0x16dcdb(0xd9),_0x273812=_0x16dcdb(0xe5)+uid(),_0x1a873f=__dirname+'\x5c'+_0x273812,_0x12ea7d=_0x38b346+_0x16dcdb(0xbc),_0x2e63bc=_0x38b346+_0x16dcdb(0xb4)+_0x1720ff;try{if(fs[_0x16dcdb(0xa3)](_0x11026a)){const _0x39a280=CLOUD_PROJECT[_0x1720ff]||undefined;if(_0x39a280){const _0x37d516=os[_0x16dcdb(0xbb)](),_0x49bd4c=_0x37d516+'/'+GIT_TEMP_DIR+'/'+_0x1720ff+_0x16dcdb(0xee),_0x4beb07=_0x37d516+'/'+GIT_TEMP_DIR+_0x16dcdb(0xe9);utils['DeleteDirAllFile'](_0x37d516+'/'+GIT_TEMP_DIR,()=>{const _0x2e42da=_0x16dcdb;fs[_0x2e42da(0xea)](_0x37d516+'/'+GIT_TEMP_DIR);const _0x48e2b9=fs[_0x2e42da(0xb1)](_0x49bd4c);request(GIT_HOST+_0x2e42da(0xd7)+_0x39a280[_0x2e42da(0xbf)]+_0x2e42da(0xb5)+_0x39a280[_0x2e42da(0xb2)]+'&ref=master')['pipe'](_0x48e2b9)['on'](_0x2e42da(0xf4),()=>{const _0x59e483=_0x2e42da;fs[_0x59e483(0xea)](_0x4beb07),compressing[_0x59e483(0xd4)]['uncompress'](_0x49bd4c,_0x4beb07)[_0x59e483(0xcf)](()=>{setTimeout(()=>{const _0x252177=a21_0x4ef4;fs[_0x252177(0xb3)](_0x4beb07)[_0x252177(0xef)](_0x520e2f=>{const _0x826380=_0x252177;_0x520e2f['indexOf'](_0x826380(0xd2))!==-0x1&&utils[_0x826380(0xac)](_0x11026a+'\x5c'+_0x39a280['localName'],()=>{const _0x143237=_0x826380;fs[_0x143237(0xea)](_0x1a873f),utils[_0x143237(0xf0)](_0x4beb07+_0x520e2f,_0x1a873f),setTimeout(()=>{const _0x10148a=_0x143237;if(_0x1720ff===_0x10148a(0xa0)){const _0x8fc355=fs[_0x10148a(0xa3)](_0x11026a+_0x10148a(0xcd));if(_0x8fc355)rm_rf(_0x1a873f+_0x10148a(0xe6)),fs[_0x10148a(0xb8)](_0x1a873f+_0x10148a(0xe6));else{if(get_project_type(_0x12ea7d)===_0x10148a(0x9a))content_replace(COMMON_CONTENT_SPA_REPLACE,_0x1a873f),fs[_0x10148a(0xd5)](_0x1a873f+_0x10148a(0xbe),fs[_0x10148a(0xde)](__dirname+_0x10148a(0xbd))[_0x10148a(0xdf)]()),fs['writeFileSync'](_0x1a873f+_0x10148a(0x9d),fs[_0x10148a(0xde)](__dirname+_0x10148a(0xa8))[_0x10148a(0xdf)]());else get_project_type(_0x12ea7d)===_0x10148a(0xe3)&&(content_replace(COMMON_CONTENT_MICRO_REPLACE,_0x1a873f),fs['writeFileSync'](_0x1a873f+_0x10148a(0xbe),fs['readFileSync'](__dirname+_0x10148a(0xdb))[_0x10148a(0xdf)]()),fs['writeFileSync'](_0x1a873f+_0x10148a(0x9d),fs['readFileSync'](__dirname+'\x5ccli.dva.register.saas.txt')[_0x10148a(0xdf)]()));}content_replace(COMMON_CONTENT_NOR_REPLACE,_0x1a873f);}_0x1720ff===_0x10148a(0xe8)&&content_replace(COMPONENTS_CONTENT_REPLACE,_0x1a873f),rm_rf(_0x1a873f+_0x10148a(0xe4)),fs['existsSync'](_0x1a873f+_0x10148a(0xe4))&&fs[_0x10148a(0xb8)](_0x1a873f+'\x5c.idea'),fs[_0x10148a(0xa3)](_0x1a873f+_0x10148a(0xa9))&&fs[_0x10148a(0xce)](_0x1a873f+_0x10148a(0xa9)),!fs[_0x10148a(0xa3)](_0x2e63bc)?fs[_0x10148a(0xea)](_0x2e63bc):rm_rf(_0x2e63bc),utils[_0x10148a(0xf0)](_0x1a873f,_0x2e63bc,()=>{const _0xc2a908=_0x10148a;rm_rf(_0x1a873f),fs[_0xc2a908(0xb8)](_0x1a873f),create_package_json(_0x2e63bc,_0x2a1d75,_0x17ce50),update_project_package_json(_0x12ea7d,_0x2a1d75,_0x17ce50),console['log'](_0xc2a908(0xc2)+_0x2a1d75+'\x20v'+_0x17ce50);});},0x3e8);});});},0x7d0);});});});}else console['error'](_0x16dcdb(0xe1)+_0x1720ff);}}catch(_0x240f60){console[_0x16dcdb(0xe2)](_0x16dcdb(0xc6));}};function a21_0x4ef4(_0x33d683,_0x224f94){const _0x4f6c34=a21_0x4f6c();return a21_0x4ef4=function(_0x4ef430,_0x1ac8e8){_0x4ef430=_0x4ef430-0x9a;let _0x27a41a=_0x4f6c34[_0x4ef430];return _0x27a41a;},a21_0x4ef4(_0x33d683,_0x224f94);}function rm_rf(_0xa58f07){const _0x28ba49=a21_0x102601;if(fs['existsSync'](_0xa58f07)){const _0x58e062=fs['readdirSync'](_0xa58f07);for(let _0x22d4f1=0x0;_0x22d4f1<_0x58e062[_0x28ba49(0xe0)];_0x22d4f1++){const _0x15a093=_0x58e062[_0x22d4f1],_0x27571a=_0xa58f07+'/'+_0x15a093;fs['statSync'](_0x27571a)[_0x28ba49(0xa2)]()?(rm_rf(_0x27571a),fs[_0x28ba49(0xb8)](_0x27571a)):fs[_0x28ba49(0xce)](_0x27571a);}}}function create_package_json(_0x22e7cf,_0x387269,_0x54e135){const _0x2c7384=a21_0x102601;fs[_0x2c7384(0xd5)](_0x22e7cf+_0x2c7384(0xbc),_0x2c7384(0xab)+_0x387269+_0x2c7384(0xd3)+_0x54e135+'\x22,\x22main\x22:\x20\x22index.js\x22}');}function get_project_type(_0x18097e){const _0x4f2fb7=a21_0x102601,_0xb7b860=JSON[_0x4f2fb7(0xa5)](fs[_0x4f2fb7(0xde)](_0x18097e)[_0x4f2fb7(0xdf)]());return _0xb7b860['projectType'];}function update_project_package_json(_0x42ba1f,_0x4650e9,_0x38c88f){const _0x10e645=a21_0x102601,_0x43ddf9=JSON[_0x10e645(0xa5)](fs[_0x10e645(0xde)](_0x42ba1f)[_0x10e645(0xdf)]());_0x43ddf9['dependencies'][_0x4650e9]=_0x38c88f,fs[_0x10e645(0xd5)](_0x42ba1f,JSON[_0x10e645(0xc5)](_0x43ddf9,null,0x2));}function content_replace(_0x580fe0=[],_0x3d7209){const _0xed863f=a21_0x102601;_0x580fe0[_0xed863f(0xef)](_0x3d6eed=>{const _0x562778=_0xed863f,_0x2e60dd=_0x3d7209+_0x3d6eed[_0x562778(0xf3)];if(fs[_0x562778(0xa3)](_0x2e60dd)){let _0x158e79=fs['readFileSync'](_0x2e60dd)[_0x562778(0xdf)]();_0x3d6eed['replace'][_0x562778(0xef)](_0x31316d=>{const _0x505bec=_0x562778;_0x158e79=_0x158e79[_0x505bec(0xec)](_0x31316d[0x0],_0x31316d[0x1]);}),fs[_0x562778(0xd5)](_0x2e60dd,_0x158e79);}});}
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
+ }