jjb-cmd 1.0.9 → 1.0.10
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/bin/command.js +1 -1
- package/package.json +1 -1
- package/src/cli.merge.js +25 -14
- package/src/cli.pull.js +1 -1
- package/src/util.js +47 -1
package/bin/command.js
CHANGED
@@ -28,7 +28,7 @@ commander.command('pull -- <文件夹名称必填。>').description('-- 文件
|
|
28
28
|
|
29
29
|
//多省多应用命令
|
30
30
|
commander.command('mp -- <multi prov多省多应用启动dev>').description('-- multi prov多省多应用合并').action(res => {
|
31
|
-
MergeScripts(res);
|
31
|
+
MergeScripts(res, 'mp');
|
32
32
|
console.log('start test')
|
33
33
|
});
|
34
34
|
|
package/package.json
CHANGED
package/src/cli.merge.js
CHANGED
@@ -9,38 +9,48 @@ let vesselPath = '';
|
|
9
9
|
//input传入参数 指令:地区:环境 start:chongqing:dev
|
10
10
|
let commandArr = [];
|
11
11
|
//application数据
|
12
|
-
let applicationData = {};
|
13
12
|
const fromFileData = {};
|
13
|
+
const applicationJson = {};
|
14
14
|
|
15
15
|
/**
|
16
16
|
* input 指令:地区:环境 start:chongqing:dev
|
17
17
|
*/
|
18
|
-
module.exports = input => {
|
18
|
+
module.exports = (input, source) => {
|
19
19
|
commandArr = input.split(':');
|
20
20
|
projectPath = path.resolve('./project');
|
21
21
|
vesselPath = path.resolve('./vessel/src');
|
22
|
+
let applicationPath = vesselPath;
|
23
|
+
if (source === 'mp') {
|
24
|
+
applicationPath = vesselPath + '/application';
|
25
|
+
utils.CreatePaths(vesselPath, ['application']);
|
26
|
+
}
|
22
27
|
const inputRegion = commandArr[1];
|
23
28
|
const settingJson = JSON.parse(fs.readFileSync(`${projectPath}/${inputRegion}/setting.json`).toString());
|
24
29
|
TileItems(settingJson.items, () => {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
const filePathArr = itemPathArr.split('/');
|
30
|
+
|
31
|
+
fromFileData.router.forEach(fromItem => {
|
32
|
+
const itemPathArr = fromItem.pathAdr.split(fromItem.region);
|
33
|
+
const filePathArr = itemPathArr[1].split('/');
|
29
34
|
const application = filePathArr[1];
|
30
|
-
if (!
|
31
|
-
|
35
|
+
if (!applicationJson[application]) {
|
36
|
+
applicationJson[application] = {
|
32
37
|
routerConfig: [],
|
33
38
|
routerPath: []
|
34
39
|
};
|
35
40
|
}
|
36
41
|
applicationJson[application].routerConfig.push(`{ path: '${fromItem.path}', component: () => import('${fromItem.file}') }`);
|
37
42
|
applicationJson[application].routerPath.push(fromItem.path);
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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);
|
42
50
|
});
|
51
|
+
|
43
52
|
});
|
53
|
+
|
44
54
|
});
|
45
55
|
};
|
46
56
|
|
@@ -56,10 +66,11 @@ function TileItems (items, cb) {
|
|
56
66
|
item.from.forEach((from, fromIndex) => {
|
57
67
|
const pathArr = [];
|
58
68
|
utils.DeepScanner(projectPath + '/' + region + '/' + from.file, pathArr);
|
69
|
+
const newPathArr = pathArr.map(pathItem => ({ region, pathAdr: pathItem, ...from }));
|
59
70
|
if (!fromFileData[from.fileType]) {
|
60
|
-
fromFileData[from.fileType] =
|
71
|
+
fromFileData[from.fileType] = newPathArr;
|
61
72
|
} else {
|
62
|
-
fromFileData[from.fileType] = fromFileData[from.fileType].concat(
|
73
|
+
fromFileData[from.fileType] = fromFileData[from.fileType].concat(newPathArr);
|
63
74
|
}
|
64
75
|
if (index === items.length - 1 && fromIndex === item.from.length - 1) {
|
65
76
|
cb();
|
package/src/cli.pull.js
CHANGED
@@ -60,7 +60,7 @@ module.exports = input => {
|
|
60
60
|
let commonToolsFile = fs.readFileSync(commonToolsPath).toString();
|
61
61
|
let commonWebsiteFile = fs.readFileSync(commonWebsitePath).toString();
|
62
62
|
commonToolsFile = commonToolsFile.replace('return __planA();', 'return process.env;');
|
63
|
-
commonWebsiteFile = commonWebsiteFile.replace(/const\srelation\s=\srequire\(`\/src\/application\/\${
|
63
|
+
commonWebsiteFile = commonWebsiteFile.replace(/const\srelation\s=\srequire\(`\/src\/application\/\${module.code}\/enumerate\/menu`\)\.default;/, 'const relation = require(`/src/enumerate/menu`).default;');
|
64
64
|
fs.writeFileSync(commonToolsPath, commonToolsFile);
|
65
65
|
fs.writeFileSync(commonWebsitePath, commonWebsiteFile);
|
66
66
|
} else {
|
package/src/util.js
CHANGED
@@ -100,4 +100,50 @@ exports.CopyFile = (srcPath, tarPath, cb) => {
|
|
100
100
|
})
|
101
101
|
|
102
102
|
rs.pipe(ws)
|
103
|
-
}
|
103
|
+
};
|
104
|
+
|
105
|
+
/**
|
106
|
+
* 深度获取目录路径
|
107
|
+
* @param path
|
108
|
+
* @param pathChildren
|
109
|
+
* @constructor
|
110
|
+
*/
|
111
|
+
exports.DeepScanner = (path, pathChildren) => {
|
112
|
+
const that = this;
|
113
|
+
const itemList = fs.readdirSync(path);
|
114
|
+
itemList.forEach(item => {
|
115
|
+
const childPath = `${path}/${item}`;
|
116
|
+
const stat = fs.statSync(childPath);
|
117
|
+
if (stat.isDirectory()) {
|
118
|
+
that.DeepScanner(childPath, pathChildren);
|
119
|
+
} else {
|
120
|
+
pathChildren.push(childPath);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
};
|
124
|
+
|
125
|
+
/**
|
126
|
+
* 创建目录路径
|
127
|
+
* @param pathArr
|
128
|
+
*/
|
129
|
+
exports.CreatePaths = (rootPath, pathArr) => {
|
130
|
+
return new Promise(resolve => {
|
131
|
+
const linkStr = [];
|
132
|
+
pathArr.forEach((item, index) => {
|
133
|
+
const dirPath = rootPath + '/' + linkStr.join('/') + '/' + item;
|
134
|
+
try {
|
135
|
+
const stat = fs.statSync(dirPath);
|
136
|
+
if (stat.isDirectory()) {
|
137
|
+
index === pathArr.length - 1 && resolve();
|
138
|
+
} else {
|
139
|
+
fs.mkdirSync(dirPath);
|
140
|
+
index === pathArr.length - 1 && resolve();
|
141
|
+
}
|
142
|
+
} catch (e) {
|
143
|
+
fs.mkdirSync(dirPath);
|
144
|
+
index === pathArr.length - 1 && resolve();
|
145
|
+
}
|
146
|
+
linkStr.push(item);
|
147
|
+
});
|
148
|
+
});
|
149
|
+
};
|