ee-bin 4.1.5 → 4.1.6-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/config/bin_default.js +1 -1
- package/lib/utils.js +18 -3
- package/package.json +1 -1
- package/tools/serve.js +61 -18
package/config/bin_default.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -144,11 +144,11 @@ function getPackage () {
|
|
|
144
144
|
return content;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
function readJsonSync (filepath) {
|
|
147
|
+
function readJsonSync (filepath, encoding = 'utf8') {
|
|
148
148
|
if (!fs.existsSync(filepath)) {
|
|
149
149
|
throw new Error(filepath + ' is not found');
|
|
150
150
|
}
|
|
151
|
-
return JSON.parse(fs.readFileSync(filepath));
|
|
151
|
+
return JSON.parse(fs.readFileSync(filepath, { encoding }));
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
function writeJsonSync (filepath, str, options) {
|
|
@@ -191,6 +191,20 @@ function getPlatform(delimiter = "_", isDiffArch = false) {
|
|
|
191
191
|
return os;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// Get cmd parameter by name
|
|
195
|
+
function getArgumentByName(args, name) {
|
|
196
|
+
if (!args) {
|
|
197
|
+
args = process.argv;
|
|
198
|
+
}
|
|
199
|
+
for (let i = 0; i < args.length; i++) {
|
|
200
|
+
const item = args[i];
|
|
201
|
+
const prefixKey = `--${name}=`;
|
|
202
|
+
if (item.indexOf(prefixKey) !== -1) {
|
|
203
|
+
return item.substring(prefixKey.length);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
194
208
|
module.exports = {
|
|
195
209
|
loadConfig,
|
|
196
210
|
getElectronProgram,
|
|
@@ -205,5 +219,6 @@ module.exports = {
|
|
|
205
219
|
rm,
|
|
206
220
|
getPackage,
|
|
207
221
|
readJsonSync,
|
|
208
|
-
writeJsonSync
|
|
222
|
+
writeJsonSync,
|
|
223
|
+
getArgumentByName
|
|
209
224
|
}
|
package/package.json
CHANGED
package/tools/serve.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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, isWindows } = require('../lib/utils');
|
|
6
|
+
const { loadConfig, isWindows, getArgumentByName, readJsonSync, writeJsonSync } = require('../lib/utils');
|
|
7
7
|
const is = require('is-type-of');
|
|
8
8
|
const chalk = require('chalk');
|
|
9
9
|
const crossSpawn = require('cross-spawn');
|
|
@@ -18,7 +18,8 @@ class ServeProcess {
|
|
|
18
18
|
process.env.NODE_ENV = 'prod'; // dev / prod
|
|
19
19
|
this.execProcess = {};
|
|
20
20
|
this.electronDir = './electron';
|
|
21
|
-
this.
|
|
21
|
+
this.bundleDir = './public/electron';
|
|
22
|
+
this.pkgPath = './package.json';
|
|
22
23
|
this._init();
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -55,7 +56,7 @@ class ServeProcess {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
// Cleaning work before the end of the process
|
|
58
|
-
await this.sleep(
|
|
59
|
+
await this.sleep(500);
|
|
59
60
|
currentProcess.forEach((p) => {
|
|
60
61
|
kill(p.pid);
|
|
61
62
|
debug(`Kill ${chalk.blue(p.name)} server, pid: ${p.pid}`);
|
|
@@ -64,10 +65,10 @@ class ServeProcess {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
+
* Start frontend and main process services
|
|
68
69
|
*/
|
|
69
70
|
dev(options = {}) {
|
|
70
|
-
//
|
|
71
|
+
// Set an environment variable
|
|
71
72
|
process.env.NODE_ENV = 'dev';
|
|
72
73
|
const { config, serve } = options;
|
|
73
74
|
const binCfg = loadConfig(config);
|
|
@@ -87,8 +88,13 @@ class ServeProcess {
|
|
|
87
88
|
// build electron main code
|
|
88
89
|
const cmds = this._formatCmds(command);
|
|
89
90
|
if (cmds.indexOf("electron") !== -1) {
|
|
90
|
-
// watche electron main code
|
|
91
91
|
const electronConfig = binCmdConfig.electron;
|
|
92
|
+
|
|
93
|
+
// Debugging source code
|
|
94
|
+
const debugging = getArgumentByName(electronConfig.args, 'debuger') == 'true'? true : false;
|
|
95
|
+
this._switchPkgMain(debugging);
|
|
96
|
+
|
|
97
|
+
// watche electron main code
|
|
92
98
|
if (electronConfig.watch) {
|
|
93
99
|
let debounceTimer = null;
|
|
94
100
|
const cmd = 'electron';
|
|
@@ -135,7 +141,7 @@ class ServeProcess {
|
|
|
135
141
|
}
|
|
136
142
|
|
|
137
143
|
/**
|
|
138
|
-
*
|
|
144
|
+
* Start the main process service
|
|
139
145
|
*/
|
|
140
146
|
start(options = {}) {
|
|
141
147
|
const { config } = options;
|
|
@@ -158,10 +164,11 @@ class ServeProcess {
|
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
/**
|
|
161
|
-
*
|
|
167
|
+
* build
|
|
162
168
|
*/
|
|
163
169
|
build(options = {}) {
|
|
164
|
-
const { config,
|
|
170
|
+
const { config, env } = options;
|
|
171
|
+
let { cmds } = options;
|
|
165
172
|
process.env.NODE_ENV = env;
|
|
166
173
|
const binCfg = loadConfig(config);
|
|
167
174
|
const binCmd = 'build';
|
|
@@ -173,9 +180,18 @@ class ServeProcess {
|
|
|
173
180
|
return
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
|
|
183
|
+
// [todo] If there is 'electron' , then execute 'electron' first and recycle other commands
|
|
184
|
+
// should it be placed in multiExec() and maintain the execution order
|
|
185
|
+
const commands = this._formatCmds(cmds);
|
|
186
|
+
if (commands.indexOf("electron") !== -1) {
|
|
177
187
|
this.bundle(binCmdConfig.electron);
|
|
178
|
-
|
|
188
|
+
// Remove electron cmd and execute others
|
|
189
|
+
const index = commands.indexOf("electron");
|
|
190
|
+
commands.splice(index, 1);
|
|
191
|
+
cmds = commands.join();
|
|
192
|
+
|
|
193
|
+
// switch pkg.main
|
|
194
|
+
this._switchPkgMain(false)
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
const opt = {
|
|
@@ -187,7 +203,7 @@ class ServeProcess {
|
|
|
187
203
|
}
|
|
188
204
|
|
|
189
205
|
/**
|
|
190
|
-
*
|
|
206
|
+
* Execute custom commands
|
|
191
207
|
*/
|
|
192
208
|
exec(options = {}) {
|
|
193
209
|
const { config, cmds } = options;
|
|
@@ -204,19 +220,20 @@ class ServeProcess {
|
|
|
204
220
|
}
|
|
205
221
|
|
|
206
222
|
/**
|
|
207
|
-
*
|
|
223
|
+
* Support multiple commands
|
|
208
224
|
*/
|
|
209
225
|
multiExec(opt = {}) {
|
|
210
226
|
//console.log('multiExec opt:', opt)
|
|
211
227
|
const { binCmd, binCmdConfig, command } = opt;
|
|
212
|
-
const
|
|
228
|
+
const commands = this._formatCmds(command);
|
|
213
229
|
|
|
214
|
-
for (let i = 0; i <
|
|
215
|
-
let cmd =
|
|
230
|
+
for (let i = 0; i < commands.length; i++) {
|
|
231
|
+
let cmd = commands[i];
|
|
216
232
|
const cfg = binCmdConfig[cmd];
|
|
217
233
|
|
|
218
234
|
if (!cfg) {
|
|
219
|
-
|
|
235
|
+
// Running the build electron code separately may be empty
|
|
236
|
+
//console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.yellow(`Warning: [${cmd}] config does not exist` ));
|
|
220
237
|
continue;
|
|
221
238
|
}
|
|
222
239
|
|
|
@@ -261,7 +278,7 @@ class ServeProcess {
|
|
|
261
278
|
const { bundleType } = bundleConfig;
|
|
262
279
|
if (bundleType == 'copy') {
|
|
263
280
|
const srcResource = path.join(process.cwd(), this.electronDir);
|
|
264
|
-
const destResource = path.join(process.cwd(), this.
|
|
281
|
+
const destResource = path.join(process.cwd(), this.bundleDir);
|
|
265
282
|
fsPro.removeSync(destResource);
|
|
266
283
|
fsPro.copySync(srcResource, destResource);
|
|
267
284
|
} else {
|
|
@@ -287,6 +304,32 @@ class ServeProcess {
|
|
|
287
304
|
|
|
288
305
|
return cmds;
|
|
289
306
|
}
|
|
307
|
+
|
|
308
|
+
// Modify the main attribute in package.json
|
|
309
|
+
_switchPkgMain(isDebugger = false) {
|
|
310
|
+
let mainFile = 'main.js';
|
|
311
|
+
const pkgPath = path.join(process.cwd(), this.pkgPath);
|
|
312
|
+
const pkg = readJsonSync(pkgPath);
|
|
313
|
+
const maints = path.join(process.cwd(), this.electronDir, 'main.ts');
|
|
314
|
+
if (fsPro.existsSync(maints)) {
|
|
315
|
+
mainFile = 'main.ts'
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// [todo] Currently only supports JS
|
|
319
|
+
if (isDebugger && mainFile == 'main.js') {
|
|
320
|
+
pkg.main = path.join(this.electronDir, mainFile);
|
|
321
|
+
//console.log("debugger:", pkg.main)
|
|
322
|
+
writeJsonSync(pkgPath, pkg);
|
|
323
|
+
} else {
|
|
324
|
+
// Modify when the path is incorrect to reduce unnecessary operations
|
|
325
|
+
const bundleMainPath = path.join(this.bundleDir, 'main.js');
|
|
326
|
+
//console.log("build:", bundleMainPath)
|
|
327
|
+
if (pkg.main != bundleMainPath) {
|
|
328
|
+
pkg.main = bundleMainPath;
|
|
329
|
+
writeJsonSync(pkgPath, pkg);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
290
333
|
|
|
291
334
|
// env
|
|
292
335
|
isDev() {
|