ee-bin 1.2.0 → 1.3.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 (3) hide show
  1. package/index.js +13 -0
  2. package/package.json +1 -1
  3. package/tools/serve.js +44 -0
package/index.js CHANGED
@@ -89,4 +89,17 @@ program
89
89
  serve.start(this.opts());
90
90
  });
91
91
 
92
+ /**
93
+ * exec
94
+ */
95
+ program
96
+ .command('exec')
97
+ .description('create frontend-serve and electron-serve')
98
+ .option('--config <folder>', 'config file', './electron/config/bin.js')
99
+ .option('--command <command>', 'Custom command')
100
+ .action(function() {
101
+ const serve = require('./tools/serve');
102
+ serve.exec(this.opts());
103
+ });
104
+
92
105
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/serve.js CHANGED
@@ -12,6 +12,8 @@ module.exports = {
12
12
 
13
13
  electronProcess: undefined,
14
14
 
15
+ execProcess: {},
16
+
15
17
  /**
16
18
  * 启动前端、主进程服务
17
19
  */
@@ -118,4 +120,46 @@ module.exports = {
118
120
  console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
119
121
  });
120
122
  },
123
+
124
+ /**
125
+ * 执行自定义命令
126
+ * 支持多个命令
127
+ */
128
+ exec(options = {}) {
129
+ const { config, command } = options;
130
+ const binCfg = Utils.loadConfig(config);
131
+
132
+ let cmds;
133
+ const cmdString = command.trim();
134
+ if (cmdString.indexOf(',') !== -1) {
135
+ cmds = cmdString.split(',');
136
+ } else {
137
+ cmds = [cmdString];
138
+ }
139
+
140
+ for (let i = 0; i < cmds.length; i++) {
141
+ let cmd = cmds[i];
142
+ let cfg = binCfg.exec[cmd];
143
+
144
+ if (!cfg) {
145
+ console.log(chalk.blue('[ee-bin] [exec] ') + chalk.red(`Error: ${cmd} config does not exist` ));
146
+ return;
147
+ }
148
+
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);
151
+
152
+ let execDir = path.join(process.cwd(), cfg.directory);
153
+ let execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
154
+
155
+ this.execProcess[cmd] = crossSpawn(
156
+ cfg.cmd,
157
+ execArgs,
158
+ { stdio: 'inherit', cwd: execDir, maxBuffer: 1024 * 1024 * 1024 },
159
+ );
160
+ this.execProcess[cmd].on('exit', () => {
161
+ console.log(chalk.blue('[ee-bin] [exec] ') + 'the ' + chalk.green(`${cmd}`) + ' is execution completed');
162
+ });
163
+ }
164
+ },
121
165
  }