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.
- package/README.md +8 -0
- package/build.js +15 -0
- package/obf.config.json +3 -0
- package/package.json +1 -1
- package/src/new/cmd.auth/index.js +26 -1
- package/src/new/cmd.init/index.js +116 -1
- package/src/new/cmd.install/config.js +70 -1
- package/src/new/cmd.install/index.js +262 -1
- package/src/new/cmd.install/tools.js +230 -1
- package/src/new/cmd.install.app/index.js +27 -1
- package/src/new/cmd.jenkins/index.js +72 -1
- package/src/new/cmd.publish/index.js +197 -1
- package/src/new/cmd.push/index.js +76 -1
- package/src/new/cmd.push/java.js +148 -1
- package/src/new/cmd.push-set/index.js +205 -1
- package/src/new/cmd.refresh/index.js +65 -1
- package/src/new/cmd.reglist/index.js +23 -1
- package/src/new/cmd.rm-rf/index.js +58 -1
- package/src/new/cmd.version/index.js +35 -1
- package/src/old/cli.dva.register.saas.txt +40 -0
- package/src/old/cli.dva.register.spa.txt +22 -0
- package/src/old/cli.dva.router.saas.txt +210 -0
- package/src/old/cli.dva.router.spa.txt +119 -0
- package/src/old/cli.init.js +26 -1
- package/src/old/cli.install/config.js +206 -1
- package/src/old/cli.install/index.js +340 -1
- package/src/old/cli.install/tools.js +230 -1
- package/src/old/cli.merge.js +80 -1
- package/src/old/cli.pull.js +94 -1
- package/src/old/cli.pull2.js +377 -1
- package/src/old/cli.rm-rf.js +88 -1
- package/src/old/progress-bar.js +23 -1
- package/src/old/util.js +149 -1
package/src/old/cli.merge.js
CHANGED
@@ -1 +1,80 @@
|
|
1
|
-
|
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
|
+
}
|
package/src/old/cli.pull.js
CHANGED
@@ -1 +1,94 @@
|
|
1
|
-
'use strict';
|
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
|
+
};
|
package/src/old/cli.pull2.js
CHANGED
@@ -1 +1,377 @@
|
|
1
|
-
'use strict';
|
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
|
+
}
|