ee-core 1.2.11-beta.1 → 1.3.0-beta.2
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 +1 -1
- package/package.json +1 -1
- package/tools/encrypt.js +55 -31
package/config/config.default.js
CHANGED
package/package.json
CHANGED
package/tools/encrypt.js
CHANGED
|
@@ -6,30 +6,28 @@ 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
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
|
24
|
+
// cli
|
|
25
|
+
if (Object.keys(this.config).length == 0) {
|
|
26
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
27
|
+
let tmpArgv = process.argv[i];
|
|
28
|
+
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
29
|
+
this.type = tmpArgv.substring(7);
|
|
30
|
+
}
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
|
|
@@ -43,17 +41,6 @@ class Encrypt {
|
|
|
43
41
|
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
44
42
|
}
|
|
45
43
|
|
|
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
44
|
/**
|
|
58
45
|
* 备份 electron 目录代码
|
|
59
46
|
*/
|
|
@@ -85,6 +72,23 @@ class Encrypt {
|
|
|
85
72
|
console.log('[ee-core] [encrypt] backup end');
|
|
86
73
|
return true;
|
|
87
74
|
}
|
|
75
|
+
|
|
76
|
+
prepare () {
|
|
77
|
+
if (this.type == 'bytecode') {
|
|
78
|
+
let filename = this.config.mangle || this.config.mangle.file || null;
|
|
79
|
+
if (filename) {
|
|
80
|
+
this.tmpFile = path.join(this.encryptCodeDir, 'electron', 'tmp.json');
|
|
81
|
+
this.mapFile = path.join(this.encryptCodeDir, 'electron', filename);
|
|
82
|
+
fs.writeFileSync(this.mapFile, '');
|
|
83
|
+
const content = {
|
|
84
|
+
nameMap: {}
|
|
85
|
+
};
|
|
86
|
+
utility.writeJSONSync(this.tmpFile, content);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
88
92
|
|
|
89
93
|
/**
|
|
90
94
|
* 加密代码
|
|
@@ -148,8 +152,8 @@ class Encrypt {
|
|
|
148
152
|
},
|
|
149
153
|
}
|
|
150
154
|
let options = defaultOpt;
|
|
151
|
-
if (is.object(this.config)) {
|
|
152
|
-
options = Object.assign(defaultOpt, this.config);
|
|
155
|
+
if (is.object(this.config.uglifyOpt)) {
|
|
156
|
+
options = Object.assign(defaultOpt, this.config.uglifyOpt);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
let code = fs.readFileSync(file, "utf8");
|
|
@@ -233,12 +237,32 @@ class Encrypt {
|
|
|
233
237
|
fs.chmodSync(path, mode);
|
|
234
238
|
}
|
|
235
239
|
};
|
|
240
|
+
|
|
241
|
+
loadConfig (prop) {
|
|
242
|
+
const filepath = path.join(this.basePath, 'electron', 'config', 'config.default.js');
|
|
243
|
+
const obj = require(filepath);
|
|
244
|
+
if (!obj) return obj;
|
|
245
|
+
|
|
246
|
+
let ret = obj;
|
|
247
|
+
if (is.function(obj) && !is.class(obj)) {
|
|
248
|
+
ret = obj();
|
|
249
|
+
}
|
|
250
|
+
return ret[prop] || {};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
md5 (file) {
|
|
254
|
+
const buffer = fs.readFileSync(file);
|
|
255
|
+
const hash = crypto.createHash('md5');
|
|
256
|
+
hash.update(buffer, 'utf8');
|
|
257
|
+
const str = hash.digest('hex');
|
|
258
|
+
return str;
|
|
259
|
+
}
|
|
236
260
|
}
|
|
237
261
|
|
|
238
262
|
const run = () => {
|
|
239
263
|
const e = new Encrypt();
|
|
240
|
-
if (!e.check()) return;
|
|
241
264
|
if (!e.backup()) return;
|
|
265
|
+
//if (!e.prepare()) return;
|
|
242
266
|
e.encrypt();
|
|
243
267
|
}
|
|
244
268
|
|