ee-bin 1.3.0-beta.1 → 1.4.0-beta.1

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/index.js CHANGED
@@ -3,7 +3,20 @@
3
3
  const { program } = require('commander');
4
4
 
5
5
  /**
6
- * rd - Moves front-end resources to a specified directory
6
+ * move - Moves resources
7
+ */
8
+ program
9
+ .command('move')
10
+ .description('Move multip resources')
11
+ .option('--config <folder>', 'config file', './electron/config/bin.js')
12
+ .option('--flag <flag>', 'Custom flag')
13
+ .action(function() {
14
+ const moveScript = require('./tools/move');
15
+ moveScript.run(this.opts());
16
+ });
17
+
18
+ /**
19
+ * (deprecated) rd - Moves front-end resources to a specified directory
7
20
  */
8
21
  program
9
22
  .command('rd')
@@ -70,8 +83,9 @@ program
70
83
  */
71
84
  program
72
85
  .command('build')
73
- .description('build frontend dist')
86
+ .description('building multiple resources')
74
87
  .option('--config <folder>', 'config file', './electron/config/bin.js')
88
+ .option('--cmds <flag>', 'custom commands')
75
89
  .action(function() {
76
90
  const serve = require('./tools/serve');
77
91
  serve.build(this.opts());
@@ -97,7 +111,9 @@ program
97
111
  .description('create frontend-serve and electron-serve')
98
112
  .option('--config <folder>', 'config file', './electron/config/bin.js')
99
113
  .option('--command <command>', 'Custom command')
114
+ .option('--cmds <flag>', 'custom commands')
100
115
  .action(function() {
116
+ // command 选项是关键字,不再使用,改为 cmds
101
117
  const serve = require('./tools/serve');
102
118
  serve.exec(this.opts());
103
119
  });
package/lib/pargv.js ADDED
@@ -0,0 +1,263 @@
1
+ 'use strict';
2
+
3
+ function hasKey(obj, keys) {
4
+ var o = obj;
5
+ keys.slice(0, -1).forEach(function (key) {
6
+ o = o[key] || {};
7
+ });
8
+
9
+ var key = keys[keys.length - 1];
10
+ return key in o;
11
+ }
12
+
13
+ function isNumber(x) {
14
+ if (typeof x === 'number') { return true; }
15
+ if ((/^0x[0-9a-f]+$/i).test(x)) { return true; }
16
+ return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
17
+ }
18
+
19
+ function isConstructorOrProto(obj, key) {
20
+ return (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';
21
+ }
22
+
23
+ module.exports = function (args, opts) {
24
+ if (!opts) { opts = {}; }
25
+
26
+ var flags = {
27
+ bools: {},
28
+ strings: {},
29
+ unknownFn: null,
30
+ };
31
+
32
+ if (typeof opts.unknown === 'function') {
33
+ flags.unknownFn = opts.unknown;
34
+ }
35
+
36
+ if (typeof opts.boolean === 'boolean' && opts.boolean) {
37
+ flags.allBools = true;
38
+ } else {
39
+ [].concat(opts.boolean).filter(Boolean).forEach(function (key) {
40
+ flags.bools[key] = true;
41
+ });
42
+ }
43
+
44
+ var aliases = {};
45
+
46
+ function aliasIsBoolean(key) {
47
+ return aliases[key].some(function (x) {
48
+ return flags.bools[x];
49
+ });
50
+ }
51
+
52
+ Object.keys(opts.alias || {}).forEach(function (key) {
53
+ aliases[key] = [].concat(opts.alias[key]);
54
+ aliases[key].forEach(function (x) {
55
+ aliases[x] = [key].concat(aliases[key].filter(function (y) {
56
+ return x !== y;
57
+ }));
58
+ });
59
+ });
60
+
61
+ [].concat(opts.string).filter(Boolean).forEach(function (key) {
62
+ flags.strings[key] = true;
63
+ if (aliases[key]) {
64
+ [].concat(aliases[key]).forEach(function (k) {
65
+ flags.strings[k] = true;
66
+ });
67
+ }
68
+ });
69
+
70
+ var defaults = opts.default || {};
71
+
72
+ var argv = { _: [] };
73
+
74
+ function argDefined(key, arg) {
75
+ return (flags.allBools && (/^--[^=]+$/).test(arg))
76
+ || flags.strings[key]
77
+ || flags.bools[key]
78
+ || aliases[key];
79
+ }
80
+
81
+ function setKey(obj, keys, value) {
82
+ var o = obj;
83
+ for (var i = 0; i < keys.length - 1; i++) {
84
+ var key = keys[i];
85
+ if (isConstructorOrProto(o, key)) { return; }
86
+ if (o[key] === undefined) { o[key] = {}; }
87
+ if (
88
+ o[key] === Object.prototype
89
+ || o[key] === Number.prototype
90
+ || o[key] === String.prototype
91
+ ) {
92
+ o[key] = {};
93
+ }
94
+ if (o[key] === Array.prototype) { o[key] = []; }
95
+ o = o[key];
96
+ }
97
+
98
+ var lastKey = keys[keys.length - 1];
99
+ if (isConstructorOrProto(o, lastKey)) { return; }
100
+ if (
101
+ o === Object.prototype
102
+ || o === Number.prototype
103
+ || o === String.prototype
104
+ ) {
105
+ o = {};
106
+ }
107
+ if (o === Array.prototype) { o = []; }
108
+ if (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {
109
+ o[lastKey] = value;
110
+ } else if (Array.isArray(o[lastKey])) {
111
+ o[lastKey].push(value);
112
+ } else {
113
+ o[lastKey] = [o[lastKey], value];
114
+ }
115
+ }
116
+
117
+ function setArg(key, val, arg) {
118
+ if (arg && flags.unknownFn && !argDefined(key, arg)) {
119
+ if (flags.unknownFn(arg) === false) { return; }
120
+ }
121
+
122
+ var value = !flags.strings[key] && isNumber(val)
123
+ ? Number(val)
124
+ : val;
125
+ setKey(argv, key.split('.'), value);
126
+
127
+ (aliases[key] || []).forEach(function (x) {
128
+ setKey(argv, x.split('.'), value);
129
+ });
130
+ }
131
+
132
+ Object.keys(flags.bools).forEach(function (key) {
133
+ setArg(key, defaults[key] === undefined ? false : defaults[key]);
134
+ });
135
+
136
+ var notFlags = [];
137
+
138
+ if (args.indexOf('--') !== -1) {
139
+ notFlags = args.slice(args.indexOf('--') + 1);
140
+ args = args.slice(0, args.indexOf('--'));
141
+ }
142
+
143
+ for (var i = 0; i < args.length; i++) {
144
+ var arg = args[i];
145
+ var key;
146
+ var next;
147
+
148
+ if ((/^--.+=/).test(arg)) {
149
+ // Using [\s\S] instead of . because js doesn't support the
150
+ // 'dotall' regex modifier. See:
151
+ // http://stackoverflow.com/a/1068308/13216
152
+ var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
153
+ key = m[1];
154
+ var value = m[2];
155
+ if (flags.bools[key]) {
156
+ value = value !== 'false';
157
+ }
158
+ setArg(key, value, arg);
159
+ } else if ((/^--no-.+/).test(arg)) {
160
+ key = arg.match(/^--no-(.+)/)[1];
161
+ setArg(key, false, arg);
162
+ } else if ((/^--.+/).test(arg)) {
163
+ key = arg.match(/^--(.+)/)[1];
164
+ next = args[i + 1];
165
+ if (
166
+ next !== undefined
167
+ && !(/^(-|--)[^-]/).test(next)
168
+ && !flags.bools[key]
169
+ && !flags.allBools
170
+ && (aliases[key] ? !aliasIsBoolean(key) : true)
171
+ ) {
172
+ setArg(key, next, arg);
173
+ i += 1;
174
+ } else if ((/^(true|false)$/).test(next)) {
175
+ setArg(key, next === 'true', arg);
176
+ i += 1;
177
+ } else {
178
+ setArg(key, flags.strings[key] ? '' : true, arg);
179
+ }
180
+ } else if ((/^-[^-]+/).test(arg)) {
181
+ var letters = arg.slice(1, -1).split('');
182
+
183
+ var broken = false;
184
+ for (var j = 0; j < letters.length; j++) {
185
+ next = arg.slice(j + 2);
186
+
187
+ if (next === '-') {
188
+ setArg(letters[j], next, arg);
189
+ continue;
190
+ }
191
+
192
+ if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
193
+ setArg(letters[j], next.slice(1), arg);
194
+ broken = true;
195
+ break;
196
+ }
197
+
198
+ if (
199
+ (/[A-Za-z]/).test(letters[j])
200
+ && (/-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
201
+ ) {
202
+ setArg(letters[j], next, arg);
203
+ broken = true;
204
+ break;
205
+ }
206
+
207
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
208
+ setArg(letters[j], arg.slice(j + 2), arg);
209
+ broken = true;
210
+ break;
211
+ } else {
212
+ setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
213
+ }
214
+ }
215
+
216
+ key = arg.slice(-1)[0];
217
+ if (!broken && key !== '-') {
218
+ if (
219
+ args[i + 1]
220
+ && !(/^(-|--)[^-]/).test(args[i + 1])
221
+ && !flags.bools[key]
222
+ && (aliases[key] ? !aliasIsBoolean(key) : true)
223
+ ) {
224
+ setArg(key, args[i + 1], arg);
225
+ i += 1;
226
+ } else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {
227
+ setArg(key, args[i + 1] === 'true', arg);
228
+ i += 1;
229
+ } else {
230
+ setArg(key, flags.strings[key] ? '' : true, arg);
231
+ }
232
+ }
233
+ } else {
234
+ if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
235
+ argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
236
+ }
237
+ if (opts.stopEarly) {
238
+ argv._.push.apply(argv._, args.slice(i + 1));
239
+ break;
240
+ }
241
+ }
242
+ }
243
+
244
+ Object.keys(defaults).forEach(function (k) {
245
+ if (!hasKey(argv, k.split('.'))) {
246
+ setKey(argv, k.split('.'), defaults[k]);
247
+
248
+ (aliases[k] || []).forEach(function (x) {
249
+ setKey(argv, x.split('.'), defaults[k]);
250
+ });
251
+ }
252
+ });
253
+
254
+ if (opts['--']) {
255
+ argv['--'] = notFlags.slice();
256
+ } else {
257
+ notFlags.forEach(function (k) {
258
+ argv._.push(k);
259
+ });
260
+ }
261
+
262
+ return argv;
263
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "1.3.0-beta.1",
3
+ "version": "1.4.0-beta.1",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/iconGen.js CHANGED
@@ -52,14 +52,14 @@ class IconGen {
52
52
  }
53
53
  }
54
54
  } catch (e) {
55
- console.error("[ee-core] [tools/iconGen] args: ", args);
56
- console.error("[ee-core] [tools/iconGen] ERROR: ", e);
55
+ console.error("[ee-bin] [icon-gen] args: ", args);
56
+ console.error("[ee-bin] [icon-gen] ERROR: ", e);
57
57
  throw new Error("参数错误!!");
58
58
  }
59
59
  this.params = params;
60
60
 
61
61
  // ---> 组装参数
62
- console.log("[ee-core] [tools/iconGen] icon 当前路径: ", process.cwd());
62
+ console.log("[ee-bin] [icon-gen] icon 当前路径: ", process.cwd());
63
63
  this.input = path.join(process.cwd(), params.input);
64
64
  this.output = path.join(process.cwd(), params.output);
65
65
  this.imagesDir = path.join(process.cwd(), params.imagesDir);
@@ -82,9 +82,9 @@ class IconGen {
82
82
  * 生成图标
83
83
  */
84
84
  generateIcons() {
85
- console.log("[ee-core] [tools/iconGen] iconGen 开始处理生成logo图片");
85
+ console.log("[ee-bin] [icon-gen] iconGen 开始处理生成logo图片");
86
86
  if (!fs.existsSync(this.input)) {
87
- console.error("[ee-core] [tools/iconGen] input: ", this.input);
87
+ console.error("[ee-bin] [icon-gen] input: ", this.input);
88
88
  throw new Error("输入的图片不存在或路径错误");
89
89
  }
90
90
  if (!fs.existsSync(this.output)) {
@@ -98,13 +98,13 @@ class IconGen {
98
98
  }
99
99
  icongen(this.input, this.output, this.iconOptions)
100
100
  .then((results) => {
101
- console.log("[ee-core] [tools/iconGen] iconGen 已生成下方图片资源");
101
+ console.log("[ee-bin] [icon-gen] iconGen 已生成下方图片资源");
102
102
  console.log(results);
103
103
  this._renameForEE(results);
104
104
  })
105
105
  .catch((err) => {
106
106
  console.error(err);
107
- throw new Error("[ee-core] [tools/iconGen] iconGen 生成失败!");
107
+ throw new Error("[ee-bin] [icon-gen] iconGen 生成失败!");
108
108
  });
109
109
  }
110
110
 
@@ -134,7 +134,7 @@ class IconGen {
134
134
  * 为生成的资源重命名 (logo-32.png -> 32x32.png)
135
135
  */
136
136
  _renameForEE(filesPath) {
137
- console.log("[ee-core] [tools/iconGen] iconGen 开始重新命名logo图片资源");
137
+ console.log("[ee-bin] [icon-gen] iconGen 开始重新命名logo图片资源");
138
138
  try {
139
139
  const len = filesPath.length;
140
140
  for (let i = 0; i < len; i++) {
@@ -165,9 +165,9 @@ class IconGen {
165
165
  console.log(`${filename}${extname} --> ${newName} 重命名成功!`);
166
166
  }
167
167
  }
168
- console.log("[ee-core] [tools/iconGen] iconGen 资源处理完成!");
168
+ console.log("[ee-bin] [icon-gen] iconGen 资源处理完成!");
169
169
  } catch (e) {
170
- console.error("[ee-core] [tools/iconGen] ERROR: ", e);
170
+ console.error("[ee-bin] [icon-gen] ERROR: ", e);
171
171
  throw new Error("重命名logo图片资源失败!!");
172
172
  }
173
173
  }
package/tools/move.js ADDED
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fsPro = require('fs-extra');
6
+ const chalk = require('chalk');
7
+ const Utils = require('../lib/utils');
8
+
9
+ /**
10
+ * 移动资源
11
+ */
12
+
13
+ module.exports = {
14
+
15
+ /**
16
+ * 执行
17
+ */
18
+ run(options = {}) {
19
+ console.log('[ee-bin] [move] Start moving resources');
20
+ const homeDir = process.cwd();
21
+ const { config, flag } = options;
22
+ const binCfg = Utils.loadConfig(config);
23
+
24
+ let flags;
25
+ const flagString = flag.trim();
26
+ if (flagString.indexOf(',') !== -1) {
27
+ flags = flagString.split(',');
28
+ } else {
29
+ flags = [flagString];
30
+ }
31
+
32
+ for (let i = 0; i < flags.length; i++) {
33
+ let f = flags[i];
34
+ let cfg = binCfg.move[f];
35
+
36
+ if (!cfg) {
37
+ console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
38
+ return;
39
+ }
40
+
41
+ console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
42
+ console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
43
+
44
+ const distResource = path.join(homeDir, cfg.dist);
45
+ if (!fs.existsSync(distResource)) {
46
+ const errorTips = chalk.bgRed('Error') + ` ${cfg.dist} resource does not exist !`;
47
+ console.error(errorTips);
48
+ return
49
+ }
50
+
51
+ // clear the historical resource and copy it to the ee resource directory
52
+ const targetResource = path.join(homeDir, cfg.target);
53
+ if (fs.statSync(distResource).isDirectory() && !fs.existsSync(targetResource)) {
54
+ fs.mkdirSync(targetResource, {recursive: true, mode: 0o777});
55
+ } else {
56
+ this._rm(targetResource);
57
+ console.log('[ee-bin] [move] Clear history resources:', targetResource);
58
+ }
59
+
60
+ fsPro.copySync(distResource, targetResource);
61
+
62
+ // [todo] go project, special treatment of package.json, reserved only necessary
63
+ console.log(`[ee-bin] [move] Copy ${distResource} to ${targetResource}`);
64
+ }
65
+
66
+ console.log('[ee-bin] [move] End');
67
+ },
68
+
69
+ /**
70
+ * Delete a file or folder
71
+ */
72
+ _rm(name) {
73
+ // check
74
+ if (!fs.existsSync(name)) {
75
+ return
76
+ }
77
+
78
+ const nodeVersion = (process.versions && process.versions.node) || null;
79
+ if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
80
+ fs.rmSync(name, {recursive: true});
81
+ } else {
82
+ fs.rmdirSync(name, {recursive: true});
83
+ }
84
+ },
85
+ }
@@ -16,6 +16,9 @@ const Utils = require('../lib/utils');
16
16
  * 执行
17
17
  */
18
18
  run(options = {}) {
19
+ const warnTips = chalk.bgYellow('Warning') + ': This command is deprecated. Use move instead !';
20
+ console.log(warnTips);
21
+
19
22
  console.log('[ee-bin] [rd] Start moving resources');
20
23
  const homeDir = process.cwd();
21
24
  let { dist, target, config } = options;
package/tools/serve.js CHANGED
@@ -8,10 +8,6 @@ const crossSpawn = require('cross-spawn');
8
8
 
9
9
  module.exports = {
10
10
 
11
- frontendProcess: undefined,
12
-
13
- electronProcess: undefined,
14
-
15
11
  execProcess: {},
16
12
 
17
13
  /**
@@ -19,21 +15,21 @@ module.exports = {
19
15
  */
20
16
  dev(options = {}) {
21
17
  const { config, serve } = options;
18
+ const binCmd = 'dev';
22
19
  const binCfg = Utils.loadConfig(config);
23
- const { frontend, electron } = binCfg.dev;
20
+ const binCmdConfig = binCfg[binCmd];
24
21
 
25
- if (serve == 'frontend') {
26
- this.frontendServe(frontend);
27
- return;
22
+ let command = serve;
23
+ if (!command) {
24
+ command = Object.keys(binCmdConfig).join();
28
25
  }
29
26
 
30
- if (serve == 'electron') {
31
- this.electronServe(electron);
32
- return;
27
+ const opt = {
28
+ binCmd,
29
+ binCmdConfig,
30
+ command,
33
31
  }
34
-
35
- this.frontendServe(frontend);
36
- this.electronServe(electron);
32
+ this.multiExec(opt);
37
33
  },
38
34
 
39
35
  /**
@@ -41,93 +37,82 @@ module.exports = {
41
37
  */
42
38
  start(options = {}) {
43
39
  const { config } = options;
40
+ const binCmd = 'start';
44
41
  const binCfg = Utils.loadConfig(config);
45
-
46
- this.electronServe(binCfg.start);
42
+ const binCmdConfig = {
43
+ start: binCfg[binCmd]
44
+ };
45
+
46
+ const opt = {
47
+ binCmd,
48
+ binCmdConfig,
49
+ command: binCmd,
50
+ }
51
+ this.multiExec(opt);
47
52
  },
48
53
 
49
54
  sleep(ms) {
50
55
  return new Promise(resolve => setTimeout(resolve, ms));
51
- },
56
+ },
52
57
 
53
58
  /**
54
- * start frontend serve
59
+ * 构建
55
60
  */
56
- frontendServe(cfg) {
57
- // 如果是 file:// 协议,则不启动
58
- if (cfg.protocol == 'file://') {
61
+ build(options = {}) {
62
+ const { config, cmds } = options;
63
+ const binCmd = 'build';
64
+ const binCfg = Utils.loadConfig(config);
65
+ const binCmdConfig = binCfg[binCmd];
66
+
67
+ if (!cmds || cmds == "") {
68
+ // [todo]
69
+ let tip = chalk.bgYellow('Warning') + ' Please modify the ' + chalk.blue('build') + ' config, See: ';
70
+ tip += chalk.underline('https://www.kaka996.com/pages/e1816f/');
71
+ console.log(tip);
59
72
  return
60
73
  }
61
- // 模拟前端启动慢
62
- // await this.sleep(5 * 1000);
63
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the frontend serve...'));
64
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
65
-
66
- const frontendDir = path.join(process.cwd(), cfg.directory);
67
- const frontendArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
68
- this.frontendProcess = crossSpawn(
69
- cfg.cmd,
70
- frontendArgs,
71
- { stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024 },
72
- );
73
- this.frontendProcess.on('exit', () => {
74
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('frontend serve exit'));
75
- });
74
+
75
+ const opt = {
76
+ binCmd,
77
+ binCmdConfig,
78
+ command: cmds,
79
+ }
80
+ this.multiExec(opt);
76
81
  },
77
82
 
78
83
  /**
79
- * start electron serve
84
+ * 执行自定义命令
80
85
  */
81
- electronServe(cfg) {
82
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the electron serve...'));
83
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
86
+ exec(options = {}) {
87
+ let { config, command, cmds } = options;
88
+ const binCmd = 'exec';
89
+ const binCfg = Utils.loadConfig(config);
90
+ const binCmdConfig = binCfg[binCmd];
84
91
 
85
- const electronDir = path.join(process.cwd(), cfg.directory);
86
- const electronArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
87
-
88
- this.electronProcess = crossSpawn(
89
- cfg.cmd,
90
- electronArgs,
91
- {stdio: 'inherit', cwd: electronDir, maxBuffer: 1024 * 1024 * 1024 }
92
- );
93
-
94
- this.electronProcess.on('exit', () => {
95
- console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Press "CTRL+C" to exit'));
96
- });
97
- },
92
+ // if (typeof command !== "string" || !cmds) {
93
+ // console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: Please specify parameters for --cmds` ));
94
+ // return
95
+ // }
98
96
 
99
- /**
100
- * 构建前端 dist
101
- */
102
- build(options = {}) {
103
- const { config } = options;
104
- const binCfg = Utils.loadConfig(config);
105
- const cfg = binCfg.build;
97
+ // 兼容
98
+ if (typeof command === "string") {
99
+ cmds = command;
100
+ }
106
101
 
107
- // start build frontend dist
108
- console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('Build frontend dist'));
109
- console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('config:'), cfg);
110
-
111
- const frontendDir = path.join(process.cwd(), cfg.directory);
112
- const buildArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
113
-
114
- const buildProcess = crossSpawn(
115
- cfg.cmd,
116
- buildArgs,
117
- { stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024 },
118
- );
119
- buildProcess.on('exit', () => {
120
- console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
121
- });
102
+ const opt = {
103
+ binCmd,
104
+ binCmdConfig,
105
+ command: cmds,
106
+ }
107
+ this.multiExec(opt);
122
108
  },
123
109
 
124
110
  /**
125
- * 执行自定义命令
126
111
  * 支持多个命令
127
112
  */
128
- exec(options = {}) {
129
- const { config, command } = options;
130
- const binCfg = Utils.loadConfig(config);
113
+ multiExec(opt = {}) {
114
+ //console.log('multiExec opt:', opt)
115
+ const { binCmd, binCmdConfig, command } = opt;
131
116
 
132
117
  let cmds;
133
118
  const cmdString = command.trim();
@@ -139,15 +124,20 @@ module.exports = {
139
124
 
140
125
  for (let i = 0; i < cmds.length; i++) {
141
126
  let cmd = cmds[i];
142
- let cfg = binCfg.exec[cmd];
127
+ let cfg = binCmdConfig[cmd];
143
128
 
144
129
  if (!cfg) {
145
- console.log(chalk.blue('[ee-bin] [exec] ') + chalk.red(`Error: ${cmd} config does not exist` ));
146
- return;
130
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: [${binCmd} ${cmd}] config does not exist` ));
131
+ continue;
132
+ }
133
+
134
+ // frontend 如果是 file:// 协议,则不启动
135
+ if (cmd == 'frontend' && cfg.protocol == 'file://') {
136
+ continue;
147
137
  }
148
138
 
149
- console.log(chalk.blue('[ee-bin] [exec] ') + chalk.green('Run custom command'));
150
- console.log(chalk.blue('[ee-bin] [exec] ') + chalk.green('config:'), cfg);
139
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + "Run " + chalk.green(`[${binCmd} ${cmd}]` + " command"));
140
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('config:'), JSON.stringify(cfg));
151
141
 
152
142
  let execDir = path.join(process.cwd(), cfg.directory);
153
143
  let execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
@@ -157,9 +147,16 @@ module.exports = {
157
147
  execArgs,
158
148
  { stdio: 'inherit', cwd: execDir, maxBuffer: 1024 * 1024 * 1024 },
159
149
  );
150
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ' command is running');
151
+
160
152
  this.execProcess[cmd].on('exit', () => {
161
- console.log(chalk.blue('[ee-bin] [exec] ') + 'the ' + chalk.green(`${cmd}`) + ' is execution completed');
153
+ if (cmd == 'electron') {
154
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
155
+ return
156
+ }
157
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ' command is executed and exits');
162
158
  });
163
159
  }
164
160
  },
161
+
165
162
  }