ee-bin 1.2.0-beta.3 → 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 +23 -10
- package/lib/utils.js +53 -1
- package/package.json +2 -1
- package/tools/replaceDist.js +30 -35
- package/tools/serve.js +121 -0
- package/tools/frontend.js +0 -82
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,9 +8,9 @@ const program = require('commander');
|
|
|
8
8
|
program
|
|
9
9
|
.command('rd')
|
|
10
10
|
.description('Move frontend resources to public/dist')
|
|
11
|
-
.option('--
|
|
12
|
-
.option('--dist <folder>', 'title to use before name'
|
|
13
|
-
.option('--target <folder>', 'title to use before name'
|
|
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')
|
|
14
14
|
.action(function() {
|
|
15
15
|
const replaceDist = require('./tools/replaceDist');
|
|
16
16
|
replaceDist.run(this.opts());
|
|
@@ -57,11 +57,12 @@ program
|
|
|
57
57
|
*/
|
|
58
58
|
program
|
|
59
59
|
.command('dev')
|
|
60
|
-
.description('create frontend-
|
|
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
|
-
const
|
|
64
|
-
|
|
64
|
+
const serve = require('./tools/serve');
|
|
65
|
+
serve.dev(this.opts());
|
|
65
66
|
});
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -72,8 +73,20 @@ program
|
|
|
72
73
|
.description('build frontend dist')
|
|
73
74
|
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
74
75
|
.action(function() {
|
|
75
|
-
const
|
|
76
|
-
|
|
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')
|
|
86
|
+
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
87
|
+
.action(function() {
|
|
88
|
+
const serve = require('./tools/serve');
|
|
89
|
+
serve.start(this.opts());
|
|
77
90
|
});
|
|
78
91
|
|
|
79
|
-
program.parse();
|
|
92
|
+
program.parse();
|
package/lib/utils.js
CHANGED
|
@@ -52,8 +52,60 @@ function loadEncryptConfig() {
|
|
|
52
52
|
return ret || {};
|
|
53
53
|
};
|
|
54
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
|
+
|
|
55
104
|
module.exports = {
|
|
56
105
|
loadConfig,
|
|
57
106
|
checkConfig,
|
|
58
|
-
loadEncryptConfig
|
|
107
|
+
loadEncryptConfig,
|
|
108
|
+
getElectronProgram,
|
|
109
|
+
compareVersion,
|
|
110
|
+
isWindows
|
|
59
111
|
}
|
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,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/replaceDist.js
CHANGED
|
@@ -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,11 +18,34 @@ const chalk = require('chalk');
|
|
|
17
18
|
run(options = {}) {
|
|
18
19
|
console.log('[ee-bin] [rd] Start moving resources');
|
|
19
20
|
const homeDir = process.cwd();
|
|
20
|
-
|
|
21
|
+
let { dist, target, config } = options;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
47
|
+
|
|
48
|
+
const sourceDir = path.join(homeDir, distDir);
|
|
25
49
|
if (!fs.existsSync(sourceDir)) {
|
|
26
50
|
const errorTips = chalk.bgRed('Error') + ' Frontend resource does not exist, please build !';
|
|
27
51
|
console.error(errorTips);
|
|
@@ -29,7 +53,7 @@ const chalk = require('chalk');
|
|
|
29
53
|
}
|
|
30
54
|
|
|
31
55
|
// 清空历史资源 并 复制到ee资源目录
|
|
32
|
-
const eeResourceDir = path.join(homeDir,
|
|
56
|
+
const eeResourceDir = path.join(homeDir, targetDir);
|
|
33
57
|
if (!fs.existsSync(eeResourceDir)) {
|
|
34
58
|
fs.mkdirSync(eeResourceDir, {recursive: true, mode: 0o777});
|
|
35
59
|
} else {
|
|
@@ -47,39 +71,10 @@ const chalk = require('chalk');
|
|
|
47
71
|
*/
|
|
48
72
|
_rmFolder(folder) {
|
|
49
73
|
const nodeVersion = (process.versions && process.versions.node) || null;
|
|
50
|
-
if (nodeVersion &&
|
|
74
|
+
if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
|
|
51
75
|
fs.rmSync(folder, {recursive: true});
|
|
52
76
|
} else {
|
|
53
77
|
fs.rmdirSync(folder, {recursive: true});
|
|
54
78
|
}
|
|
55
79
|
},
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 版本号比较
|
|
59
|
-
*/
|
|
60
|
-
_compareVersion(v1, v2) {
|
|
61
|
-
v1 = v1.split('.')
|
|
62
|
-
v2 = v2.split('.')
|
|
63
|
-
const len = Math.max(v1.length, v2.length)
|
|
64
|
-
|
|
65
|
-
while (v1.length < len) {
|
|
66
|
-
v1.push('0')
|
|
67
|
-
}
|
|
68
|
-
while (v2.length < len) {
|
|
69
|
-
v2.push('0')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
for (let i = 0; i < len; i++) {
|
|
73
|
-
const num1 = parseInt(v1[i])
|
|
74
|
-
const num2 = parseInt(v2[i])
|
|
75
|
-
|
|
76
|
-
if (num1 > num2) {
|
|
77
|
-
return 1
|
|
78
|
-
} else if (num1 < num2) {
|
|
79
|
-
return -1
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return 0
|
|
84
|
-
}
|
|
85
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,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const { spawn, exec } = require('child_process');
|
|
6
|
-
const Utils = require('../lib/utils');
|
|
7
|
-
const is = require('is-type-of');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 启动前端、主进程服务
|
|
14
|
-
*/
|
|
15
|
-
serve(options = {}) {
|
|
16
|
-
const { config } = options;
|
|
17
|
-
const cfg = Utils.loadConfig(config);
|
|
18
|
-
const { frontend, main } = cfg;
|
|
19
|
-
|
|
20
|
-
// start frontend serve
|
|
21
|
-
console.log(chalk.blue('[ee-bin] [serve] ') + chalk.green('Start the frontend serve...'));
|
|
22
|
-
const frontendDir = path.join(process.cwd(), frontend.directory);
|
|
23
|
-
exec(frontend.devCommond, { stdio: 'inherit', cwd: frontendDir});
|
|
24
|
-
|
|
25
|
-
// start electron serve
|
|
26
|
-
console.log(chalk.blue('[ee-bin] [serve] ') + chalk.green('Start the electron serve...'));
|
|
27
|
-
const mainDir = path.join(process.cwd(), main.directory);
|
|
28
|
-
const mainArgs = is.string(main.args) ? [main.args] : main.args;
|
|
29
|
-
const electronPath = this._getElectronPath();
|
|
30
|
-
spawn(electronPath, mainArgs, {
|
|
31
|
-
stdio: 'inherit',
|
|
32
|
-
cwd: mainDir,
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 构建前端 dist
|
|
38
|
-
*/
|
|
39
|
-
build(options = {}) {
|
|
40
|
-
const { config } = options;
|
|
41
|
-
const cfg = Utils.loadConfig(config);
|
|
42
|
-
const { frontend } = cfg;
|
|
43
|
-
|
|
44
|
-
// start build frontend dist
|
|
45
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('Build frontend dist'));
|
|
46
|
-
let i = 1;
|
|
47
|
-
let buildProgress = setInterval(() => {
|
|
48
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.magenta(`${i}s`));
|
|
49
|
-
i++;
|
|
50
|
-
}, 1000)
|
|
51
|
-
|
|
52
|
-
const frontendDir = path.join(process.cwd(), frontend.directory);
|
|
53
|
-
exec(
|
|
54
|
-
frontend.buildCommond,
|
|
55
|
-
{ stdio: 'inherit', cwd: frontendDir, maxBuffer: 1024 * 1024 * 1024},
|
|
56
|
-
(error, stdout, stderr) => {
|
|
57
|
-
if (error) {
|
|
58
|
-
console.log(chalk.red('build error:') + error);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
console.log(stdout);
|
|
62
|
-
console.log(stderr);
|
|
63
|
-
clearInterval(buildProgress);
|
|
64
|
-
console.log(chalk.blue('[ee-bin] [build] ') + chalk.green('End'));
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
_getElectronPath() {
|
|
70
|
-
let electronExecPath = ''
|
|
71
|
-
const electronModulePath = path.dirname(require.resolve('electron'))
|
|
72
|
-
const pathFile = path.join(electronModulePath, 'path.txt')
|
|
73
|
-
const executablePath = fs.readFileSync(pathFile, 'utf-8')
|
|
74
|
-
if (executablePath) {
|
|
75
|
-
electronExecPath = path.join(electronModulePath, 'dist', executablePath)
|
|
76
|
-
} else {
|
|
77
|
-
throw new Error('Electron uninstall')
|
|
78
|
-
}
|
|
79
|
-
return electronExecPath
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
}
|