ee-bin 4.0.0-beta.1 → 4.0.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 +85 -15
- package/index.js +1 -0
- package/package.json +4 -2
- package/tools/encrypt.js +23 -41
- package/tools/serve.js +74 -16
package/config/bin_default.js
CHANGED
|
@@ -16,12 +16,17 @@ module.exports = {
|
|
|
16
16
|
hostname: 'localhost',
|
|
17
17
|
port: 8080,
|
|
18
18
|
indexPath: 'index.html',
|
|
19
|
+
force: false,
|
|
20
|
+
sync: false,
|
|
19
21
|
},
|
|
20
22
|
electron: {
|
|
21
23
|
directory: './',
|
|
22
24
|
cmd: 'electron',
|
|
23
25
|
args: ['.', '--env=local'],
|
|
24
26
|
loadingPage: '/public/html/loading.html',
|
|
27
|
+
watch: false,
|
|
28
|
+
sync: false,
|
|
29
|
+
delay: 1000,
|
|
25
30
|
},
|
|
26
31
|
},
|
|
27
32
|
|
|
@@ -36,8 +41,9 @@ module.exports = {
|
|
|
36
41
|
args: ['run', 'build'],
|
|
37
42
|
},
|
|
38
43
|
electron: {
|
|
44
|
+
type: 'javascript',
|
|
39
45
|
bundler: 'esbuild',
|
|
40
|
-
|
|
46
|
+
bundleType: 'bundle', // copy | bundle
|
|
41
47
|
javascript: {
|
|
42
48
|
entryPoints: ['./electron/**/*.js'],
|
|
43
49
|
platform: 'node',
|
|
@@ -60,7 +66,47 @@ module.exports = {
|
|
|
60
66
|
sourcemap:false,
|
|
61
67
|
sourcesContent: false
|
|
62
68
|
}
|
|
63
|
-
}
|
|
69
|
+
},
|
|
70
|
+
win32: {
|
|
71
|
+
cmd: 'electron-builder',
|
|
72
|
+
directory: './',
|
|
73
|
+
args: ['--config=./cmd/builder.json', '-w=nsis', '--ia32'],
|
|
74
|
+
},
|
|
75
|
+
win64: {
|
|
76
|
+
cmd: 'electron-builder',
|
|
77
|
+
directory: './',
|
|
78
|
+
args: ['--config=./cmd/builder.json', '-w=nsis', '--x64'],
|
|
79
|
+
},
|
|
80
|
+
win_e: {
|
|
81
|
+
cmd: 'electron-builder',
|
|
82
|
+
directory: './',
|
|
83
|
+
args: ['--config=./cmd/builder.json', '-w=portable', '--x64'],
|
|
84
|
+
},
|
|
85
|
+
win_7z: {
|
|
86
|
+
cmd: 'electron-builder',
|
|
87
|
+
directory: './',
|
|
88
|
+
args: ['--config=./cmd/builder.json', '-w=7z', '--x64'],
|
|
89
|
+
},
|
|
90
|
+
mac: {
|
|
91
|
+
cmd: 'electron-builder',
|
|
92
|
+
directory: './',
|
|
93
|
+
args: ['--config=./cmd/builder-mac.json', '-m'],
|
|
94
|
+
},
|
|
95
|
+
mac_arm64: {
|
|
96
|
+
cmd: 'electron-builder',
|
|
97
|
+
directory: './',
|
|
98
|
+
args: ['--config=./cmd/builder-mac-arm64.json', '-m', '--arm64'],
|
|
99
|
+
},
|
|
100
|
+
linux: {
|
|
101
|
+
cmd: 'electron-builder',
|
|
102
|
+
directory: './',
|
|
103
|
+
args: ['--config=./cmd/builder-linux.json', '-l=deb', '--x64'],
|
|
104
|
+
},
|
|
105
|
+
linux_arm64: {
|
|
106
|
+
cmd: 'electron-builder',
|
|
107
|
+
directory: './',
|
|
108
|
+
args: ['--config=./cmd/builder-linux.json', '-l=deb', '--arm64'],
|
|
109
|
+
},
|
|
64
110
|
},
|
|
65
111
|
|
|
66
112
|
/**
|
|
@@ -88,19 +134,43 @@ module.exports = {
|
|
|
88
134
|
* 加密
|
|
89
135
|
*/
|
|
90
136
|
encrypt: {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
137
|
+
frontend: {
|
|
138
|
+
type: 'none',
|
|
139
|
+
files: [
|
|
140
|
+
'./public/dist/**/*.(js|json)',
|
|
141
|
+
],
|
|
142
|
+
fileExt: ['.js'],
|
|
143
|
+
cleanFiles: ['./public/dist'],
|
|
144
|
+
specificFiles: [],
|
|
145
|
+
encryptDir: './',
|
|
146
|
+
confusionOptions: {
|
|
147
|
+
compact: true,
|
|
148
|
+
stringArray: true,
|
|
149
|
+
stringArrayEncoding: ['none'],
|
|
150
|
+
deadCodeInjection: false,
|
|
151
|
+
stringArrayCallsTransform: true,
|
|
152
|
+
numbersToExpressions: true,
|
|
153
|
+
target: 'browser',
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
electron: {
|
|
157
|
+
type: 'none',
|
|
158
|
+
files: [
|
|
159
|
+
'./public/electron/**/*.(js|json)',
|
|
160
|
+
],
|
|
161
|
+
fileExt: ['.js'],
|
|
162
|
+
cleanFiles: ['./public/electron'],
|
|
163
|
+
specificFiles: ['./public/electron/preload/bridge.js'],
|
|
164
|
+
encryptDir: './',
|
|
165
|
+
confusionOptions: {
|
|
166
|
+
compact: true,
|
|
167
|
+
stringArray: true,
|
|
168
|
+
stringArrayEncoding: ['rc4'],
|
|
169
|
+
deadCodeInjection: false,
|
|
170
|
+
stringArrayCallsTransform: true,
|
|
171
|
+
numbersToExpressions: true,
|
|
172
|
+
target: 'node',
|
|
173
|
+
}
|
|
104
174
|
}
|
|
105
175
|
},
|
|
106
176
|
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-bin",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "ee bin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"adm-zip": "^0.4.11",
|
|
16
16
|
"bytenode": "^1.3.6",
|
|
17
17
|
"chalk": "^4.1.2",
|
|
18
|
+
"chokidar": "^4.0.3",
|
|
18
19
|
"commander": "^11.0.0",
|
|
19
20
|
"config-file-ts": "^0.2.8-rc1",
|
|
20
21
|
"cross-spawn": "^7.0.3",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"is-type-of": "^1.2.1",
|
|
26
27
|
"javascript-obfuscator": "^4.0.2",
|
|
27
28
|
"json5": "^2.2.3",
|
|
28
|
-
"mkdirp": "^2.1.3"
|
|
29
|
+
"mkdirp": "^2.1.3",
|
|
30
|
+
"tree-kill": "^1.2.2"
|
|
29
31
|
}
|
|
30
32
|
}
|
package/tools/encrypt.js
CHANGED
|
@@ -9,17 +9,19 @@ const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
|
9
9
|
const globby = require('globby');
|
|
10
10
|
const chalk = require('chalk');
|
|
11
11
|
const { loadConfig } = require('../lib/utils');
|
|
12
|
+
const { extend } = require('../lib/extend');
|
|
12
13
|
|
|
13
14
|
const EncryptTypes = ['bytecode', 'confusion', 'strict'];
|
|
14
15
|
|
|
15
16
|
class Encrypt {
|
|
16
17
|
constructor(options = {}) {
|
|
17
18
|
// cli args
|
|
18
|
-
const { config, out } = options;
|
|
19
|
+
const { config, out, target } = options;
|
|
19
20
|
this.basePath = process.cwd();
|
|
21
|
+
this.target = target;
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
this.config =
|
|
23
|
+
const conf = loadConfig(config).encrypt;
|
|
24
|
+
this.config = conf[target];
|
|
23
25
|
const outputFolder = out || this.config.encryptDir;
|
|
24
26
|
this.encryptDir = path.join(this.basePath, outputFolder);
|
|
25
27
|
this.filesExt = this.config.fileExt;
|
|
@@ -43,45 +45,16 @@ class Encrypt {
|
|
|
43
45
|
return files;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
/**
|
|
47
|
-
* 备份代码
|
|
48
|
-
*/
|
|
49
|
-
backup() {
|
|
50
|
-
// clean
|
|
51
|
-
this.cleanCode();
|
|
52
|
-
|
|
53
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup start');
|
|
54
|
-
this.codefiles.forEach((filepath) => {
|
|
55
|
-
let source = path.join(this.basePath, filepath);
|
|
56
|
-
if (fs.existsSync(source)) {
|
|
57
|
-
let target = path.join(this.encryptCodeDir, filepath);
|
|
58
|
-
fsPro.copySync(source, target);
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup end');
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 清除加密代码
|
|
68
|
-
*/
|
|
69
|
-
cleanCode() {
|
|
70
|
-
this.cleanFiles.forEach((file) => {
|
|
71
|
-
let tmpFile = path.join(this.basePath, file);
|
|
72
|
-
fsPro.removeSync(tmpFile);
|
|
73
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files:' + chalk.magenta(`${tmpFile}`));
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
48
|
/**
|
|
78
49
|
* 加密代码
|
|
79
50
|
*/
|
|
80
51
|
encrypt() {
|
|
81
|
-
|
|
82
|
-
|
|
52
|
+
if (EncryptTypes.indexOf(this.type) == -1) return;
|
|
53
|
+
if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
|
|
54
|
+
|
|
55
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
|
|
83
56
|
for (const file of this.codefiles) {
|
|
84
|
-
const fullpath = path.join(this.
|
|
57
|
+
const fullpath = path.join(this.encryptDir, file);
|
|
85
58
|
if (!fs.statSync(fullpath).isFile()) continue;
|
|
86
59
|
|
|
87
60
|
// 特殊文件处理
|
|
@@ -172,13 +145,22 @@ class Encrypt {
|
|
|
172
145
|
}
|
|
173
146
|
|
|
174
147
|
function encrypt(options = {}) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
148
|
+
const electronOpt = extend(true, {
|
|
149
|
+
target: 'electron',
|
|
150
|
+
}, options);
|
|
151
|
+
const electronEpt = new Encrypt(electronOpt);
|
|
152
|
+
electronEpt.encrypt();
|
|
153
|
+
|
|
154
|
+
const frontendOpt = extend(true, {
|
|
155
|
+
target: 'frontend',
|
|
156
|
+
}, options);
|
|
157
|
+
const frontendEpt = new Encrypt(frontendOpt);
|
|
158
|
+
frontendEpt.encrypt();
|
|
179
159
|
}
|
|
180
160
|
|
|
181
161
|
function cleanEncrypt(options = {}) {
|
|
162
|
+
// [todo] 删除前端和主进程代码
|
|
163
|
+
return;
|
|
182
164
|
let files = options.dir !== undefined ? options.dir : ['./public/electron'];
|
|
183
165
|
files = is.string(files) ? [files] : files;
|
|
184
166
|
|
package/tools/serve.js
CHANGED
|
@@ -2,22 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
const debug = require('debug')('ee-bin:serve');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
5
6
|
const { loadConfig } = require('../lib/utils');
|
|
6
7
|
const is = require('is-type-of');
|
|
7
8
|
const chalk = require('chalk');
|
|
8
9
|
const crossSpawn = require('cross-spawn');
|
|
9
10
|
const { buildSync } = require('esbuild');
|
|
11
|
+
const chokidar = require('chokidar');
|
|
12
|
+
const kill = require('tree-kill');
|
|
10
13
|
|
|
11
14
|
class ServeProcess {
|
|
12
15
|
|
|
13
16
|
constructor() {
|
|
17
|
+
process.env.NODE_ENV = 'prod'; // dev / prod
|
|
14
18
|
this.execProcess = {};
|
|
19
|
+
this.electronDir = './electron';
|
|
20
|
+
this.defaultBundleDir = './public/electron';
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* 启动前端、主进程服务
|
|
19
25
|
*/
|
|
20
26
|
dev(options = {}) {
|
|
27
|
+
// 设置一个环境变量
|
|
28
|
+
process.env.NODE_ENV = 'dev';
|
|
21
29
|
const { config, serve } = options;
|
|
22
30
|
const binCfg = loadConfig(config);
|
|
23
31
|
const binCmd = 'dev';
|
|
@@ -27,18 +35,53 @@ class ServeProcess {
|
|
|
27
35
|
if (!command) {
|
|
28
36
|
command = Object.keys(binCmdConfig).join();
|
|
29
37
|
}
|
|
30
|
-
|
|
31
|
-
// build electron code
|
|
32
|
-
const cmds = this._formatCmds(command);
|
|
33
|
-
if (cmds.indexOf("electron") !== -1) {
|
|
34
|
-
this.bundle(true, binCfg.build.electron);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
38
|
const opt = {
|
|
38
39
|
binCmd,
|
|
39
40
|
binCmdConfig,
|
|
40
41
|
command,
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
// build electron main code
|
|
45
|
+
const cmds = this._formatCmds(command);
|
|
46
|
+
if (cmds.indexOf("electron") !== -1) {
|
|
47
|
+
// watche electron main code
|
|
48
|
+
const electronConfig = binCmdConfig.electron;
|
|
49
|
+
if (electronConfig.watch) {
|
|
50
|
+
const cmd = 'electron';
|
|
51
|
+
const watcher = chokidar.watch([this.electronDir], {
|
|
52
|
+
persistent: true
|
|
53
|
+
});
|
|
54
|
+
watcher.on('change', async (f) => {
|
|
55
|
+
console.log(chalk.blue('[ee-bin] [dev] ') + `File ${f} has been changed`);
|
|
56
|
+
console.log(chalk.blue('[ee-bin] [dev] ') + `Restart ${cmd}`);
|
|
57
|
+
|
|
58
|
+
// rebuild code
|
|
59
|
+
this.bundle(binCfg.build.electron);
|
|
60
|
+
let subPorcess = this.execProcess[cmd];
|
|
61
|
+
kill(subPorcess.pid, 'SIGKILL', (err) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
console.log(chalk.red('[ee-bin] [dev] ') + `Restart failed, error: ${err}`);
|
|
64
|
+
process.exit(-1);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
delete this.execProcess[cmd];
|
|
68
|
+
|
|
69
|
+
// restart electron command
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
let onlyElectronOpt = {
|
|
72
|
+
binCmd,
|
|
73
|
+
binCmdConfig,
|
|
74
|
+
command: cmd,
|
|
75
|
+
}
|
|
76
|
+
this.multiExec(onlyElectronOpt);
|
|
77
|
+
}, electronConfig.delay);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// When starting for the first time, build the code for the electron directory
|
|
82
|
+
this.bundle(binCfg.build.electron);
|
|
83
|
+
}
|
|
84
|
+
|
|
42
85
|
this.multiExec(opt);
|
|
43
86
|
}
|
|
44
87
|
|
|
@@ -69,7 +112,8 @@ class ServeProcess {
|
|
|
69
112
|
* 构建
|
|
70
113
|
*/
|
|
71
114
|
build(options = {}) {
|
|
72
|
-
const { config, cmds } = options;
|
|
115
|
+
const { config, cmds, env } = options;
|
|
116
|
+
process.env.NODE_ENV = env;
|
|
73
117
|
const binCfg = loadConfig(config);
|
|
74
118
|
const binCmd = 'build';
|
|
75
119
|
const binCmdConfig = binCfg[binCmd];
|
|
@@ -81,7 +125,7 @@ class ServeProcess {
|
|
|
81
125
|
}
|
|
82
126
|
|
|
83
127
|
if (cmds.indexOf("electron") !== -1) {
|
|
84
|
-
this.bundle(
|
|
128
|
+
this.bundle(binCmdConfig.electron);
|
|
85
129
|
return;
|
|
86
130
|
}
|
|
87
131
|
|
|
@@ -161,13 +205,22 @@ class ServeProcess {
|
|
|
161
205
|
}
|
|
162
206
|
|
|
163
207
|
// esbuild
|
|
164
|
-
bundle(
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
|
|
208
|
+
bundle(bundleConfig) {
|
|
209
|
+
const { bundleType } = bundleConfig;
|
|
210
|
+
if (bundleType == 'copy') {
|
|
211
|
+
const srcResource = path.join(process.cwd(), this.electronDir);
|
|
212
|
+
const destResource = path.join(process.cwd(), this.defaultBundleDir);
|
|
213
|
+
fsPro.removeSync(destResource);
|
|
214
|
+
fsPro.copySync(srcResource, destResource);
|
|
215
|
+
} else {
|
|
216
|
+
const esbuildOptions = bundleConfig[bundleConfig.type];
|
|
217
|
+
// todo 不压缩
|
|
218
|
+
// if (this.isDev()) {
|
|
219
|
+
// esbuildOptions.minify = false;
|
|
220
|
+
// }
|
|
221
|
+
debug('esbuild options:%O', esbuildOptions);
|
|
222
|
+
buildSync(esbuildOptions);
|
|
168
223
|
}
|
|
169
|
-
debug('esbuild options:%O', esbuildOptions);
|
|
170
|
-
buildSync(esbuildOptions);
|
|
171
224
|
}
|
|
172
225
|
|
|
173
226
|
// format commands
|
|
@@ -181,7 +234,12 @@ class ServeProcess {
|
|
|
181
234
|
}
|
|
182
235
|
|
|
183
236
|
return cmds;
|
|
184
|
-
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// env
|
|
240
|
+
isDev() {
|
|
241
|
+
return process.env.NODE_ENV === 'dev';
|
|
242
|
+
}
|
|
185
243
|
}
|
|
186
244
|
|
|
187
245
|
module.exports = {
|