ee-bin 1.2.0-beta.4 → 1.2.0-beta.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.
- package/index.js +1 -0
- package/package.json +2 -2
- package/tools/serve.js +45 -80
package/index.js
CHANGED
|
@@ -59,6 +59,7 @@ program
|
|
|
59
59
|
.command('dev')
|
|
60
60
|
.description('create frontend-serve and electron-serve')
|
|
61
61
|
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
62
|
+
.option('--serve <mode>', 'serve mode')
|
|
62
63
|
.action(function() {
|
|
63
64
|
const serve = require('./tools/serve');
|
|
64
65
|
serve.dev(this.opts());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-bin",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.5",
|
|
4
4
|
"description": "ee bin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,9 +15,9 @@
|
|
|
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
|
-
"iconv-lite": "^0.6.3",
|
|
21
21
|
"is-type-of": "^1.2.1",
|
|
22
22
|
"javascript-obfuscator": "^4.0.2"
|
|
23
23
|
}
|
package/tools/serve.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const { spawn, exec } = require('child_process');
|
|
5
4
|
const Utils = require('../lib/utils');
|
|
6
5
|
const is = require('is-type-of');
|
|
7
6
|
const chalk = require('chalk');
|
|
8
|
-
const
|
|
9
|
-
const { Buffer } = require('buffer');
|
|
7
|
+
const crossSpawn = require('cross-spawn');
|
|
10
8
|
|
|
11
9
|
module.exports = {
|
|
12
10
|
|
|
@@ -18,9 +16,20 @@ module.exports = {
|
|
|
18
16
|
* 启动前端、主进程服务
|
|
19
17
|
*/
|
|
20
18
|
dev(options = {}) {
|
|
21
|
-
const { config } = options;
|
|
22
|
-
const
|
|
23
|
-
const { frontend, electron } =
|
|
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
|
+
|
|
24
33
|
this.frontendServe(frontend);
|
|
25
34
|
this.electronServe(electron);
|
|
26
35
|
},
|
|
@@ -30,9 +39,9 @@ module.exports = {
|
|
|
30
39
|
*/
|
|
31
40
|
start(options = {}) {
|
|
32
41
|
const { config } = options;
|
|
33
|
-
const
|
|
42
|
+
const binCfg = Utils.loadConfig(config);
|
|
34
43
|
|
|
35
|
-
this.electronServe(
|
|
44
|
+
this.electronServe(binCfg.start);
|
|
36
45
|
},
|
|
37
46
|
|
|
38
47
|
sleep(ms) {
|
|
@@ -40,77 +49,48 @@ module.exports = {
|
|
|
40
49
|
},
|
|
41
50
|
|
|
42
51
|
/**
|
|
43
|
-
*
|
|
52
|
+
* start frontend serve
|
|
44
53
|
*/
|
|
45
|
-
|
|
54
|
+
frontendServe(cfg) {
|
|
46
55
|
// 如果是 file:// 协议,则不启动
|
|
47
56
|
if (cfg.protocol == 'file://') {
|
|
48
57
|
return
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
//
|
|
59
|
+
// 模拟前端启动慢
|
|
60
|
+
// await this.sleep(5 * 1000);
|
|
52
61
|
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the frontend serve...'));
|
|
53
62
|
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
|
|
54
63
|
|
|
55
64
|
const frontendDir = path.join(process.cwd(), cfg.directory);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const msgEncoding = isWindows ? 'cp936' : 'utf8';
|
|
59
|
-
this.frontendProcess = exec(
|
|
65
|
+
const frontendArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
|
|
66
|
+
this.frontendProcess = crossSpawn(
|
|
60
67
|
cfg.cmd,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (err) {
|
|
64
|
-
const errMsg = iconv.decode(new Buffer.from(err.message, cmdEncoding), msgEncoding);
|
|
65
|
-
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.red(`Error: ${errMsg}`))
|
|
66
|
-
process.exit();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
68
|
+
frontendArgs,
|
|
69
|
+
{ stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024 },
|
|
69
70
|
);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
let out = data;
|
|
73
|
-
if (isWindows) {
|
|
74
|
-
out = iconv.decode(new Buffer.from(data, cmdEncoding), 'utf8');
|
|
75
|
-
}
|
|
76
|
-
console.log(chalk.blue('[ee-bin] [dev] ') + `frontend ${out}`);
|
|
77
|
-
});
|
|
78
|
-
this.frontendProcess.stderr.on('data', (data) => {
|
|
79
|
-
let out = data;
|
|
80
|
-
if (isWindows) {
|
|
81
|
-
out = iconv.decode(new Buffer.from(data, cmdEncoding), 'utf8');
|
|
82
|
-
}
|
|
83
|
-
console.error(chalk.blue('[ee-bin] [dev] ') + `frontend ${out}`);
|
|
71
|
+
this.frontendProcess.on('exit', () => {
|
|
72
|
+
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('frontend serve exit'));
|
|
84
73
|
});
|
|
85
74
|
},
|
|
86
75
|
|
|
87
76
|
/**
|
|
88
|
-
*
|
|
77
|
+
* start electron serve
|
|
89
78
|
*/
|
|
90
79
|
electronServe(cfg) {
|
|
91
|
-
// start electron serve
|
|
92
80
|
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Start the electron serve...'));
|
|
93
81
|
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('config:'), JSON.stringify(cfg));
|
|
94
82
|
|
|
95
83
|
const electronDir = path.join(process.cwd(), cfg.directory);
|
|
96
84
|
const electronArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (cfg.cmd == 'electron') {
|
|
101
|
-
electronProgram = Utils.getElectronProgram();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.electronProcess = spawn(
|
|
105
|
-
electronProgram,
|
|
86
|
+
this.electronProcess = crossSpawn(
|
|
87
|
+
cfg.cmd,
|
|
106
88
|
electronArgs,
|
|
107
|
-
{stdio: 'inherit', cwd: electronDir,}
|
|
89
|
+
{stdio: 'inherit', cwd: electronDir, maxBuffer: 1024 * 1024 * 1024 }
|
|
108
90
|
);
|
|
109
91
|
|
|
110
92
|
this.electronProcess.on('exit', () => {
|
|
111
|
-
|
|
112
|
-
process.exit();
|
|
113
|
-
}, 500)
|
|
93
|
+
console.log(chalk.blue('[ee-bin] [dev] ') + chalk.green('Press "CTRL+C" to exit'));
|
|
114
94
|
});
|
|
115
95
|
},
|
|
116
96
|
|
|
@@ -119,38 +99,23 @@ module.exports = {
|
|
|
119
99
|
*/
|
|
120
100
|
build(options = {}) {
|
|
121
101
|
const { config } = options;
|
|
122
|
-
const
|
|
123
|
-
const
|
|
102
|
+
const binCfg = Utils.loadConfig(config);
|
|
103
|
+
const cfg = binCfg.build;
|
|
124
104
|
|
|
125
105
|
// start build frontend dist
|
|
126
106
|
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('Build frontend dist'));
|
|
127
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('config:'),
|
|
107
|
+
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('config:'), cfg);
|
|
128
108
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const buildProcess = exec(
|
|
137
|
-
buildCfg.cmd,
|
|
138
|
-
{ stdio: 'inherit', cwd: frontendDir, }, // maxBuffer: 1024 * 1024 * 1024
|
|
139
|
-
(err) => {
|
|
140
|
-
if (err) {
|
|
141
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.red(`Error: ${err.message}`))
|
|
142
|
-
process.exit();
|
|
143
|
-
}
|
|
144
|
-
clearInterval(buildProgress);
|
|
145
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
|
|
146
|
-
}
|
|
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 },
|
|
147
116
|
);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
buildProcess.stderr.on('data', (data) => {
|
|
153
|
-
console.error(chalk.blue('[ee-bin] [build] ') + chalk.yellow(`Warning: ${data}`));
|
|
154
|
-
});
|
|
117
|
+
buildProcess.on('exit', () => {
|
|
118
|
+
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
|
|
119
|
+
});
|
|
155
120
|
},
|
|
156
121
|
}
|