ee-core 1.2.10 → 1.3.0-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/config.default.js +11 -0
- package/package.json +1 -2
- package/tools/encrypt.js +48 -26
package/config/config.default.js
CHANGED
|
@@ -247,6 +247,17 @@ module.exports = appInfo => {
|
|
|
247
247
|
enable: false
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* 加密配置
|
|
252
|
+
*/
|
|
253
|
+
config.encrypt = {
|
|
254
|
+
type: 'bytecode', // bytecode | confusion
|
|
255
|
+
directory: [
|
|
256
|
+
'electron'
|
|
257
|
+
],
|
|
258
|
+
fileExt: ['.js'],
|
|
259
|
+
};
|
|
260
|
+
|
|
250
261
|
/**
|
|
251
262
|
* TODO storage
|
|
252
263
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.1",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"agentkeepalive": "^4.2.0",
|
|
16
|
-
"better-sqlite3": "^7.6.0",
|
|
17
16
|
"bytenode": "^1.3.6",
|
|
18
17
|
"co": "^4.6.0",
|
|
19
18
|
"debug": "^4.3.3",
|
package/tools/encrypt.js
CHANGED
|
@@ -6,19 +6,20 @@ const fsPro = require('fs-extra');
|
|
|
6
6
|
const is = require('is-type-of');
|
|
7
7
|
const UglifyJS = require('uglify-js');
|
|
8
8
|
const bytenode = require('bytenode');
|
|
9
|
+
const utility = require('utility');
|
|
10
|
+
const crypto = require('crypto');
|
|
9
11
|
|
|
10
12
|
class Encrypt {
|
|
11
13
|
constructor() {
|
|
12
14
|
this.basePath = process.cwd();
|
|
13
|
-
const directory = [
|
|
14
|
-
'electron',
|
|
15
|
-
];
|
|
16
15
|
this.dirs = [];
|
|
17
|
-
this.type = '';
|
|
18
|
-
this.configPath = '';
|
|
19
|
-
this.config = null;
|
|
20
|
-
this.filesExt = ['.js', '.json', '.node'];
|
|
21
16
|
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
17
|
+
this.config = this.loadConfig('encrypt');
|
|
18
|
+
this.filesExt = this.config.fileExt || ['.js'];
|
|
19
|
+
this.type = this.config.type || 'bytecode';
|
|
20
|
+
const directory = this.config.directory || ['electron'];
|
|
21
|
+
this.tmpFile = '';
|
|
22
|
+
this.mapFile = '';
|
|
22
23
|
|
|
23
24
|
// argv
|
|
24
25
|
for (let i = 0; i < process.argv.length; i++) {
|
|
@@ -26,11 +27,6 @@ class Encrypt {
|
|
|
26
27
|
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
27
28
|
this.type = tmpArgv.substring(7);
|
|
28
29
|
}
|
|
29
|
-
if (tmpArgv.indexOf('--config=') !== -1) {
|
|
30
|
-
let configPathStr = tmpArgv.substring(9);
|
|
31
|
-
this.configPath = path.join(this.basePath, configPathStr);
|
|
32
|
-
this.config = fs.existsSync(this.configPath) ? require(this.configPath) : null;
|
|
33
|
-
}
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
// 检查存在的目录
|
|
@@ -43,17 +39,6 @@ class Encrypt {
|
|
|
43
39
|
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
/**
|
|
47
|
-
* 检查
|
|
48
|
-
*/
|
|
49
|
-
check () {
|
|
50
|
-
if (this.configPath.length > 0 && !is.object(this.config)) {
|
|
51
|
-
console.log('[ee-core] [encrypt] ERROR: config file is invalid');
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
42
|
/**
|
|
58
43
|
* 备份 electron 目录代码
|
|
59
44
|
*/
|
|
@@ -85,6 +70,23 @@ class Encrypt {
|
|
|
85
70
|
console.log('[ee-core] [encrypt] backup end');
|
|
86
71
|
return true;
|
|
87
72
|
}
|
|
73
|
+
|
|
74
|
+
prepare () {
|
|
75
|
+
if (this.type == 'bytecode') {
|
|
76
|
+
let filename = this.config.mangle || this.config.mangle.file || null;
|
|
77
|
+
if (filename) {
|
|
78
|
+
this.tmpFile = path.join(this.encryptCodeDir, 'electron', 'tmp.json');
|
|
79
|
+
this.mapFile = path.join(this.encryptCodeDir, 'electron', filename);
|
|
80
|
+
fs.writeFileSync(this.mapFile, '');
|
|
81
|
+
const content = {
|
|
82
|
+
nameMap: {}
|
|
83
|
+
};
|
|
84
|
+
utility.writeJSONSync(this.tmpFile, content);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
88
90
|
|
|
89
91
|
/**
|
|
90
92
|
* 加密代码
|
|
@@ -171,7 +173,7 @@ class Encrypt {
|
|
|
171
173
|
output: jscFile,
|
|
172
174
|
electron: true
|
|
173
175
|
});
|
|
174
|
-
|
|
176
|
+
fsPro.removeSync(curPath);
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
/**
|
|
@@ -180,7 +182,7 @@ class Encrypt {
|
|
|
180
182
|
rmBackup (dir) {
|
|
181
183
|
if (fs.existsSync(dir)) {
|
|
182
184
|
console.log('[ee-core] [encrypt] clean old directory:', dir);
|
|
183
|
-
|
|
185
|
+
fsPro.removeSync(dir);
|
|
184
186
|
}
|
|
185
187
|
return;
|
|
186
188
|
}
|
|
@@ -233,12 +235,32 @@ class Encrypt {
|
|
|
233
235
|
fs.chmodSync(path, mode);
|
|
234
236
|
}
|
|
235
237
|
};
|
|
238
|
+
|
|
239
|
+
loadConfig (prop) {
|
|
240
|
+
const filepath = path.join(this.basePath, 'electron', 'config', 'config.default.js');
|
|
241
|
+
const obj = require(filepath);
|
|
242
|
+
if (!obj) return obj;
|
|
243
|
+
|
|
244
|
+
let ret = obj;
|
|
245
|
+
if (is.function(obj) && !is.class(obj)) {
|
|
246
|
+
ret = obj();
|
|
247
|
+
}
|
|
248
|
+
return ret[prop] || {};
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
md5 (file) {
|
|
252
|
+
const buffer = fs.readFileSync(file);
|
|
253
|
+
const hash = crypto.createHash('md5');
|
|
254
|
+
hash.update(buffer, 'utf8');
|
|
255
|
+
const str = hash.digest('hex');
|
|
256
|
+
return str;
|
|
257
|
+
}
|
|
236
258
|
}
|
|
237
259
|
|
|
238
260
|
const run = () => {
|
|
239
261
|
const e = new Encrypt();
|
|
240
|
-
if (!e.check()) return;
|
|
241
262
|
if (!e.backup()) return;
|
|
263
|
+
//if (!e.prepare()) return;
|
|
242
264
|
e.encrypt();
|
|
243
265
|
}
|
|
244
266
|
|