jjb-cmd 1.0.16 → 2.0.0

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.
Files changed (73) hide show
  1. package/bin/command-old.js +65 -0
  2. package/bin/command.js +52 -40
  3. package/package.json +7 -4
  4. package/src/new/cmd.init/index.js +48 -0
  5. package/src/{cli.init → new/cmd.init.copy/lib}/jjb.config.json +3 -8
  6. package/src/{cli.init → new/cmd.init.copy/lib}/jjb.script/build.js +0 -0
  7. package/src/new/cmd.init.copy/lib/jjb.script/config.js +149 -0
  8. package/src/{cli.init → new/cmd.init.copy/lib}/jjb.script/proxy.js +0 -0
  9. package/src/{cli.init → new/cmd.init.copy/lib}/jjb.script/server.js +0 -0
  10. package/src/{cli.init → new/cmd.init.copy/lib}/jjb.script/utils.js +0 -0
  11. package/src/{cli.init → new/cmd.init.copy/lib}/package.json +2 -2
  12. package/src/new/cmd.init.copy/lib/src/index.js +1 -0
  13. package/src/{cli.init → new/cmd.init.copy/lib}/webstorm.config.js +0 -0
  14. package/src/new/cmd.init.copy/micro-app/jjb.config.json +40 -0
  15. package/src/new/cmd.init.copy/micro-app/jjb.script/build.js +11 -0
  16. package/src/new/cmd.init.copy/micro-app/jjb.script/config.js +222 -0
  17. package/src/new/cmd.init.copy/micro-app/jjb.script/proxy.js +19 -0
  18. package/src/new/cmd.init.copy/micro-app/jjb.script/server.js +29 -0
  19. package/src/new/cmd.init.copy/micro-app/jjb.script/utils.js +13 -0
  20. package/src/new/cmd.init.copy/micro-app/package.json +65 -0
  21. package/src/new/cmd.init.copy/micro-app/public/index.html +22 -0
  22. package/src/new/cmd.init.copy/micro-app/src/enumerate/namespace/index.js +3 -0
  23. package/src/new/cmd.init.copy/micro-app/src/index.js +24 -0
  24. package/src/new/cmd.init.copy/micro-app/src/models/main/index.js +9 -0
  25. package/src/new/cmd.init.copy/micro-app/src/pages/index.js +11 -0
  26. package/src/new/cmd.init.copy/micro-app/webstorm.config.js +18 -0
  27. package/src/new/cmd.init.copy/react-component/jjb.config.json +33 -0
  28. package/src/new/cmd.init.copy/react-component/jjb.script/build.js +11 -0
  29. package/src/new/cmd.init.copy/react-component/jjb.script/config.js +159 -0
  30. package/src/new/cmd.init.copy/react-component/jjb.script/proxy.js +22 -0
  31. package/src/new/cmd.init.copy/react-component/jjb.script/server.js +29 -0
  32. package/src/new/cmd.init.copy/react-component/jjb.script/utils.js +13 -0
  33. package/src/new/cmd.init.copy/react-component/package.json +56 -0
  34. package/src/new/cmd.init.copy/react-component/src/index.js +11 -0
  35. package/src/new/cmd.init.copy/react-component/webstorm.config.js +16 -0
  36. package/src/new/cmd.install/config.js +31 -0
  37. package/src/new/cmd.install/index.js +255 -0
  38. package/src/{cli.install → new/cmd.install}/tools.js +5 -2
  39. package/src/new/cmd.push/index.js +54 -0
  40. package/src/new/cmd.reglist/index.js +22 -0
  41. package/src/new/cmd.rm-rf/index.js +58 -0
  42. package/src/new/cmd.version/index.js +34 -0
  43. package/src/{cli.dva.register.saas.txt → old/cli.dva.register.saas.txt} +5 -9
  44. package/src/{cli.dva.register.spa.txt → old/cli.dva.register.spa.txt} +0 -0
  45. package/src/{cli.dva.router.saas.txt → old/cli.dva.router.saas.txt} +37 -25
  46. package/src/{cli.dva.router.spa.txt → old/cli.dva.router.spa.txt} +0 -0
  47. package/src/old/cli.init/jjb.config.json +40 -0
  48. package/src/old/cli.init/jjb.script/build.js +11 -0
  49. package/src/{cli.init → old/cli.init}/jjb.script/config.js +11 -8
  50. package/src/old/cli.init/jjb.script/proxy.js +19 -0
  51. package/src/old/cli.init/jjb.script/server.js +29 -0
  52. package/src/old/cli.init/jjb.script/utils.js +13 -0
  53. package/src/old/cli.init/package.json +65 -0
  54. package/src/{cli.init → old/cli.init}/public/index.html +7 -1
  55. package/src/{cli.init → old/cli.init}/src/enumerate/menu/index.js +0 -0
  56. package/src/old/cli.init/src/enumerate/namespace/index.js +3 -0
  57. package/src/{cli.init → old/cli.init}/src/index.js +1 -1
  58. package/src/old/cli.init/src/models/main/index.js +31 -0
  59. package/src/old/cli.init/src/pages/index.js +9 -0
  60. package/src/old/cli.init/webstorm.config.js +18 -0
  61. package/src/{cli.init.js → old/cli.init.js} +1 -4
  62. package/src/{cli.install → old/cli.install}/config.js +12 -0
  63. package/src/{cli.install → old/cli.install}/index.js +3 -5
  64. package/src/old/cli.install/tools.js +230 -0
  65. package/src/{cli.merge.js → old/cli.merge.js} +0 -0
  66. package/src/{cli.pull.js → old/cli.pull.js} +0 -0
  67. package/src/{cli.pull2.js → old/cli.pull2.js} +4 -6
  68. package/src/{cli.rm-rf.js → old/cli.rm-rf.js} +11 -11
  69. package/src/{progress-bar.js → old/progress-bar.js} +0 -0
  70. package/src/{util.js → old/util.js} +0 -0
  71. package/src/cli.init/src/enumerate/namespace/index.js +0 -3
  72. package/src/cli.init/src/models/demo/index.js +0 -10
  73. package/src/cli.init/src/pages/index.js +0 -14
@@ -0,0 +1,230 @@
1
+ const fs = require('fs');
2
+ const os = require('os');
3
+ const {
4
+ GIT_HOST,
5
+ GIT_TEMP_DIR,
6
+ CLOUD_PROJECT
7
+ } = require('./config');
8
+
9
+ /**
10
+ * @description 删除全部
11
+ * @param path {string} 路径
12
+ */
13
+ exports.f_rm_rf = function (path) {
14
+ if (fs.existsSync(path)) {
15
+ const list = fs.readdirSync(path);
16
+ for (let i = 0; i < list.length; i++) {
17
+ const item = list[ i ];
18
+ const vPath = `${path}/${item}`;
19
+ if (fs.statSync(vPath).isDirectory()) {
20
+ exports.f_rm_rf(vPath);
21
+ fs.rmdirSync(vPath);
22
+ } else {
23
+ fs.unlinkSync(vPath);
24
+ }
25
+ }
26
+ }
27
+ };
28
+
29
+ /**
30
+ * @typedef {object} GitResource
31
+ * @property {string} path
32
+ * @property {string} compress
33
+ * @property {string} repository
34
+ */
35
+
36
+ /**
37
+ * @description 拉取git资源
38
+ * @param installResources {Resource[]} 资源名称
39
+ * @return {GitResource[]}
40
+ */
41
+ exports.f_pull_git_repository = function (installResources = []) {
42
+ return installResources.map(item => {
43
+ const resource = CLOUD_PROJECT[ item.name ] || undefined;
44
+ const template = os.tmpdir();
45
+ return {
46
+ path: `${template}\\${GIT_TEMP_DIR}\\${item.name}.zip`,
47
+ compress: `${template}\\${GIT_TEMP_DIR}\\${item.name}_zip`,
48
+ repository: `${GIT_HOST}/api/v4/projects/${resource.projectId}/repository/archive.zip?private_token=${resource.token}&ref=master`
49
+ };
50
+ });
51
+ };
52
+
53
+ /**
54
+ * @description 扫描是否存在jjb.config.json
55
+ * @param root 路径
56
+ * @returns {boolean}
57
+ */
58
+ exports.f_scan_jjb_config_json = function (root) {
59
+ return fs.existsSync(`${root}\\jjb.config.json`);
60
+ };
61
+
62
+ /**
63
+ * @typedef {object} JJB_CONFIG_JSON
64
+ * @property {string} projectType
65
+ * @property {string} installTarget
66
+ * @property {Resource[]} installResources
67
+ */
68
+
69
+ /**
70
+ * @description 验证规则
71
+ * @param root {string} 路径
72
+ * @return {JJB_CONFIG_JSON}
73
+ */
74
+ exports.f_scan_jjb_config_json_rules = function (root) {
75
+ let jjb_config_json = {};
76
+ try {
77
+ jjb_config_json = JSON.parse(fs.readFileSync(`${root}\\jjb.config.json`).toString());
78
+ } catch (e) {
79
+ console.log('【Error】:[jjb.config.json]文件解析失败,请确认是否配置正确。');
80
+ process.exit(0);
81
+ }
82
+ if (!('projectType' in jjb_config_json)) {
83
+ console.log('【Error】:[jjb.config.json]文件配置无效,需要projectType属性。');
84
+ process.exit(0);
85
+ }
86
+ if (!('installTarget' in jjb_config_json)) {
87
+ console.log('【Error】:[jjb.config.json]文件配置无效,需要installTarget属性。');
88
+ process.exit(0);
89
+ }
90
+ if (!('installResources' in jjb_config_json)) {
91
+ console.log('【Error】:[jjb.config.json]文件配置无效,需要installResources属性。');
92
+ process.exit(0);
93
+ }
94
+ if (typeof jjb_config_json.projectType !== 'string') {
95
+ console.log('【Error】:[jjb.config.json.projectType]类型是一个string。');
96
+ process.exit(0);
97
+ }
98
+ if (![
99
+ 'multi',
100
+ 'spa',
101
+ 'uniapp',
102
+ 'micro-spa'
103
+ ].includes(jjb_config_json.projectType)) {
104
+ console.log('【Error】:[jjb.config.json.projectType]配置无效,有效值<multi | spa | micro-spa | uniapp>。');
105
+ process.exit(0);
106
+ }
107
+ if (typeof jjb_config_json.installTarget !== 'string') {
108
+ console.log('【Error】:[jjb.config.json.installTarget]类型是一个string。');
109
+ process.exit(0);
110
+ }
111
+ if (![
112
+ 'node_modules',
113
+ 'src'
114
+ ].includes(jjb_config_json.installTarget)) {
115
+ console.log('【Error】:[jjb.config.json.node_modules]配置无效,有效值<node_modules | src>。');
116
+ process.exit(0);
117
+ }
118
+ if (!Array.isArray(jjb_config_json.installResources)) {
119
+ console.log('【Error】:[jjb.config.json.installResources]类型是一个Array<string>。');
120
+ process.exit(0);
121
+ }
122
+ if (jjb_config_json.installResources.length === 0) {
123
+ console.log('【Error】:[jjb.config.json.installResources]无资源。');
124
+ process.exit(0);
125
+ }
126
+ const resources = exports.f_resolve_install_resources(jjb_config_json.installResources);
127
+ if (resources.map(item => item.name).filter(v => ![
128
+ 'jjb-common',
129
+ 'jjb-dva-runtime',
130
+ 'jjb-common-lib',
131
+ 'jjb-common-decorator',
132
+ 'react-admin-component',
133
+ 'vue-unisass-component'
134
+ ].includes(v)).length !== 0) {
135
+ console.log('【Error】:[jjb.config.json.installResources]配置无效,有效值<common | react-admin-component | vue-unisass-component | jjb-common-decorator | jjb-dva-runtime | jjb-common-lib>。');
136
+ process.exit(0);
137
+ }
138
+ jjb_config_json.installResources = resources;
139
+ return jjb_config_json;
140
+ };
141
+
142
+ /**
143
+ * @description 创建package.json
144
+ * @param path {string} 路径
145
+ * @param name {string} 包名
146
+ * @param version {string} 版本
147
+ */
148
+ exports.f_create_package_json = function (path, name, version) {
149
+ fs.writeFileSync(`${path}\\package.json`, `{"name":"${name}","version":"${version}","main": "index.js"}`);
150
+ };
151
+
152
+ /**
153
+ * @typedef {object} Resource
154
+ * @property {string} name
155
+ * @property {string[]} importList
156
+ */
157
+
158
+ /**
159
+ * @description 分析resources
160
+ * @param installResources
161
+ * @return {Resource[]}
162
+ */
163
+ exports.f_resolve_install_resources = function (installResources = []) {
164
+ const resources = [];
165
+ if (Array.isArray(installResources)) {
166
+ installResources.forEach(resource => {
167
+ if (Array.isArray(resource)) {
168
+ const [ name, importList = [] ] = resource;
169
+ resources.push({
170
+ name,
171
+ importList
172
+ });
173
+ } else {
174
+ resources.push({
175
+ name: resource,
176
+ importList: []
177
+ });
178
+ }
179
+ });
180
+ }
181
+ return resources;
182
+ };
183
+
184
+ /**
185
+ * @description 更新项目package.json文件
186
+ * @param path {string} 路径
187
+ * @param name {string} 包名
188
+ * @param version {string} 版本
189
+ */
190
+ exports.f_update_project_package_json = function (path, name, version) {
191
+ const packageJSONFile = JSON.parse(fs.readFileSync(path).toString());
192
+ packageJSONFile.dependencies[ name ] = version;
193
+ fs.writeFileSync(path, JSON.stringify(packageJSONFile, null, 2));
194
+ };
195
+
196
+ /**
197
+ * @description 复制文件
198
+ * @param originSrc
199
+ * @param targetSrc
200
+ */
201
+ exports.f_file_copy = function (originSrc, targetSrc) {
202
+ fs.readdirSync(originSrc).forEach(dir => {
203
+ const oPath = `${originSrc}\\${dir}`;
204
+ const tPath = `${targetSrc}\\${dir}`;
205
+ if (fs.statSync(oPath).isDirectory()) {
206
+ fs.mkdirSync(tPath);
207
+ exports.f_file_copy(oPath, tPath);
208
+ } else {
209
+ fs.writeFileSync(tPath, fs.readFileSync(oPath).toString());
210
+ }
211
+ });
212
+ };
213
+
214
+ /**
215
+ * @description 替换文件操作
216
+ * @param source {[]} 替换源
217
+ * @param root {string} 路径
218
+ */
219
+ exports.f_content_replace = function (source = [], root) {
220
+ source.forEach(item => {
221
+ const path = root + item.path;
222
+ if (fs.existsSync(path)) {
223
+ let content = fs.readFileSync(path).toString();
224
+ item.replace.forEach(rep => {
225
+ content = content.replace(rep[ 0 ], rep[ 1 ]);
226
+ });
227
+ fs.writeFileSync(path, content);
228
+ }
229
+ });
230
+ };
File without changes
File without changes
@@ -16,14 +16,12 @@ const CLOUD_PROJECT = {
16
16
  'common': {
17
17
  token: 'G4HJRsHr9D7Ssmixegw2',
18
18
  projectId: 279,
19
- localName: 'common',
20
- sha: '20e00c48'
19
+ localName: 'common'
21
20
  },
22
21
  'react-admin-component': {
23
22
  token: 'FT3pKzxpRynFkmddJ9Bs',
24
23
  projectId: 340,
25
- localName: 'components',
26
- sha: 'a79d730b'
24
+ localName: 'components'
27
25
  }
28
26
  };
29
27
  // common 需要替换的文本(常规应用)
@@ -219,7 +217,7 @@ module.exports = input => {
219
217
  utils.DeleteDirAllFile(`${tmpDir}/${GIT_TEMP_DIR}`, () => {
220
218
  fs.mkdirSync(`${tmpDir}/${GIT_TEMP_DIR}`);
221
219
  const stream = fs.createWriteStream(zipPath);
222
- request(`${GIT_HOST}/api/v4/projects/${cloudObj.projectId}/repository/archive.zip?private_token=${cloudObj.token}&sha=${cloudObj.sha}`)
220
+ request(`${GIT_HOST}/api/v4/projects/${cloudObj.projectId}/repository/archive.zip?private_token=${cloudObj.token}&ref=master`)
223
221
  .pipe(stream)
224
222
  .on('close', () => {
225
223
  fs.mkdirSync(zipFolder);
@@ -227,7 +225,7 @@ module.exports = input => {
227
225
  .then(() => {
228
226
  setTimeout(() => {
229
227
  fs.readdirSync(zipFolder).forEach(dirName => {
230
- if (dirName.indexOf(`-${cloudObj.sha}`) !== -1) {
228
+ if (dirName.indexOf('-master-') !== -1) {
231
229
  /* 删除下载的文件 */
232
230
  utils.DeleteDirAllFile(`${srcFolderPath}\\${cloudObj.localName}`, () => {
233
231
  /* 创建临时文件夹 */
@@ -18,8 +18,8 @@ module.exports = function () {
18
18
  if (answer.trim() === 'y') {
19
19
  console.log('正在计算项目数,请稍等...');
20
20
  setTimeout(() => {
21
- scanner(root_path);
22
- console.log(`计算完成共计[${f_total}]项目。`);
21
+ // scanner(root_path);
22
+ // console.log(`计算完成共计[${f_total}]项目。`);
23
23
  setTimeout(() => {
24
24
  console.clear();
25
25
  exec(root_path);
@@ -50,19 +50,19 @@ function exec (path) {
50
50
  if (fs.statSync(vPath).isDirectory()) {
51
51
  exec(vPath);
52
52
  fs.rmdirSync(vPath, { recursive: true });
53
- f_number = f_number + 1;
54
- // console.log('删除文件夹:' + vPath);
53
+ // f_number = f_number + 1;
54
+ console.log('删除文件夹:' + vPath);
55
55
  } else {
56
56
  fs.unlinkSync(vPath);
57
- f_number = f_number + 1;
58
- // console.log('删除文件:' + vPath);
57
+ // f_number = f_number + 1;
58
+ console.log('删除文件:' + vPath);
59
59
  }
60
- progress.render({
61
- completed: f_number,
62
- total: f_total
63
- });
60
+ // progress.render({
61
+ // completed: f_number,
62
+ // total: f_total
63
+ // });
64
64
  } catch (e) {
65
- // console.log('删除异常:' + vPath);
65
+ console.log('删除异常:' + vPath);
66
66
  }
67
67
  }
68
68
  }
File without changes
File without changes
@@ -1,3 +0,0 @@
1
- import { defineNamespace } from 'jjb-common/dva';
2
-
3
- export const NS_DEMO = defineNamespace('demo');
@@ -1,10 +0,0 @@
1
- import { NS_DEMO } from '~/enumerate/namespace';
2
- import { registerModelNew } from 'jjb-common/dva';
3
-
4
- export default registerModelNew(NS_DEMO, {
5
- state: {
6
- loading: false
7
- },
8
- effects: {
9
- }
10
- });
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { Connect } from 'jjb-common/dva';
3
- import { NS_DEMO } from '~/enumerate/namespace';
4
-
5
- @Connect([ NS_DEMO ], true)
6
- export default class extends React.Component {
7
- render () {
8
- return (
9
- <div>
10
- <h1>Hello World</h1>
11
- </div>
12
- );
13
- }
14
- }