ee-bin 1.2.0-bete.1 → 1.2.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.
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const program = require('commander');
3
+ const { program } = require('commander');
4
4
 
5
5
  /**
6
6
  * rd - Moves front-end resources to a specified directory
@@ -8,7 +8,9 @@ const program = require('commander');
8
8
  program
9
9
  .command('rd')
10
10
  .description('Move frontend resources to public/dist')
11
- .option('--dist-dir <folder>', 'title to use before name', './frontend/dist')
11
+ .option('--config <folder>', 'config file', './electron/config/bin.js')
12
+ .option('--dist <folder>', 'title to use before name')
13
+ .option('--target <folder>', 'title to use before name')
12
14
  .action(function() {
13
15
  const replaceDist = require('./tools/replaceDist');
14
16
  replaceDist.run(this.opts());
@@ -20,7 +22,7 @@ program
20
22
  program
21
23
  .command('encrypt')
22
24
  .description('Code encryption')
23
- .option('--config <folder>', 'config file', './electron/config/encrypt.js')
25
+ .option('--config <folder>', 'config file')
24
26
  .option('--out <folder>', 'output directory', './public')
25
27
  .action(function() {
26
28
  const encrypt = require('./tools/encrypt');
@@ -55,11 +57,36 @@ program
55
57
  */
56
58
  program
57
59
  .command('dev')
58
- .description('create frontend-server and electron-server')
60
+ .description('create frontend-serve and electron-serve')
61
+ .option('--config <folder>', 'config file', './electron/config/bin.js')
62
+ .option('--serve <mode>', 'serve mode')
63
+ .action(function() {
64
+ const serve = require('./tools/serve');
65
+ serve.dev(this.opts());
66
+ });
67
+
68
+ /**
69
+ * build
70
+ */
71
+ program
72
+ .command('build')
73
+ .description('build frontend dist')
74
+ .option('--config <folder>', 'config file', './electron/config/bin.js')
75
+ .action(function() {
76
+ const serve = require('./tools/serve');
77
+ serve.build(this.opts());
78
+ });
79
+
80
+ /**
81
+ * start
82
+ */
83
+ program
84
+ .command('start')
85
+ .description('preview effect')
59
86
  .option('--config <folder>', 'config file', './electron/config/bin.js')
60
87
  .action(function() {
61
- const frontend = require('./tools/frontend');
62
- frontend.serve(this.opts());
88
+ const serve = require('./tools/serve');
89
+ serve.start(this.opts());
63
90
  });
64
91
 
65
- program.parse();
92
+ program.parse();
package/lib/utils.js CHANGED
@@ -7,8 +7,17 @@ const is = require('is-type-of');
7
7
 
8
8
  const _basePath = process.cwd();
9
9
 
10
+ function checkConfig(prop) {
11
+ const filepath = path.join(_basePath, prop);
12
+ if (fs.existsSync(filepath)) {
13
+ return true;
14
+ }
15
+
16
+ return false;
17
+ }
18
+
10
19
  function loadConfig(prop) {
11
- const configFile = prop || './electron/config/bin.js';
20
+ const configFile = prop;
12
21
  const filepath = path.join(_basePath, configFile);
13
22
  if (!fs.existsSync(filepath)) {
14
23
  const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
@@ -25,6 +34,78 @@ function loadConfig(prop) {
25
34
  return ret || {};
26
35
  };
27
36
 
37
+ function loadEncryptConfig() {
38
+ const configFile = './electron/config/encrypt.js';
39
+ const filepath = path.join(_basePath, configFile);
40
+ if (!fs.existsSync(filepath)) {
41
+ const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
42
+ throw new Error(errorTips)
43
+ }
44
+ const obj = require(filepath);
45
+ if (!obj) return obj;
46
+
47
+ let ret = obj;
48
+ if (is.function(obj) && !is.class(obj)) {
49
+ ret = obj();
50
+ }
51
+
52
+ return ret || {};
53
+ };
54
+
55
+ /**
56
+ * get electron program
57
+ */
58
+ function getElectronProgram() {
59
+ let electronPath
60
+ const electronModulePath = path.dirname(require.resolve('electron'))
61
+ const pathFile = path.join(electronModulePath, 'path.txt')
62
+ const executablePath = fs.readFileSync(pathFile, 'utf-8')
63
+ if (executablePath) {
64
+ electronPath = path.join(electronModulePath, 'dist', executablePath)
65
+ } else {
66
+ throw new Error('Check that electron is installed!')
67
+ }
68
+ return electronPath;
69
+ };
70
+
71
+ /**
72
+ * 版本号比较
73
+ */
74
+ function compareVersion(v1, v2) {
75
+ v1 = v1.split('.')
76
+ v2 = v2.split('.')
77
+ const len = Math.max(v1.length, v2.length)
78
+
79
+ while (v1.length < len) {
80
+ v1.push('0')
81
+ }
82
+ while (v2.length < len) {
83
+ v2.push('0')
84
+ }
85
+
86
+ for (let i = 0; i < len; i++) {
87
+ const num1 = parseInt(v1[i])
88
+ const num2 = parseInt(v2[i])
89
+
90
+ if (num1 > num2) {
91
+ return 1
92
+ } else if (num1 < num2) {
93
+ return -1
94
+ }
95
+ }
96
+
97
+ return 0
98
+ }
99
+
100
+ function isWindows(prop) {
101
+ return process.platform === 'win32'
102
+ }
103
+
28
104
  module.exports = {
29
- loadConfig
105
+ loadConfig,
106
+ checkConfig,
107
+ loadEncryptConfig,
108
+ getElectronProgram,
109
+ compareVersion,
110
+ isWindows
30
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "1.2.0-bete.1",
3
+ "version": "1.2.0",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +15,7 @@
15
15
  "bytenode": "^1.3.6",
16
16
  "chalk": "^4.1.2",
17
17
  "commander": "^11.0.0",
18
+ "cross-spawn": "^7.0.3",
18
19
  "fs-extra": "^10.0.0",
19
20
  "globby": "^10.0.0",
20
21
  "is-type-of": "^1.2.1",
package/tools/encrypt.js CHANGED
@@ -9,16 +9,27 @@ const crypto = require('crypto');
9
9
  const JavaScriptObfuscator = require('javascript-obfuscator');
10
10
  const globby = require('globby');
11
11
  const chalk = require('chalk');
12
+ const Utils = require('../lib/utils');
12
13
 
13
14
  class Encrypt {
14
15
  constructor(options = {}) {
15
16
  // cli args
16
17
  const outputFolder = options.out || './public';
17
- const configFile = options.config || './electron/config/encrypt.js';
18
+ const configFile = options.config || './electron/config/bin.js';
18
19
 
19
20
  this.basePath = process.cwd();
20
21
  this.encryptCodeDir = path.join(this.basePath, outputFolder);
21
- this.config = this.loadConfig(configFile);
22
+
23
+ // 先从 bin config获取,没有的话从 config/encrypt.js
24
+ const hasConfig = Utils.checkConfig(configFile);
25
+ if (hasConfig) {
26
+ const cfg = Utils.loadConfig(configFile);
27
+ this.config = cfg.encrypt;
28
+ }
29
+ if (!this.config) {
30
+ this.config = Utils.loadEncryptConfig();
31
+ }
32
+
22
33
  this.filesExt = this.config.fileExt || ['.js'];
23
34
  this.type = this.config.type || 'confusion';
24
35
  this.bOpt = this.config.bytecodeOptions || {};
@@ -38,8 +49,7 @@ class Encrypt {
38
49
  }
39
50
 
40
51
  this.codefiles = this._initCodeFiles();
41
- //console.log('[ee-core] [encrypt] codefiles:', this.codefiles);
42
- console.log('[ee-core] [encrypt] cleanFiles:', this.cleanFiles);
52
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'cleanFiles:' + this.cleanFiles);
43
53
  }
44
54
 
45
55
  /**
@@ -59,7 +69,7 @@ class Encrypt {
59
69
  // clean
60
70
  this.cleanCode();
61
71
 
62
- console.log('[ee-core] [encrypt] backup start');
72
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup start');
63
73
  if (this.patterns) {
64
74
  this.codefiles.forEach((filepath) => {
65
75
  let source = path.join(this.basePath, filepath);
@@ -74,13 +84,13 @@ class Encrypt {
74
84
  // check code dir
75
85
  let codeDirPath = path.join(this.basePath, this.dirs[i]);
76
86
  if (!fs.existsSync(codeDirPath)) {
77
- console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
87
+ console.log('[ee-bin] [encrypt] ERROR: backup %s is not exist', codeDirPath);
78
88
  return
79
89
  }
80
90
 
81
91
  // copy
82
92
  let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
83
- console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
93
+ console.log('[ee-bin] [encrypt] backup target Dir:', targetDir);
84
94
  if (!fs.existsSync(targetDir)) {
85
95
  this.mkdir(targetDir);
86
96
  this.chmodPath(targetDir, '777');
@@ -90,7 +100,7 @@ class Encrypt {
90
100
  }
91
101
  }
92
102
 
93
- console.log('[ee-core] [encrypt] backup end');
103
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup end');
94
104
  return true;
95
105
  }
96
106
 
@@ -101,7 +111,7 @@ class Encrypt {
101
111
  this.cleanFiles.forEach((file) => {
102
112
  let tmpFile = path.join(this.basePath, file);
103
113
  this.rmBackup(tmpFile);
104
- console.log('[ee-core] [encrypt] clean up tmp files:', tmpFile);
114
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files:' + chalk.magenta(`${tmpFile}`));
105
115
  })
106
116
  }
107
117
 
@@ -109,7 +119,7 @@ class Encrypt {
109
119
  * 加密代码
110
120
  */
111
121
  encrypt() {
112
- console.log('[ee-core] [encrypt] start ciphering');
122
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'start ciphering');
113
123
  if (this.patterns) {
114
124
  for (const file of this.codefiles) {
115
125
  const fullpath = path.join(this.encryptCodeDir, file);
@@ -125,15 +135,15 @@ class Encrypt {
125
135
  }
126
136
  } else {
127
137
  // 旧逻辑,将废弃
128
- console.log('[ee-core] [encrypt] !!!!!! please use the new encryption method !!!!!!');
138
+ console.log('[ee-bin] [encrypt] !!!!!! please use the new encryption method !!!!!!');
129
139
  for (let i = 0; i < this.dirs.length; i++) {
130
140
  let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
131
141
  this.loop(codeDirPath);
132
142
  }
133
- console.log('[ee-core] [encrypt] !!!!!! please use the new encryption method !!!!!!');
143
+ console.log('[ee-bin] [encrypt] !!!!!! please use the new encryption method !!!!!!');
134
144
  }
135
145
 
136
- console.log('[ee-core] [encrypt] end ciphering');
146
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
137
147
  };
138
148
 
139
149
  /**
@@ -163,7 +173,7 @@ class Encrypt {
163
173
  generate(curPath, type) {
164
174
  let encryptType = type ? type : this.type;
165
175
 
166
- let tips = '[ee-core] [encrypt] file: ' + chalk.green(`${curPath}`) + ' ' + chalk.blue(`(${encryptType})`);
176
+ let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
167
177
  console.log(tips);
168
178
 
169
179
  if (encryptType == 'bytecode') {
@@ -272,23 +282,6 @@ class Encrypt {
272
282
  }
273
283
  };
274
284
 
275
- loadConfig(prop) {
276
- const filepath = path.join(this.basePath, prop);
277
- if (!fs.existsSync(filepath)) {
278
- const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
279
- throw new Error(errorTips)
280
- }
281
- const obj = require(filepath);
282
- if (!obj) return obj;
283
-
284
- let ret = obj;
285
- if (is.function(obj) && !is.class(obj)) {
286
- ret = obj();
287
- }
288
-
289
- return ret || {};
290
- };
291
-
292
285
  md5(file) {
293
286
  const buffer = fs.readFileSync(file);
294
287
  const hash = crypto.createHash('md5');
@@ -312,7 +305,7 @@ const clean = (options = {}) => {
312
305
  const tmpFile = path.join(process.cwd(), file);
313
306
  if (fs.existsSync(tmpFile)) {
314
307
  fsPro.removeSync(tmpFile);
315
- console.log('[ee-core] [encrypt] clean up tmp files:', tmpFile);
308
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
316
309
  }
317
310
  })
318
311
  }
@@ -4,6 +4,7 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const fsPro = require('fs-extra');
6
6
  const chalk = require('chalk');
7
+ const Utils = require('../lib/utils');
7
8
 
8
9
  /**
9
10
  * 资源替换
@@ -17,80 +18,63 @@ const chalk = require('chalk');
17
18
  run(options = {}) {
18
19
  console.log('[ee-bin] [rd] Start moving resources');
19
20
  const homeDir = process.cwd();
21
+ let { dist, target, config } = options;
22
+
23
+ let distDir = './frontend/dist';
24
+ let targetDir = './public/dist';
25
+
26
+ // 命令行优先
27
+ if (dist) {
28
+ distDir = dist;
29
+ }
30
+ if (target) {
31
+ targetDir = target;
32
+ }
33
+
34
+ // 如果命令行没参数,从bin config 获取
35
+ if (!dist && !target) {
36
+ const hasConfig = Utils.checkConfig(config);
37
+ if (hasConfig) {
38
+ const cfg = Utils.loadConfig(config);
39
+ if (cfg.rd && cfg.rd.dist) {
40
+ distDir = cfg.rd.dist;
41
+ }
42
+ if (cfg.rd && cfg.rd.target) {
43
+ targetDir = cfg.rd.target;
44
+ }
45
+ }
46
+ }
20
47
 
21
- // argv
22
- const distDir = options.distDir;
23
48
  const sourceDir = path.join(homeDir, distDir);
24
- const sourceIndexFile = path.join(sourceDir, 'index.html');
25
-
26
- if (!this._fileExist(sourceIndexFile)) {
27
- console.info(sourceIndexFile);
49
+ if (!fs.existsSync(sourceDir)) {
28
50
  const errorTips = chalk.bgRed('Error') + ' Frontend resource does not exist, please build !';
29
51
  console.error(errorTips);
30
52
  return
31
53
  }
32
54
 
33
55
  // 清空历史资源 并 复制到ee资源目录
34
- const eeResourceDir = path.join(homeDir, 'public', 'dist');
56
+ const eeResourceDir = path.join(homeDir, targetDir);
35
57
  if (!fs.existsSync(eeResourceDir)) {
36
58
  fs.mkdirSync(eeResourceDir, {recursive: true, mode: 0o777});
59
+ } else {
60
+ this._rmFolder(eeResourceDir);
61
+ console.log('[ee-bin] [rd] Clear history resources:', eeResourceDir);
37
62
  }
38
- this._rmFolder(eeResourceDir);
39
- console.log('[ee-bin] [rd] Clear history resources:', eeResourceDir);
40
63
 
41
64
  fsPro.copySync(sourceDir, eeResourceDir);
42
65
  console.log('[ee-bin] [rd] Copy a resource to:', eeResourceDir);
43
66
  console.log('[ee-bin] [rd] End');
44
67
  },
45
68
 
46
- _fileExist(filePath) {
47
- try {
48
- return fs.statSync(filePath).isFile();
49
- } catch (err) {
50
- // const errorTips = chalk.bgRed('Error') + ' [ee-bin] [rd] ';
51
- // console.error(errorTips, err);
52
- return false;
53
- }
54
- },
55
-
56
69
  /**
57
70
  * 删除文件夹
58
71
  */
59
72
  _rmFolder(folder) {
60
73
  const nodeVersion = (process.versions && process.versions.node) || null;
61
- if (nodeVersion && this._compareVersion(nodeVersion, '14.14.0') == 1) {
74
+ if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
62
75
  fs.rmSync(folder, {recursive: true});
63
76
  } else {
64
77
  fs.rmdirSync(folder, {recursive: true});
65
78
  }
66
79
  },
67
-
68
- /**
69
- * 版本号比较
70
- */
71
- _compareVersion(v1, v2) {
72
- v1 = v1.split('.')
73
- v2 = v2.split('.')
74
- const len = Math.max(v1.length, v2.length)
75
-
76
- while (v1.length < len) {
77
- v1.push('0')
78
- }
79
- while (v2.length < len) {
80
- v2.push('0')
81
- }
82
-
83
- for (let i = 0; i < len; i++) {
84
- const num1 = parseInt(v1[i])
85
- const num2 = parseInt(v2[i])
86
-
87
- if (num1 > num2) {
88
- return 1
89
- } else if (num1 < num2) {
90
- return -1
91
- }
92
- }
93
-
94
- return 0
95
- }
96
80
  }
package/tools/serve.js ADDED
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const Utils = require('../lib/utils');
5
+ const is = require('is-type-of');
6
+ const chalk = require('chalk');
7
+ const crossSpawn = require('cross-spawn');
8
+
9
+ module.exports = {
10
+
11
+ frontendProcess: undefined,
12
+
13
+ electronProcess: undefined,
14
+
15
+ /**
16
+ * 启动前端、主进程服务
17
+ */
18
+ dev(options = {}) {
19
+ const { config, serve } = options;
20
+ const binCfg = Utils.loadConfig(config);
21
+ const { frontend, electron } = binCfg.dev;
22
+
23
+ if (serve == 'frontend') {
24
+ this.frontendServe(frontend);
25
+ return;
26
+ }
27
+
28
+ if (serve == 'electron') {
29
+ this.electronServe(electron);
30
+ return;
31
+ }
32
+
33
+ this.frontendServe(frontend);
34
+ this.electronServe(electron);
35
+ },
36
+
37
+ /**
38
+ * 启动主进程服务
39
+ */
40
+ start(options = {}) {
41
+ const { config } = options;
42
+ const binCfg = Utils.loadConfig(config);
43
+
44
+ this.electronServe(binCfg.start);
45
+ },
46
+
47
+ sleep(ms) {
48
+ return new Promise(resolve => setTimeout(resolve, ms));
49
+ },
50
+
51
+ /**
52
+ * start frontend serve
53
+ */
54
+ frontendServe(cfg) {
55
+ // 如果是 file:// 协议,则不启动
56
+ if (cfg.protocol == 'file://') {
57
+ return
58
+ }
59
+ // 模拟前端启动慢
60
+ // await this.sleep(5 * 1000);
61
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the frontend serve...'));
62
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
63
+
64
+ const frontendDir = path.join(process.cwd(), cfg.directory);
65
+ const frontendArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
66
+ this.frontendProcess = crossSpawn(
67
+ cfg.cmd,
68
+ frontendArgs,
69
+ { stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024 },
70
+ );
71
+ this.frontendProcess.on('exit', () => {
72
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('frontend serve exit'));
73
+ });
74
+ },
75
+
76
+ /**
77
+ * start electron serve
78
+ */
79
+ electronServe(cfg) {
80
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the electron serve...'));
81
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
82
+
83
+ const electronDir = path.join(process.cwd(), cfg.directory);
84
+ const electronArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
85
+
86
+ this.electronProcess = crossSpawn(
87
+ cfg.cmd,
88
+ electronArgs,
89
+ {stdio: 'inherit', cwd: electronDir, maxBuffer: 1024 * 1024 * 1024 }
90
+ );
91
+
92
+ this.electronProcess.on('exit', () => {
93
+ console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Press "CTRL+C" to exit'));
94
+ });
95
+ },
96
+
97
+ /**
98
+ * 构建前端 dist
99
+ */
100
+ build(options = {}) {
101
+ const { config } = options;
102
+ const binCfg = Utils.loadConfig(config);
103
+ const cfg = binCfg.build;
104
+
105
+ // start build frontend dist
106
+ console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('Build frontend dist'));
107
+ console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('config:'), cfg);
108
+
109
+ const frontendDir = path.join(process.cwd(), cfg.directory);
110
+ const buildArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
111
+
112
+ const buildProcess = crossSpawn(
113
+ cfg.cmd,
114
+ buildArgs,
115
+ { stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024 },
116
+ );
117
+ buildProcess.on('exit', () => {
118
+ console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
119
+ });
120
+ },
121
+ }
package/tools/frontend.js DELETED
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const { spawn, spawnSync, exec, execFile } = require('child_process');
6
- const Utils = require('../lib/utils');
7
- const is = require('is-type-of');
8
-
9
- module.exports = {
10
-
11
- electronServer: undefined,
12
-
13
- frontendServer: undefined,
14
-
15
- /**
16
- * 启动前端、主进程服务
17
- */
18
- serve(options = {}) {
19
- const { config } = options;
20
- const cfg = Utils.loadConfig(config);
21
-
22
- const { frontend, main } = cfg;
23
- console.log('frontend:', frontend);
24
- console.log('main:', main);
25
-
26
- // const frontendDir = path.join(process.cwd(), frontend.directory);
27
- // const frontendArgs = is.string(frontend.args) ? [frontend.args] : frontend.args;
28
- // console.log('frontendDir:', frontendDir);
29
- // console.log('frontendArgs:', frontendArgs);
30
-
31
- //['--host --port 8080'], ['--host', '--port 8080'],
32
- this.frontendServer = spawnSync(
33
- 'vite',
34
- ['--host', '--port=8080'],
35
- {
36
- stdio: 'inherit',
37
- cwd: path.join(process.cwd(), 'frontend'),
38
- shell: true,
39
- }
40
- );
41
- console.log('this.frontendServer:', this.frontendServer);
42
- // todo execSync衍生了shell无法找到cmd
43
- // this.frontendServer = execSync(frontend.exec, {stdio: 'inherit', cwd: frontendDir});
44
- // spawnSync(
45
- // frontend.cmd,
46
- // frontendArgs,
47
- // {
48
- // stdio: 'inherit',
49
- // cwd: frontendDir
50
- // }
51
- // );
52
-
53
- const mainDir = path.join(process.cwd(), main.directory);
54
- const mainArgs = is.string(main.args) ? [main.args] : main.args;
55
- const electronPath = this._getElectronPath();
56
- this.electronServer = spawn(electronPath, mainArgs, { stdio: 'inherit' });
57
-
58
- this._init();
59
- },
60
-
61
- _getElectronPath() {
62
- let electronExecPath = ''
63
- const electronModulePath = path.dirname(require.resolve('electron'))
64
- const pathFile = path.join(electronModulePath, 'path.txt')
65
- let executablePath
66
- if (fs.existsSync(pathFile)) {
67
- executablePath = fs.readFileSync(pathFile, 'utf-8')
68
- }
69
- if (executablePath) {
70
- electronExecPath = path.join(electronModulePath, 'dist', executablePath)
71
- } else {
72
- throw new Error('Electron uninstall')
73
- }
74
- return electronExecPath
75
- },
76
-
77
- /**
78
- * 事件监听
79
- */
80
- _init() {
81
- // this.frontendServer.on('data', (data) => {
82
- // console.log(`[ee-bin] [serve] frontend-server data:${data}`);
83
- // });
84
- // this.frontendServer.on('exit', (code, signal) => {
85
- // console.log(`[ee-bin] [serve] frontend-server code:${code}, signal:${signal}`);
86
- // });
87
-
88
- // this.frontendServer.on('error', (err) => {
89
- // console.log(`[ee-bin] [serve] frontendServer error: ${err}`);
90
- // });
91
-
92
- // this.electronServer.on('exit', (code, signal) => {
93
- // console.log(`[ee-bin] [serve] electronServer code:${code}, signal:${signal}`);
94
- // });
95
-
96
- // this.electronServer.on('error', (err) => {
97
- // console.log(`[ee-bin] [serve] electronServer error: ${err}`);
98
- // });
99
- }
100
- }