ee-bin 1.2.0-beta.1 → 1.2.0-beta.3
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 +16 -2
- package/lib/utils.js +31 -2
- package/package.json +1 -1
- package/tools/encrypt.js +25 -32
- package/tools/frontend.js +47 -65
- package/tools/replaceDist.js +8 -19
package/index.js
CHANGED
|
@@ -8,7 +8,9 @@ const program = require('commander');
|
|
|
8
8
|
program
|
|
9
9
|
.command('rd')
|
|
10
10
|
.description('Move frontend resources to public/dist')
|
|
11
|
-
.option('--dist-dir <folder>', 'title to use before name', './frontend/dist')
|
|
11
|
+
.option('--dist-dir <folder>', 'title to use before name', './frontend/dist') // 兼容旧的api
|
|
12
|
+
.option('--dist <folder>', 'title to use before name', './frontend/dist')
|
|
13
|
+
.option('--target <folder>', 'title to use before name', './public/dist')
|
|
12
14
|
.action(function() {
|
|
13
15
|
const replaceDist = require('./tools/replaceDist');
|
|
14
16
|
replaceDist.run(this.opts());
|
|
@@ -20,7 +22,7 @@ program
|
|
|
20
22
|
program
|
|
21
23
|
.command('encrypt')
|
|
22
24
|
.description('Code encryption')
|
|
23
|
-
.option('--config <folder>', 'config file'
|
|
25
|
+
.option('--config <folder>', 'config file')
|
|
24
26
|
.option('--out <folder>', 'output directory', './public')
|
|
25
27
|
.action(function() {
|
|
26
28
|
const encrypt = require('./tools/encrypt');
|
|
@@ -62,4 +64,16 @@ program
|
|
|
62
64
|
frontend.serve(this.opts());
|
|
63
65
|
});
|
|
64
66
|
|
|
67
|
+
/**
|
|
68
|
+
* build
|
|
69
|
+
*/
|
|
70
|
+
program
|
|
71
|
+
.command('build')
|
|
72
|
+
.description('build frontend dist')
|
|
73
|
+
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
74
|
+
.action(function() {
|
|
75
|
+
const frontend = require('./tools/frontend');
|
|
76
|
+
frontend.build(this.opts());
|
|
77
|
+
});
|
|
78
|
+
|
|
65
79
|
program.parse();
|
package/lib/utils.js
CHANGED
|
@@ -7,8 +7,35 @@ const is = require('is-type-of');
|
|
|
7
7
|
|
|
8
8
|
const _basePath = process.cwd();
|
|
9
9
|
|
|
10
|
+
function checkConfig(prop) {
|
|
11
|
+
const filepath = path.join(_basePath, prop);
|
|
12
|
+
if (fs.existsSync(filepath)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
function loadConfig(prop) {
|
|
11
|
-
const configFile = prop
|
|
20
|
+
const configFile = prop;
|
|
21
|
+
const filepath = path.join(_basePath, configFile);
|
|
22
|
+
if (!fs.existsSync(filepath)) {
|
|
23
|
+
const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
|
|
24
|
+
throw new Error(errorTips)
|
|
25
|
+
}
|
|
26
|
+
const obj = require(filepath);
|
|
27
|
+
if (!obj) return obj;
|
|
28
|
+
|
|
29
|
+
let ret = obj;
|
|
30
|
+
if (is.function(obj) && !is.class(obj)) {
|
|
31
|
+
ret = obj();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return ret || {};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function loadEncryptConfig() {
|
|
38
|
+
const configFile = './electron/config/encrypt.js';
|
|
12
39
|
const filepath = path.join(_basePath, configFile);
|
|
13
40
|
if (!fs.existsSync(filepath)) {
|
|
14
41
|
const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
|
|
@@ -26,5 +53,7 @@ function loadConfig(prop) {
|
|
|
26
53
|
};
|
|
27
54
|
|
|
28
55
|
module.exports = {
|
|
29
|
-
loadConfig
|
|
56
|
+
loadConfig,
|
|
57
|
+
checkConfig,
|
|
58
|
+
loadEncryptConfig
|
|
30
59
|
}
|
package/package.json
CHANGED
package/tools/encrypt.js
CHANGED
|
@@ -9,16 +9,27 @@ const crypto = require('crypto');
|
|
|
9
9
|
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
10
10
|
const globby = require('globby');
|
|
11
11
|
const chalk = require('chalk');
|
|
12
|
+
const Utils = require('../lib/utils');
|
|
12
13
|
|
|
13
14
|
class Encrypt {
|
|
14
15
|
constructor(options = {}) {
|
|
15
16
|
// cli args
|
|
16
17
|
const outputFolder = options.out || './public';
|
|
17
|
-
const configFile = options.config || './electron/config/
|
|
18
|
+
const configFile = options.config || './electron/config/bin.js';
|
|
18
19
|
|
|
19
20
|
this.basePath = process.cwd();
|
|
20
21
|
this.encryptCodeDir = path.join(this.basePath, outputFolder);
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
// 先从 bin config获取,没有的话从 config/encrypt.js
|
|
24
|
+
const hasConfig = Utils.checkConfig(configFile);
|
|
25
|
+
if (hasConfig) {
|
|
26
|
+
const cfg = Utils.loadConfig(configFile);
|
|
27
|
+
this.config = cfg.encrypt;
|
|
28
|
+
}
|
|
29
|
+
if (!this.config) {
|
|
30
|
+
this.config = Utils.loadEncryptConfig();
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
this.filesExt = this.config.fileExt || ['.js'];
|
|
23
34
|
this.type = this.config.type || 'confusion';
|
|
24
35
|
this.bOpt = this.config.bytecodeOptions || {};
|
|
@@ -38,8 +49,7 @@ class Encrypt {
|
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
this.codefiles = this._initCodeFiles();
|
|
41
|
-
|
|
42
|
-
console.log('[ee-core] [encrypt] cleanFiles:', this.cleanFiles);
|
|
52
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'cleanFiles:' + this.cleanFiles);
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
/**
|
|
@@ -59,7 +69,7 @@ class Encrypt {
|
|
|
59
69
|
// clean
|
|
60
70
|
this.cleanCode();
|
|
61
71
|
|
|
62
|
-
console.log('[ee-
|
|
72
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup start');
|
|
63
73
|
if (this.patterns) {
|
|
64
74
|
this.codefiles.forEach((filepath) => {
|
|
65
75
|
let source = path.join(this.basePath, filepath);
|
|
@@ -74,13 +84,13 @@ class Encrypt {
|
|
|
74
84
|
// check code dir
|
|
75
85
|
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
76
86
|
if (!fs.existsSync(codeDirPath)) {
|
|
77
|
-
console.log('[ee-
|
|
87
|
+
console.log('[ee-bin] [encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
78
88
|
return
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
// copy
|
|
82
92
|
let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
83
|
-
console.log('[ee-
|
|
93
|
+
console.log('[ee-bin] [encrypt] backup target Dir:', targetDir);
|
|
84
94
|
if (!fs.existsSync(targetDir)) {
|
|
85
95
|
this.mkdir(targetDir);
|
|
86
96
|
this.chmodPath(targetDir, '777');
|
|
@@ -90,7 +100,7 @@ class Encrypt {
|
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
console.log('[ee-
|
|
103
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup end');
|
|
94
104
|
return true;
|
|
95
105
|
}
|
|
96
106
|
|
|
@@ -101,7 +111,7 @@ class Encrypt {
|
|
|
101
111
|
this.cleanFiles.forEach((file) => {
|
|
102
112
|
let tmpFile = path.join(this.basePath, file);
|
|
103
113
|
this.rmBackup(tmpFile);
|
|
104
|
-
console.log('[ee-
|
|
114
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files:' + chalk.magenta(`${tmpFile}`));
|
|
105
115
|
})
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -109,7 +119,7 @@ class Encrypt {
|
|
|
109
119
|
* 加密代码
|
|
110
120
|
*/
|
|
111
121
|
encrypt() {
|
|
112
|
-
console.log('[ee-
|
|
122
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'start ciphering');
|
|
113
123
|
if (this.patterns) {
|
|
114
124
|
for (const file of this.codefiles) {
|
|
115
125
|
const fullpath = path.join(this.encryptCodeDir, file);
|
|
@@ -125,15 +135,15 @@ class Encrypt {
|
|
|
125
135
|
}
|
|
126
136
|
} else {
|
|
127
137
|
// 旧逻辑,将废弃
|
|
128
|
-
console.log('[ee-
|
|
138
|
+
console.log('[ee-bin] [encrypt] !!!!!! please use the new encryption method !!!!!!');
|
|
129
139
|
for (let i = 0; i < this.dirs.length; i++) {
|
|
130
140
|
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
131
141
|
this.loop(codeDirPath);
|
|
132
142
|
}
|
|
133
|
-
console.log('[ee-
|
|
143
|
+
console.log('[ee-bin] [encrypt] !!!!!! please use the new encryption method !!!!!!');
|
|
134
144
|
}
|
|
135
145
|
|
|
136
|
-
console.log('[ee-
|
|
146
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
|
|
137
147
|
};
|
|
138
148
|
|
|
139
149
|
/**
|
|
@@ -163,7 +173,7 @@ class Encrypt {
|
|
|
163
173
|
generate(curPath, type) {
|
|
164
174
|
let encryptType = type ? type : this.type;
|
|
165
175
|
|
|
166
|
-
let tips = '[ee-
|
|
176
|
+
let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
|
|
167
177
|
console.log(tips);
|
|
168
178
|
|
|
169
179
|
if (encryptType == 'bytecode') {
|
|
@@ -272,23 +282,6 @@ class Encrypt {
|
|
|
272
282
|
}
|
|
273
283
|
};
|
|
274
284
|
|
|
275
|
-
loadConfig(prop) {
|
|
276
|
-
const filepath = path.join(this.basePath, prop);
|
|
277
|
-
if (!fs.existsSync(filepath)) {
|
|
278
|
-
const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
|
|
279
|
-
throw new Error(errorTips)
|
|
280
|
-
}
|
|
281
|
-
const obj = require(filepath);
|
|
282
|
-
if (!obj) return obj;
|
|
283
|
-
|
|
284
|
-
let ret = obj;
|
|
285
|
-
if (is.function(obj) && !is.class(obj)) {
|
|
286
|
-
ret = obj();
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return ret || {};
|
|
290
|
-
};
|
|
291
|
-
|
|
292
285
|
md5(file) {
|
|
293
286
|
const buffer = fs.readFileSync(file);
|
|
294
287
|
const hash = crypto.createHash('md5');
|
|
@@ -312,7 +305,7 @@ const clean = (options = {}) => {
|
|
|
312
305
|
const tmpFile = path.join(process.cwd(), file);
|
|
313
306
|
if (fs.existsSync(tmpFile)) {
|
|
314
307
|
fsPro.removeSync(tmpFile);
|
|
315
|
-
console.log('[ee-
|
|
308
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
|
|
316
309
|
}
|
|
317
310
|
})
|
|
318
311
|
}
|
package/tools/frontend.js
CHANGED
|
@@ -2,70 +2,75 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
|
-
const { spawn,
|
|
5
|
+
const { spawn, exec } = require('child_process');
|
|
6
6
|
const Utils = require('../lib/utils');
|
|
7
7
|
const is = require('is-type-of');
|
|
8
|
+
const chalk = require('chalk');
|
|
8
9
|
|
|
9
10
|
module.exports = {
|
|
10
11
|
|
|
11
|
-
electronServer: undefined,
|
|
12
|
-
|
|
13
|
-
frontendServer: undefined,
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* 启动前端、主进程服务
|
|
17
14
|
*/
|
|
18
15
|
serve(options = {}) {
|
|
19
16
|
const { config } = options;
|
|
20
17
|
const cfg = Utils.loadConfig(config);
|
|
21
|
-
|
|
22
18
|
const { frontend, main } = cfg;
|
|
23
|
-
console.log('frontend:', frontend);
|
|
24
|
-
console.log('main:', main);
|
|
25
19
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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});
|
|
30
24
|
|
|
31
|
-
//
|
|
32
|
-
|
|
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
|
-
|
|
25
|
+
// start electron serve
|
|
26
|
+
console.log(chalk.blue('[ee-bin] [serve] ') + chalk.green('Start the electron serve...'));
|
|
53
27
|
const mainDir = path.join(process.cwd(), main.directory);
|
|
54
28
|
const mainArgs = is.string(main.args) ? [main.args] : main.args;
|
|
55
29
|
const electronPath = this._getElectronPath();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
);
|
|
59
67
|
},
|
|
60
68
|
|
|
61
69
|
_getElectronPath() {
|
|
62
70
|
let electronExecPath = ''
|
|
63
71
|
const electronModulePath = path.dirname(require.resolve('electron'))
|
|
64
72
|
const pathFile = path.join(electronModulePath, 'path.txt')
|
|
65
|
-
|
|
66
|
-
if (fs.existsSync(pathFile)) {
|
|
67
|
-
executablePath = fs.readFileSync(pathFile, 'utf-8')
|
|
68
|
-
}
|
|
73
|
+
const executablePath = fs.readFileSync(pathFile, 'utf-8')
|
|
69
74
|
if (executablePath) {
|
|
70
75
|
electronExecPath = path.join(electronModulePath, 'dist', executablePath)
|
|
71
76
|
} else {
|
|
@@ -73,28 +78,5 @@ module.exports = {
|
|
|
73
78
|
}
|
|
74
79
|
return electronExecPath
|
|
75
80
|
},
|
|
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
|
-
}
|
|
81
|
+
|
|
100
82
|
}
|
package/tools/replaceDist.js
CHANGED
|
@@ -17,42 +17,31 @@ const chalk = require('chalk');
|
|
|
17
17
|
run(options = {}) {
|
|
18
18
|
console.log('[ee-bin] [rd] Start moving resources');
|
|
19
19
|
const homeDir = process.cwd();
|
|
20
|
+
const { distDir, dist, target } = options;
|
|
20
21
|
|
|
21
22
|
// argv
|
|
22
|
-
const
|
|
23
|
-
const sourceDir = path.join(homeDir,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!this._fileExist(sourceIndexFile)) {
|
|
27
|
-
console.info(sourceIndexFile);
|
|
23
|
+
const distFolder = dist ? dist : distDir;
|
|
24
|
+
const sourceDir = path.join(homeDir, distFolder);
|
|
25
|
+
if (!fs.existsSync(sourceDir)) {
|
|
28
26
|
const errorTips = chalk.bgRed('Error') + ' Frontend resource does not exist, please build !';
|
|
29
27
|
console.error(errorTips);
|
|
30
28
|
return
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
// 清空历史资源 并 复制到ee资源目录
|
|
34
|
-
const eeResourceDir = path.join(homeDir,
|
|
32
|
+
const eeResourceDir = path.join(homeDir, target);
|
|
35
33
|
if (!fs.existsSync(eeResourceDir)) {
|
|
36
34
|
fs.mkdirSync(eeResourceDir, {recursive: true, mode: 0o777});
|
|
35
|
+
} else {
|
|
36
|
+
this._rmFolder(eeResourceDir);
|
|
37
|
+
console.log('[ee-bin] [rd] Clear history resources:', eeResourceDir);
|
|
37
38
|
}
|
|
38
|
-
this._rmFolder(eeResourceDir);
|
|
39
|
-
console.log('[ee-bin] [rd] Clear history resources:', eeResourceDir);
|
|
40
39
|
|
|
41
40
|
fsPro.copySync(sourceDir, eeResourceDir);
|
|
42
41
|
console.log('[ee-bin] [rd] Copy a resource to:', eeResourceDir);
|
|
43
42
|
console.log('[ee-bin] [rd] End');
|
|
44
43
|
},
|
|
45
44
|
|
|
46
|
-
_fileExist(filePath) {
|
|
47
|
-
try {
|
|
48
|
-
return fs.statSync(filePath).isFile();
|
|
49
|
-
} catch (err) {
|
|
50
|
-
// const errorTips = chalk.bgRed('Error') + ' [ee-bin] [rd] ';
|
|
51
|
-
// console.error(errorTips, err);
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
|
|
56
45
|
/**
|
|
57
46
|
* 删除文件夹
|
|
58
47
|
*/
|