jjb-cmd 1.0.9 → 1.0.11

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 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
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "jjb-cmd",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "jjb脚手架工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "node bin/command.js help",
8
- "publish": "npm publish"
7
+ "test": "node bin/command.js help"
9
8
  },
10
9
  "bin": {
11
10
  "jjb-cmd": "bin/command.js"
package/src/cli.merge.js CHANGED
@@ -9,38 +9,55 @@ 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
- fromFileData.router.forEach(itemPath => {
26
- const itemPathArr = itemPath.split(inputRegion);
27
- console.log(itemPath)
28
- const filePathArr = itemPathArr.split('/');
29
- const application = filePathArr[1];
30
- if (!applicationData[application]) {
31
- applicationData[application] = {
32
- routerConfig: [],
33
- routerPath: []
34
- };
35
- }
36
- applicationJson[application].routerConfig.push(`{ path: '${fromItem.path}', component: () => import('${fromItem.file}') }`);
37
- applicationJson[application].routerPath.push(fromItem.path);
38
- utils.CreatePaths(vesselPath, filePathArr.slice(2, filePathArr.length - 1)).then(() => {
39
- const filePath = filePathArr.slice(2, filePathArr.length);
40
- const fileContent = fs.readFileSync(`${projectPath}/${inputRegion}/${filePath.join('/')}`).toString();
41
- fs.writeFileSync(`${projectPath}/${inputRegion}/${filePath.join('/')}`, fileContent);
30
+
31
+ Object.keys(fromFileData).forEach(fileKey => {
32
+ fromFileData[fileKey].forEach(fromItem => {
33
+ const itemPathArr = fromItem.pathAdr.split(fromItem.region);
34
+ const filePathArr = itemPathArr[1].split('/');
35
+ const application = filePathArr[1];
36
+ if (!applicationJson[application]) {
37
+ applicationJson[application] = {
38
+ routerConfig: [],
39
+ routerPath: []
40
+ };
41
+ }
42
+ applicationJson[application].routerConfig.push(`{ path: '${fromItem.path}', component: () => import('${fromItem.file}') }`);
43
+ applicationJson[application].routerPath.push(fromItem.path);
44
+
45
+ let applicationStr = filePathArr.join('/');
46
+
47
+ const strArr = applicationStr.split('/');
48
+ utils.CreatePaths(applicationPath, strArr.slice(0, strArr.length - 1)).then(() => {
49
+ if (fromItem.pathAdr.match(/(.png|.svg)/) != null) {
50
+ const imageFile = fs.readFileSync(fromItem.pathAdr, 'binary');
51
+ fs.writeFileSync(`${applicationPath}/${applicationStr}`, imageFile, 'binary');
52
+ } else {
53
+ const fileContent = fs.readFileSync(fromItem.pathAdr).toString();
54
+ fs.writeFileSync(`${applicationPath}/${applicationStr}`, fileContent);
55
+ }
56
+ });
57
+
42
58
  });
43
59
  });
60
+
44
61
  });
45
62
  };
46
63
 
@@ -56,10 +73,11 @@ function TileItems (items, cb) {
56
73
  item.from.forEach((from, fromIndex) => {
57
74
  const pathArr = [];
58
75
  utils.DeepScanner(projectPath + '/' + region + '/' + from.file, pathArr);
76
+ const newPathArr = pathArr.map(pathItem => ({ region, pathAdr: pathItem, ...from }));
59
77
  if (!fromFileData[from.fileType]) {
60
- fromFileData[from.fileType] = pathArr;
78
+ fromFileData[from.fileType] = newPathArr;
61
79
  } else {
62
- fromFileData[from.fileType] = fromFileData[from.fileType].concat(pathArr);
80
+ fromFileData[from.fileType] = fromFileData[from.fileType].concat(newPathArr);
63
81
  }
64
82
  if (index === items.length - 1 && fromIndex === item.from.length - 1) {
65
83
  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\/\${mainMenu.code}\/enumerate\/menu`\)\.default;/g, 'const relation = require(`/src/enumerate/menu`).default;');
63
+ commonWebsiteFile = commonWebsiteFile.replace(/const\srelation\s=\srequire\(`~\/application\/\${module.code}\/enumerate\/menu`\)\.default;/, "const relation = require('~/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
+ };