ee-bin 4.1.4 → 4.1.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/tools/serve.js +56 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "4.1.4",
3
+ "version": "4.1.5",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/serve.js CHANGED
@@ -3,13 +3,14 @@
3
3
  const debug = require('debug')('ee-bin:serve');
4
4
  const path = require('path');
5
5
  const fsPro = require('fs-extra');
6
- const { loadConfig } = require('../lib/utils');
6
+ const { loadConfig, isWindows } = require('../lib/utils');
7
7
  const is = require('is-type-of');
8
8
  const chalk = require('chalk');
9
9
  const crossSpawn = require('cross-spawn');
10
10
  const { buildSync } = require('esbuild');
11
11
  const chokidar = require('chokidar');
12
12
  const kill = require('tree-kill');
13
+ const process = require("process");
13
14
 
14
15
  class ServeProcess {
15
16
 
@@ -18,6 +19,48 @@ class ServeProcess {
18
19
  this.execProcess = {};
19
20
  this.electronDir = './electron';
20
21
  this.defaultBundleDir = './public/electron';
22
+ this._init();
23
+ }
24
+
25
+ /**
26
+ * init
27
+ */
28
+ _init() {
29
+ // process manager
30
+ // Monitor SIGINT signal(Ctrl + C)
31
+ process.on('SIGINT', () => {
32
+ console.log(chalk.blue('[ee-bin] ') + `Received SIGINT. Closing processes...`);
33
+ this._closeProcess();
34
+ });
35
+
36
+ // Monitor SIGTERM signal
37
+ process.on('SIGTERM', () => {
38
+ console.log(chalk.blue('[ee-bin] ') + `Received SIGTERM. Closing processes...`);
39
+ this._closeProcess();
40
+ });
41
+ }
42
+
43
+ // Close process
44
+ async _closeProcess() {
45
+ const currentProcess = [];
46
+ const keys = Object.keys(this.execProcess);
47
+ const len = keys.length;
48
+ for (let i = 0; i < len; i++) {
49
+ const key = keys[i];
50
+ const p = this.execProcess[key];
51
+ currentProcess.push({
52
+ name: key,
53
+ pid: p.pid,
54
+ });
55
+ }
56
+
57
+ // Cleaning work before the end of the process
58
+ await this.sleep(1000);
59
+ currentProcess.forEach((p) => {
60
+ kill(p.pid);
61
+ debug(`Kill ${chalk.blue(p.name)} server, pid: ${p.pid}`);
62
+ });
63
+ process.exit(0);
21
64
  }
22
65
 
23
66
  /**
@@ -53,7 +96,8 @@ class ServeProcess {
53
96
  persistent: true
54
97
  });
55
98
  watcher.on('change', async (f) => {
56
- console.log(chalk.blue('[ee-bin] [dev] ') + `File ${f} has been changed`);
99
+ //console.log(chalk.blue('[ee-bin] [dev] ') + 'File ' + chalk.cyan(`[${f}]`) + 'has been changed');
100
+ console.log(chalk.blue('[ee-bin] [dev] ') + `File [${chalk.cyan(f)}] has been changed`);
57
101
 
58
102
  // 防抖
59
103
  if (debounceTimer) {
@@ -172,7 +216,7 @@ class ServeProcess {
172
216
  const cfg = binCmdConfig[cmd];
173
217
 
174
218
  if (!cfg) {
175
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: [${binCmd} ${cmd}] config does not exist` ));
219
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: [${cmd}] config does not exist` ));
176
220
  continue;
177
221
  }
178
222
 
@@ -181,8 +225,8 @@ class ServeProcess {
181
225
  continue;
182
226
  }
183
227
 
184
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + "Run " + chalk.green(`[${binCmd} ${cmd}]` + " command"));
185
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('config:'), JSON.stringify(cfg));
228
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `Run ${chalk.green(cmd)} command`);
229
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.magenta('Config:'), JSON.stringify(cfg));
186
230
 
187
231
  const execDir = path.join(process.cwd(), cfg.directory);
188
232
  const execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
@@ -195,15 +239,18 @@ class ServeProcess {
195
239
  execArgs,
196
240
  { stdio: stdio, cwd: execDir, maxBuffer: 1024 * 1024 * 1024 },
197
241
  );
198
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ` command is ${cfg.sync ? 'run completed' : 'running'}`);
242
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`${cmd}`) + ` command is ${cfg.sync ? 'run completed' : 'running'}`);
199
243
 
200
244
  if(!cfg.sync) {
201
245
  this.execProcess[cmd].on('exit', () => {
202
- if (cmd == 'electron') {
203
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
246
+ if (binCmd == 'dev') {
247
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} process is exiting`);
248
+ if (isWindows() && cmd == 'electron') {
249
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
250
+ }
204
251
  return
205
252
  }
206
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ' command has been executed and exited');
253
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} command has been executed and exited`);
207
254
  });
208
255
  }
209
256
  }