ee-bin 1.1.0 → 1.2.0-bete.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/index.js +12 -0
- package/lib/utils.js +30 -0
- package/package.json +23 -23
- package/tools/frontend.js +100 -0
package/index.js
CHANGED
|
@@ -50,4 +50,16 @@ program
|
|
|
50
50
|
iconGen.run();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* dev
|
|
55
|
+
*/
|
|
56
|
+
program
|
|
57
|
+
.command('dev')
|
|
58
|
+
.description('create frontend-server and electron-server')
|
|
59
|
+
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
60
|
+
.action(function() {
|
|
61
|
+
const frontend = require('./tools/frontend');
|
|
62
|
+
frontend.serve(this.opts());
|
|
63
|
+
});
|
|
64
|
+
|
|
53
65
|
program.parse();
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const is = require('is-type-of');
|
|
7
|
+
|
|
8
|
+
const _basePath = process.cwd();
|
|
9
|
+
|
|
10
|
+
function loadConfig(prop) {
|
|
11
|
+
const configFile = prop || './electron/config/bin.js';
|
|
12
|
+
const filepath = path.join(_basePath, configFile);
|
|
13
|
+
if (!fs.existsSync(filepath)) {
|
|
14
|
+
const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
|
|
15
|
+
throw new Error(errorTips)
|
|
16
|
+
}
|
|
17
|
+
const obj = require(filepath);
|
|
18
|
+
if (!obj) return obj;
|
|
19
|
+
|
|
20
|
+
let ret = obj;
|
|
21
|
+
if (is.function(obj) && !is.class(obj)) {
|
|
22
|
+
ret = obj();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return ret || {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
loadConfig
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ee-bin",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "ee bin",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"bin": {
|
|
12
|
-
"ee-bin": "index.js"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"bytenode": "^1.3.6",
|
|
16
|
-
"chalk": "^4.1.2",
|
|
17
|
-
"commander": "^11.0.0",
|
|
18
|
-
"fs-extra": "^10.0.0",
|
|
19
|
-
"globby": "^10.0.0",
|
|
20
|
-
"is-type-of": "^1.2.1",
|
|
21
|
-
"javascript-obfuscator": "^4.0.2"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ee-bin",
|
|
3
|
+
"version": "1.2.0-bete.1",
|
|
4
|
+
"description": "ee bin",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"bin": {
|
|
12
|
+
"ee-bin": "index.js"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"bytenode": "^1.3.6",
|
|
16
|
+
"chalk": "^4.1.2",
|
|
17
|
+
"commander": "^11.0.0",
|
|
18
|
+
"fs-extra": "^10.0.0",
|
|
19
|
+
"globby": "^10.0.0",
|
|
20
|
+
"is-type-of": "^1.2.1",
|
|
21
|
+
"javascript-obfuscator": "^4.0.2"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
}
|