ee-core 1.2.10-beta.2 → 1.2.10
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 -0
- package/core/lib/loader/context_loader.js +2 -1
- package/core/lib/loader/ee_loader.js +5 -2
- package/core/lib/loader/file_loader.js +8 -9
- package/core/lib/loader/mixin/config.js +0 -3
- package/core/lib/loader/mixin/controller.js +4 -3
- package/core/lib/utils/index.js +17 -0
- package/lib/application.js +0 -5
- package/lib/eeApp.js +4 -7
- package/lib/socket/ipcServer.js +6 -24
- package/package.json +2 -1
- package/tools/encrypt.js +55 -26
package/config/config.default.js
CHANGED
|
@@ -5,6 +5,7 @@ const is = require('is-type-of');
|
|
|
5
5
|
const FileLoader = require('./file_loader');
|
|
6
6
|
const CLASSLOADER = Symbol('classLoader');
|
|
7
7
|
const EXPORTS = FileLoader.EXPORTS;
|
|
8
|
+
const utils = require('../utils');
|
|
8
9
|
|
|
9
10
|
class ClassLoader {
|
|
10
11
|
|
|
@@ -88,7 +89,7 @@ function getInstance(values, ctx) {
|
|
|
88
89
|
const Class = values[EXPORTS] ? values : null;
|
|
89
90
|
let instance;
|
|
90
91
|
if (Class) {
|
|
91
|
-
if (is.class(Class)) {
|
|
92
|
+
if (is.class(Class) || utils.isBytecodeClass(Class)) {
|
|
92
93
|
instance = new Class(ctx);
|
|
93
94
|
} else {
|
|
94
95
|
// it's just an object
|
|
@@ -272,7 +272,7 @@ class EeLoader {
|
|
|
272
272
|
if (inject.length === 0) inject = [ this.app ];
|
|
273
273
|
|
|
274
274
|
let ret = this.requireFile(filepath);
|
|
275
|
-
if (is.function(ret) && !is.class(ret)) {
|
|
275
|
+
if (is.function(ret) && !is.class(ret) && !utils.isBytecodeClass(ret)) {
|
|
276
276
|
ret = ret(...inject);
|
|
277
277
|
}
|
|
278
278
|
return ret;
|
|
@@ -358,7 +358,6 @@ class EeLoader {
|
|
|
358
358
|
const timingKey = `Load "${String(property)}" to Application`;
|
|
359
359
|
this.timing.start(timingKey);
|
|
360
360
|
new FileLoader(opt).load();
|
|
361
|
-
//console.log('app property:', this.app[property]);
|
|
362
361
|
this.timing.end(timingKey);
|
|
363
362
|
}
|
|
364
363
|
|
|
@@ -412,6 +411,10 @@ class EeLoader {
|
|
|
412
411
|
try {
|
|
413
412
|
fullPath = require.resolve(filepath);
|
|
414
413
|
} catch (e) {
|
|
414
|
+
let jscFile = filepath + '.jsc';
|
|
415
|
+
if (fs.existsSync(jscFile)) {
|
|
416
|
+
return jscFile;
|
|
417
|
+
}
|
|
415
418
|
return undefined;
|
|
416
419
|
}
|
|
417
420
|
|
|
@@ -65,7 +65,6 @@ class FileLoader {
|
|
|
65
65
|
*/
|
|
66
66
|
load() {
|
|
67
67
|
const items = this.parse();
|
|
68
|
-
//console.log('FileLoader load items:', items);
|
|
69
68
|
const target = this.options.target;
|
|
70
69
|
for (const item of items) {
|
|
71
70
|
// item { properties: [ 'a', 'b', 'c'], exports }
|
|
@@ -123,11 +122,10 @@ class FileLoader {
|
|
|
123
122
|
*/
|
|
124
123
|
parse() {
|
|
125
124
|
let files = this.options.match;
|
|
126
|
-
|
|
127
125
|
if (!files) {
|
|
128
126
|
files = (process.env.EE_TYPESCRIPT === 'true' && utils.extensions['.ts'])
|
|
129
127
|
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
130
|
-
: [ '**/*.js' ];
|
|
128
|
+
: [ '**/*.js', '**/*.jsc'];
|
|
131
129
|
} else {
|
|
132
130
|
files = Array.isArray(files) ? files : [ files ];
|
|
133
131
|
}
|
|
@@ -150,7 +148,6 @@ class FileLoader {
|
|
|
150
148
|
|
|
151
149
|
for (const directory of directories) {
|
|
152
150
|
const filepaths = globby.sync(files, { cwd: directory });
|
|
153
|
-
|
|
154
151
|
for (const filepath of filepaths) {
|
|
155
152
|
const fullpath = path.join(directory, filepath);
|
|
156
153
|
if (!fs.statSync(fullpath).isFile()) continue;
|
|
@@ -160,17 +157,16 @@ class FileLoader {
|
|
|
160
157
|
// app/service/foo/bar.js => service.foo.bar
|
|
161
158
|
const pathName = directory.split(/[/\\]/).slice(-1) + '.' + properties.join('.');
|
|
162
159
|
// get exports from the file
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
let exports = getExports(fullpath, this.options, pathName);
|
|
165
161
|
// ignore exports when it's null or false returned by filter function
|
|
166
162
|
if (exports == null || (filter && filter(exports) === false)) continue;
|
|
167
163
|
|
|
168
164
|
// set properties of class
|
|
169
|
-
if (is.class(exports)) {
|
|
165
|
+
if (is.class(exports) || utils.isBytecodeClass(exports)) {
|
|
170
166
|
exports.prototype.pathName = pathName;
|
|
171
167
|
exports.prototype.fullPath = fullpath;
|
|
172
168
|
}
|
|
173
|
-
|
|
169
|
+
|
|
174
170
|
items.push({ fullpath, properties, exports });
|
|
175
171
|
debug('parse %s, properties %j, export %O', fullpath, properties, exports);
|
|
176
172
|
}
|
|
@@ -202,6 +198,7 @@ function getProperties(filepath, { caseStyle }) {
|
|
|
202
198
|
// If exports is null/undefined, it will be ignored
|
|
203
199
|
function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
204
200
|
let exports = utils.loadFile(fullpath);
|
|
201
|
+
|
|
205
202
|
// process exports as you like
|
|
206
203
|
if (initializer) {
|
|
207
204
|
exports = initializer(exports, { path: fullpath, pathName });
|
|
@@ -212,7 +209,9 @@ function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
|
212
209
|
// module.exports = class Service {};
|
|
213
210
|
// or
|
|
214
211
|
// module.exports = function*() {}
|
|
215
|
-
|
|
212
|
+
//new exports;
|
|
213
|
+
|
|
214
|
+
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) || utils.isBytecodeClass(exports)) {
|
|
216
215
|
return exports;
|
|
217
216
|
}
|
|
218
217
|
|
|
@@ -75,11 +75,8 @@ module.exports = {
|
|
|
75
75
|
_loadConfig(dirpath, filename, extraInject, type) {
|
|
76
76
|
const isPlugin = type === 'plugin';
|
|
77
77
|
const isApp = type === 'app';
|
|
78
|
-
|
|
79
78
|
let filepath = this.resolveModule(path.join(dirpath, 'config', filename));
|
|
80
79
|
|
|
81
|
-
//console.log("_loadConfig filepath:", filepath);
|
|
82
|
-
|
|
83
80
|
// let config.js compatible
|
|
84
81
|
if (filename === 'config.default' && !filepath) {
|
|
85
82
|
filepath = this.resolveModule(path.join(dirpath, 'config/config'));
|
|
@@ -6,7 +6,6 @@ const utility = require('utility');
|
|
|
6
6
|
const utils = require('../../utils');
|
|
7
7
|
const FULLPATH = require('../file_loader').FULLPATH;
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
module.exports = {
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -26,10 +25,11 @@ module.exports = {
|
|
|
26
25
|
// return class HomeController extends app.Controller {};
|
|
27
26
|
// }
|
|
28
27
|
// ```
|
|
29
|
-
|
|
28
|
+
|
|
29
|
+
if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !utils.isBytecodeClass(obj)) {
|
|
30
30
|
obj = obj(this.app);
|
|
31
31
|
}
|
|
32
|
-
if (is.class(obj)) {
|
|
32
|
+
if (is.class(obj) || utils.isBytecodeClass(obj)) {
|
|
33
33
|
obj.prototype.pathName = opt.pathName;
|
|
34
34
|
obj.prototype.fullPath = opt.path;
|
|
35
35
|
return wrapClass(obj);
|
|
@@ -76,6 +76,7 @@ function wrapClass(Controller) {
|
|
|
76
76
|
}
|
|
77
77
|
proto = Object.getPrototypeOf(proto);
|
|
78
78
|
}
|
|
79
|
+
|
|
79
80
|
return ret;
|
|
80
81
|
|
|
81
82
|
function methodToMiddleware(Controller, key) {
|
package/core/lib/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
require('bytenode');
|
|
3
4
|
const convert = require('koa-convert');
|
|
4
5
|
const is = require('is-type-of');
|
|
5
6
|
const path = require('path');
|
|
@@ -23,6 +24,7 @@ module.exports = {
|
|
|
23
24
|
if (extname && !Module._extensions[extname]) {
|
|
24
25
|
return fs.readFileSync(filepath);
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
// require js module
|
|
27
29
|
const obj = require(filepath);
|
|
28
30
|
if (!obj) return obj;
|
|
@@ -87,6 +89,21 @@ module.exports = {
|
|
|
87
89
|
const reg = /[/\\]/g;
|
|
88
90
|
return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
|
|
89
91
|
},
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 字节码类
|
|
95
|
+
*/
|
|
96
|
+
isBytecodeClass (exports) {
|
|
97
|
+
let isClass = false;
|
|
98
|
+
|
|
99
|
+
// 标识
|
|
100
|
+
if (exports.toString().indexOf('[class') != -1) {
|
|
101
|
+
isClass = true;
|
|
102
|
+
}
|
|
103
|
+
// TODO 更严谨的判断,应该加上文件名和路径
|
|
104
|
+
|
|
105
|
+
return isClass;
|
|
106
|
+
},
|
|
90
107
|
};
|
|
91
108
|
|
|
92
109
|
|
package/lib/application.js
CHANGED
package/lib/eeApp.js
CHANGED
|
@@ -70,12 +70,12 @@ class EeApp extends BaseApp {
|
|
|
70
70
|
|
|
71
71
|
app.whenReady().then(() => {
|
|
72
72
|
self.createWindow();
|
|
73
|
-
app.on('activate',
|
|
73
|
+
app.on('activate', () => {
|
|
74
74
|
self.restoreMainWindow();
|
|
75
75
|
})
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
-
app.on('window-all-closed',
|
|
78
|
+
app.on('window-all-closed', () => {
|
|
79
79
|
if (process.platform !== 'darwin') {
|
|
80
80
|
self.coreLogger.info('[Appliaction] [initialize] window-all-closed quit');
|
|
81
81
|
self.appQuit();
|
|
@@ -243,8 +243,9 @@ class EeApp extends BaseApp {
|
|
|
243
243
|
* 主页面
|
|
244
244
|
*/
|
|
245
245
|
loadMainUrl (type, url) {
|
|
246
|
+
const mainServer = this.config.mainServer;
|
|
246
247
|
this.logger.info('main page is env: %s, type: %s, App running at: %s', this.config.env, type, url);
|
|
247
|
-
this.electron.mainWindow.loadURL(url);
|
|
248
|
+
this.electron.mainWindow.loadURL(url, mainServer.options);
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
/**
|
|
@@ -252,7 +253,6 @@ class EeApp extends BaseApp {
|
|
|
252
253
|
*/
|
|
253
254
|
async appQuit () {
|
|
254
255
|
await this.beforeClose();
|
|
255
|
-
|
|
256
256
|
app.quit();
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -299,7 +299,6 @@ class EeApp extends BaseApp {
|
|
|
299
299
|
*/
|
|
300
300
|
async electronAppReady () {
|
|
301
301
|
// do some things
|
|
302
|
-
|
|
303
302
|
}
|
|
304
303
|
|
|
305
304
|
/**
|
|
@@ -307,7 +306,6 @@ class EeApp extends BaseApp {
|
|
|
307
306
|
*/
|
|
308
307
|
async windowReady () {
|
|
309
308
|
// do some things
|
|
310
|
-
|
|
311
309
|
}
|
|
312
310
|
|
|
313
311
|
/**
|
|
@@ -315,7 +313,6 @@ class EeApp extends BaseApp {
|
|
|
315
313
|
*/
|
|
316
314
|
async beforeClose () {
|
|
317
315
|
// do some things
|
|
318
|
-
|
|
319
316
|
}
|
|
320
317
|
}
|
|
321
318
|
|
package/lib/socket/ipcServer.js
CHANGED
|
@@ -9,7 +9,6 @@ const fs = require('fs');
|
|
|
9
9
|
const globby = require('globby');
|
|
10
10
|
const utils = require('../../core/lib/utils');
|
|
11
11
|
const wrap = require('../../utils/wrap');
|
|
12
|
-
const utility = require('utility');
|
|
13
12
|
|
|
14
13
|
class IpcServer {
|
|
15
14
|
constructor (app) {
|
|
@@ -27,23 +26,23 @@ class IpcServer {
|
|
|
27
26
|
// 遍历方法
|
|
28
27
|
const files = (process.env.EE_TYPESCRIPT === 'true' && utils.extensions['.ts'])
|
|
29
28
|
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
30
|
-
: [ '**/*.js' ];
|
|
29
|
+
: [ '**/*.js','**/*.jsc' ];
|
|
31
30
|
const directory = path.join(this.app.config.baseDir, 'controller');
|
|
32
31
|
const filepaths = globby.sync(files, { cwd: directory });
|
|
32
|
+
|
|
33
33
|
for (const filepath of filepaths) {
|
|
34
34
|
const fullpath = path.join(directory, filepath);
|
|
35
35
|
if (!fs.statSync(fullpath).isFile()) continue;
|
|
36
36
|
|
|
37
37
|
const properties = wrap.getProperties(filepath, {caseStyle: 'lower'});
|
|
38
38
|
const pathName = directory.split(/[/\\]/).slice(-1) + '.' + properties.join('.');
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
let fileObj = utils.loadFile(fullpath);
|
|
41
41
|
const fns = {};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (is.class(fileObj)) {
|
|
42
|
+
// 为了统一,仅支持class文件
|
|
43
|
+
if (is.class(fileObj) || utils.isBytecodeClass(fileObj)) {
|
|
46
44
|
let proto = fileObj.prototype;
|
|
45
|
+
// 不遍历父类的方法
|
|
47
46
|
//while (proto !== Object.prototype) {
|
|
48
47
|
const keys = Object.getOwnPropertyNames(proto);
|
|
49
48
|
for (const key of keys) {
|
|
@@ -58,23 +57,6 @@ class IpcServer {
|
|
|
58
57
|
//proto = Object.getPrototypeOf(proto);
|
|
59
58
|
//}
|
|
60
59
|
}
|
|
61
|
-
if (is.object(fileObj)) {
|
|
62
|
-
const keys = Object.keys(fileObj);
|
|
63
|
-
for (const key of keys) {
|
|
64
|
-
if (is.function(fileObj[key])) {
|
|
65
|
-
const names = utility.getParamNames(fileObj[key]);
|
|
66
|
-
if (names[0] === 'next') {
|
|
67
|
-
throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
|
|
68
|
-
}
|
|
69
|
-
fns[key] = 1;
|
|
70
|
-
}
|
|
71
|
-
// else if (is.object(fileObj[key])) {
|
|
72
|
-
// ret[key] = wrapObject(obj[key], path, `${prefix || ''}${key}.`);
|
|
73
|
-
// }
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// if (is.generatorFunction(obj) || is.asyncFunction(obj)) {
|
|
77
|
-
// }
|
|
78
60
|
|
|
79
61
|
debug('register class %s fns %j', pathName, fns);
|
|
80
62
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "1.2.10
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"agentkeepalive": "^4.2.0",
|
|
16
16
|
"better-sqlite3": "^7.6.0",
|
|
17
|
+
"bytenode": "^1.3.6",
|
|
17
18
|
"co": "^4.6.0",
|
|
18
19
|
"debug": "^4.3.3",
|
|
19
20
|
"depd": "^2.0.0",
|
package/tools/encrypt.js
CHANGED
|
@@ -3,32 +3,36 @@
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const fsPro = require('fs-extra');
|
|
6
|
+
const is = require('is-type-of');
|
|
6
7
|
const UglifyJS = require('uglify-js');
|
|
7
8
|
const bytenode = require('bytenode');
|
|
8
9
|
|
|
9
10
|
class Encrypt {
|
|
10
11
|
constructor() {
|
|
12
|
+
this.basePath = process.cwd();
|
|
13
|
+
const directory = [
|
|
14
|
+
'electron',
|
|
15
|
+
];
|
|
16
|
+
this.dirs = [];
|
|
17
|
+
this.type = '';
|
|
18
|
+
this.configPath = '';
|
|
19
|
+
this.config = null;
|
|
20
|
+
this.filesExt = ['.js', '.json', '.node'];
|
|
21
|
+
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
11
22
|
|
|
12
23
|
// argv
|
|
13
|
-
this.type = '';
|
|
14
24
|
for (let i = 0; i < process.argv.length; i++) {
|
|
15
25
|
let tmpArgv = process.argv[i];
|
|
16
26
|
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
17
27
|
this.type = tmpArgv.substring(7);
|
|
18
28
|
}
|
|
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
|
+
}
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
const directory = [
|
|
22
|
-
'electron',
|
|
23
|
-
];
|
|
24
|
-
this.dirs = [];
|
|
25
|
-
|
|
26
|
-
this.basePath = process.cwd();
|
|
27
|
-
// if (this.type == 'uglify') {
|
|
28
|
-
// this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
29
|
-
// }
|
|
30
|
-
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
31
|
-
|
|
32
36
|
// 检查存在的目录
|
|
33
37
|
for (let i = 0; i < directory.length; i++) {
|
|
34
38
|
let codeDirPath = path.join(this.basePath, directory[i]);
|
|
@@ -36,7 +40,18 @@ class Encrypt {
|
|
|
36
40
|
this.dirs.push(directory[i]);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
console.log('dirs:', this.dirs);
|
|
43
|
+
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
44
|
+
}
|
|
45
|
+
|
|
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;
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
/**
|
|
@@ -49,7 +64,7 @@ class Encrypt {
|
|
|
49
64
|
// check code dir
|
|
50
65
|
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
51
66
|
if (!fs.existsSync(codeDirPath)) {
|
|
52
|
-
console.log('[ee-core] [encrypt]
|
|
67
|
+
console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
53
68
|
return
|
|
54
69
|
}
|
|
55
70
|
|
|
@@ -67,7 +82,8 @@ class Encrypt {
|
|
|
67
82
|
|
|
68
83
|
fsPro.copySync(codeDirPath, targetDir);
|
|
69
84
|
}
|
|
70
|
-
console.log('[ee-core] [encrypt] backup
|
|
85
|
+
console.log('[ee-core] [encrypt] backup end');
|
|
86
|
+
return true;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
/**
|
|
@@ -77,7 +93,7 @@ class Encrypt {
|
|
|
77
93
|
console.log('[ee-core] [encrypt] start ciphering');
|
|
78
94
|
for (let i = 0; i < this.dirs.length; i++) {
|
|
79
95
|
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
80
|
-
this.
|
|
96
|
+
this.loop(codeDirPath);
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
console.log('[ee-core] [encrypt] end ciphering');
|
|
@@ -86,16 +102,17 @@ class Encrypt {
|
|
|
86
102
|
/**
|
|
87
103
|
* 递归
|
|
88
104
|
*/
|
|
89
|
-
|
|
105
|
+
loop (dirPath) {
|
|
90
106
|
let files = [];
|
|
91
107
|
if (fs.existsSync(dirPath)) {
|
|
92
108
|
files = fs.readdirSync(dirPath);
|
|
93
109
|
files.forEach((file, index) => {
|
|
94
110
|
let curPath = dirPath + '/' + file;
|
|
95
111
|
if (fs.statSync(curPath).isDirectory()) {
|
|
96
|
-
this.
|
|
112
|
+
this.loop(curPath);
|
|
97
113
|
} else {
|
|
98
|
-
|
|
114
|
+
const extname = path.extname(curPath);
|
|
115
|
+
if (this.filesExt.indexOf(extname) !== -1) {
|
|
99
116
|
this.generate(curPath);
|
|
100
117
|
}
|
|
101
118
|
}
|
|
@@ -110,7 +127,7 @@ class Encrypt {
|
|
|
110
127
|
if (this.type == 'bytecode') {
|
|
111
128
|
this.generateBytecodeFile(curPath);
|
|
112
129
|
} else {
|
|
113
|
-
this.
|
|
130
|
+
this.generateConfuseFile(curPath);
|
|
114
131
|
}
|
|
115
132
|
}
|
|
116
133
|
|
|
@@ -118,13 +135,24 @@ class Encrypt {
|
|
|
118
135
|
* 生成压缩/混淆文件
|
|
119
136
|
*/
|
|
120
137
|
generateConfuseFile (file) {
|
|
121
|
-
let
|
|
122
|
-
const options = {
|
|
138
|
+
let defaultOpt = {
|
|
123
139
|
mangle: {
|
|
124
140
|
toplevel: false,
|
|
125
141
|
},
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
compress: {
|
|
143
|
+
drop_console: true,
|
|
144
|
+
passes: 2
|
|
145
|
+
},
|
|
146
|
+
output: {
|
|
147
|
+
beautify: false
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
let options = defaultOpt;
|
|
151
|
+
if (is.object(this.config)) {
|
|
152
|
+
options = Object.assign(defaultOpt, this.config);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let code = fs.readFileSync(file, "utf8");
|
|
128
156
|
let result = UglifyJS.minify(code, options);
|
|
129
157
|
fs.writeFileSync(file, result.code, "utf8");
|
|
130
158
|
}
|
|
@@ -141,9 +169,9 @@ class Encrypt {
|
|
|
141
169
|
bytenode.compileFile({
|
|
142
170
|
filename: curPath,
|
|
143
171
|
output: jscFile,
|
|
172
|
+
electron: true
|
|
144
173
|
});
|
|
145
174
|
fs.rmSync(curPath, {force: true});
|
|
146
|
-
console.log('[ee-core] [encrypt] generate ', jscFile);
|
|
147
175
|
}
|
|
148
176
|
|
|
149
177
|
/**
|
|
@@ -209,7 +237,8 @@ class Encrypt {
|
|
|
209
237
|
|
|
210
238
|
const run = () => {
|
|
211
239
|
const e = new Encrypt();
|
|
212
|
-
e.
|
|
240
|
+
if (!e.check()) return;
|
|
241
|
+
if (!e.backup()) return;
|
|
213
242
|
e.encrypt();
|
|
214
243
|
}
|
|
215
244
|
|