ee-core 1.5.2-beta.1 → 1.5.2-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/LICENSE +21 -21
- package/README.md +2 -2
- package/addon/window/index.js +91 -91
- package/bin/tools.js +18 -18
- package/config/config.default.js +280 -280
- package/core/index.js +12 -12
- package/core/lib/ee.js +218 -218
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +457 -457
- package/core/lib/loader/file_loader.js +325 -325
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +135 -135
- package/core/lib/loader/mixin/controller.js +124 -124
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/index.js +127 -127
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/index.js +49 -49
- package/lib/appLoader.js +53 -53
- package/lib/application.js +84 -84
- package/lib/baseApp.js +131 -131
- package/lib/constant.js +9 -9
- package/lib/eeApp.js +359 -359
- package/lib/httpclient.js +136 -136
- package/lib/logger.js +46 -46
- package/lib/socket/httpServer.js +142 -142
- package/lib/socket/io.js +23 -23
- package/lib/socket/ipcServer.js +108 -108
- package/lib/socket/socketClient.js +50 -50
- package/lib/socket/socketServer.js +76 -76
- package/lib/socket/start.js +22 -22
- package/lib/storage/index.js +33 -33
- package/lib/storage/lowdb/adapters/Base.js +15 -15
- package/lib/storage/lowdb/adapters/FileAsync.js +41 -41
- package/lib/storage/lowdb/adapters/FileSync.js +39 -39
- package/lib/storage/lowdb/adapters/LocalStorage.js +20 -20
- package/lib/storage/lowdb/adapters/Memory.js +8 -8
- package/lib/storage/lowdb/adapters/_stringify.js +4 -4
- package/lib/storage/lowdb/common.js +33 -33
- package/lib/storage/lowdb/fp.js +23 -23
- package/lib/storage/lowdb/{is-promise.js → isPromise.js} +5 -5
- package/lib/storage/lowdb/main.js +46 -46
- package/lib/storage/lowdb/nano.js +5 -5
- package/lib/storage/lowdbStorage.js +98 -98
- package/lib/storage/sqliteStorage.js +127 -127
- package/package.json +48 -48
- package/tools/encrypt.js +274 -274
- package/tools/replaceDist.js +61 -61
- package/utils/common.js +90 -90
- package/utils/index.js +246 -246
- package/utils/wrap.js +37 -37
package/tools/encrypt.js
CHANGED
|
@@ -1,275 +1,275 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const is = require('is-type-of');
|
|
7
|
-
const bytenode = require('bytenode');
|
|
8
|
-
const utility = require('utility');
|
|
9
|
-
const crypto = require('crypto');
|
|
10
|
-
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
11
|
-
|
|
12
|
-
class Encrypt {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.basePath = process.cwd();
|
|
15
|
-
this.dirs = [];
|
|
16
|
-
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
17
|
-
this.config = this.loadConfig('encrypt.js');
|
|
18
|
-
this.filesExt = this.config.fileExt || ['.js'];
|
|
19
|
-
this.type = this.config.type || 'bytecode';
|
|
20
|
-
this.bOpt = this.config.bytecodeOptions || {};
|
|
21
|
-
this.cOpt = this.config.confusionOptions || {};
|
|
22
|
-
|
|
23
|
-
const directory = this.config.directory || ['electron'];
|
|
24
|
-
this.tmpFile = ''; // todo
|
|
25
|
-
this.mapFile = ''; // todo
|
|
26
|
-
|
|
27
|
-
// cli
|
|
28
|
-
if (Object.keys(this.config).length == 0) {
|
|
29
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
30
|
-
let tmpArgv = process.argv[i];
|
|
31
|
-
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
32
|
-
this.type = tmpArgv.substring(7);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 检查存在的目录
|
|
38
|
-
for (let i = 0; i < directory.length; i++) {
|
|
39
|
-
let codeDirPath = path.join(this.basePath, directory[i]);
|
|
40
|
-
if (fs.existsSync(codeDirPath)) {
|
|
41
|
-
this.dirs.push(directory[i]);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 备份 electron 目录代码
|
|
49
|
-
*/
|
|
50
|
-
backup () {
|
|
51
|
-
console.log('[ee-core] [encrypt] backup start');
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
54
|
-
// check code dir
|
|
55
|
-
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
56
|
-
if (!fs.existsSync(codeDirPath)) {
|
|
57
|
-
console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
62
|
-
|
|
63
|
-
// remove old
|
|
64
|
-
this.rmBackup(targetDir);
|
|
65
|
-
|
|
66
|
-
// copy
|
|
67
|
-
console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
|
|
68
|
-
if (!fs.existsSync(targetDir)) {
|
|
69
|
-
this.mkdir(targetDir);
|
|
70
|
-
this.chmodPath(targetDir, '777');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fsPro.copySync(codeDirPath, targetDir);
|
|
74
|
-
}
|
|
75
|
-
console.log('[ee-core] [encrypt] backup end');
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
prepare () {
|
|
80
|
-
if (this.type == 'bytecode') {
|
|
81
|
-
let filename = this.config.mangle || this.config.mangle.file || null;
|
|
82
|
-
if (filename) {
|
|
83
|
-
this.tmpFile = path.join(this.encryptCodeDir, 'electron', 'tmp.json');
|
|
84
|
-
this.mapFile = path.join(this.encryptCodeDir, 'electron', filename);
|
|
85
|
-
fs.writeFileSync(this.mapFile, '');
|
|
86
|
-
const content = {
|
|
87
|
-
nameMap: {}
|
|
88
|
-
};
|
|
89
|
-
utility.writeJSONSync(this.tmpFile, content);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 加密代码
|
|
98
|
-
*/
|
|
99
|
-
encrypt () {
|
|
100
|
-
console.log('[ee-core] [encrypt] start ciphering');
|
|
101
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
102
|
-
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
103
|
-
this.loop(codeDirPath);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
console.log('[ee-core] [encrypt] end ciphering');
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 递归
|
|
111
|
-
*/
|
|
112
|
-
loop (dirPath) {
|
|
113
|
-
let files = [];
|
|
114
|
-
if (fs.existsSync(dirPath)) {
|
|
115
|
-
files = fs.readdirSync(dirPath);
|
|
116
|
-
files.forEach((file, index) => {
|
|
117
|
-
let curPath = dirPath + '/' + file;
|
|
118
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
119
|
-
this.loop(curPath);
|
|
120
|
-
} else {
|
|
121
|
-
const extname = path.extname(curPath);
|
|
122
|
-
if (this.filesExt.indexOf(extname) !== -1) {
|
|
123
|
-
this.generate(curPath);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 生成文件
|
|
132
|
-
*/
|
|
133
|
-
generate (curPath) {
|
|
134
|
-
if (this.type == 'bytecode') {
|
|
135
|
-
this.generateBytecodeFile(curPath);
|
|
136
|
-
} else if (this.type == 'confusion') {
|
|
137
|
-
this.generateJSConfuseFile(curPath);
|
|
138
|
-
} else {
|
|
139
|
-
this.generateJSConfuseFile(curPath);
|
|
140
|
-
this.generateBytecodeFile(curPath);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
146
|
-
*/
|
|
147
|
-
generateJSConfuseFile (file) {
|
|
148
|
-
let opt = Object.assign({
|
|
149
|
-
compact: true,
|
|
150
|
-
stringArray: true,
|
|
151
|
-
stringArrayThreshold: 1,
|
|
152
|
-
}, this.cOpt);
|
|
153
|
-
|
|
154
|
-
let code = fs.readFileSync(file, "utf8");
|
|
155
|
-
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
156
|
-
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 生成字节码文件
|
|
161
|
-
*/
|
|
162
|
-
generateBytecodeFile (curPath) {
|
|
163
|
-
if (path.extname(curPath) !== '.js') {
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
167
|
-
let jscFile = curPath + 'c';
|
|
168
|
-
let opt = Object.assign({
|
|
169
|
-
filename: curPath,
|
|
170
|
-
output: jscFile,
|
|
171
|
-
electron: true
|
|
172
|
-
}, this.bOpt);
|
|
173
|
-
|
|
174
|
-
bytenode.compileFile(opt);
|
|
175
|
-
|
|
176
|
-
//fs.writeFileSync(curPath, 'require("bytenode");module.exports = require("./'+path.basename(jscFile)+'");', 'utf8');
|
|
177
|
-
|
|
178
|
-
fsPro.removeSync(curPath);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 移除备份
|
|
183
|
-
*/
|
|
184
|
-
rmBackup (dir) {
|
|
185
|
-
if (fs.existsSync(dir)) {
|
|
186
|
-
console.log('[ee-core] [encrypt] clean old directory:', dir);
|
|
187
|
-
fsPro.removeSync(dir);
|
|
188
|
-
}
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 检查文件是否存在
|
|
194
|
-
*/
|
|
195
|
-
fileExist (filePath) {
|
|
196
|
-
try {
|
|
197
|
-
return fs.statSync(filePath).isFile();
|
|
198
|
-
} catch (err) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
mkdir (dirpath, dirname) {
|
|
204
|
-
// 判断是否是第一次调用
|
|
205
|
-
if (typeof dirname === 'undefined') {
|
|
206
|
-
if (fs.existsSync(dirpath)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
this.mkdir(dirpath, path.dirname(dirpath));
|
|
210
|
-
} else {
|
|
211
|
-
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
212
|
-
if (dirname !== path.dirname(dirpath)) {
|
|
213
|
-
this.mkdir(dirpath);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (fs.existsSync(dirname)) {
|
|
217
|
-
fs.mkdirSync(dirpath);
|
|
218
|
-
} else {
|
|
219
|
-
this.mkdir(dirname, path.dirname(dirname));
|
|
220
|
-
fs.mkdirSync(dirpath);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
chmodPath (path, mode) {
|
|
226
|
-
let files = [];
|
|
227
|
-
if (fs.existsSync(path)) {
|
|
228
|
-
files = fs.readdirSync(path);
|
|
229
|
-
files.forEach((file, index) => {
|
|
230
|
-
const curPath = path + '/' + file;
|
|
231
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
232
|
-
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
233
|
-
} else {
|
|
234
|
-
fs.chmodSync(curPath, mode);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
fs.chmodSync(path, mode);
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
loadConfig (prop) {
|
|
242
|
-
const filepath = path.join(this.basePath, 'electron', 'config', prop);
|
|
243
|
-
if (!fs.existsSync(filepath)) {
|
|
244
|
-
return {};
|
|
245
|
-
}
|
|
246
|
-
const obj = require(filepath);
|
|
247
|
-
if (!obj) return obj;
|
|
248
|
-
|
|
249
|
-
let ret = obj;
|
|
250
|
-
if (is.function(obj) && !is.class(obj)) {
|
|
251
|
-
ret = obj();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return ret || {};
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
md5 (file) {
|
|
258
|
-
const buffer = fs.readFileSync(file);
|
|
259
|
-
const hash = crypto.createHash('md5');
|
|
260
|
-
hash.update(buffer, 'utf8');
|
|
261
|
-
const str = hash.digest('hex');
|
|
262
|
-
return str;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const run = () => {
|
|
267
|
-
const e = new Encrypt();
|
|
268
|
-
if (!e.backup()) return;
|
|
269
|
-
//if (!e.prepare()) return;
|
|
270
|
-
e.encrypt();
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
module.exports = {
|
|
274
|
-
run
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const is = require('is-type-of');
|
|
7
|
+
const bytenode = require('bytenode');
|
|
8
|
+
const utility = require('utility');
|
|
9
|
+
const crypto = require('crypto');
|
|
10
|
+
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
11
|
+
|
|
12
|
+
class Encrypt {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.basePath = process.cwd();
|
|
15
|
+
this.dirs = [];
|
|
16
|
+
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
17
|
+
this.config = this.loadConfig('encrypt.js');
|
|
18
|
+
this.filesExt = this.config.fileExt || ['.js'];
|
|
19
|
+
this.type = this.config.type || 'bytecode';
|
|
20
|
+
this.bOpt = this.config.bytecodeOptions || {};
|
|
21
|
+
this.cOpt = this.config.confusionOptions || {};
|
|
22
|
+
|
|
23
|
+
const directory = this.config.directory || ['electron'];
|
|
24
|
+
this.tmpFile = ''; // todo
|
|
25
|
+
this.mapFile = ''; // todo
|
|
26
|
+
|
|
27
|
+
// cli
|
|
28
|
+
if (Object.keys(this.config).length == 0) {
|
|
29
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
30
|
+
let tmpArgv = process.argv[i];
|
|
31
|
+
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
32
|
+
this.type = tmpArgv.substring(7);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 检查存在的目录
|
|
38
|
+
for (let i = 0; i < directory.length; i++) {
|
|
39
|
+
let codeDirPath = path.join(this.basePath, directory[i]);
|
|
40
|
+
if (fs.existsSync(codeDirPath)) {
|
|
41
|
+
this.dirs.push(directory[i]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 备份 electron 目录代码
|
|
49
|
+
*/
|
|
50
|
+
backup () {
|
|
51
|
+
console.log('[ee-core] [encrypt] backup start');
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < this.dirs.length; i++) {
|
|
54
|
+
// check code dir
|
|
55
|
+
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
56
|
+
if (!fs.existsSync(codeDirPath)) {
|
|
57
|
+
console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
62
|
+
|
|
63
|
+
// remove old
|
|
64
|
+
this.rmBackup(targetDir);
|
|
65
|
+
|
|
66
|
+
// copy
|
|
67
|
+
console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
|
|
68
|
+
if (!fs.existsSync(targetDir)) {
|
|
69
|
+
this.mkdir(targetDir);
|
|
70
|
+
this.chmodPath(targetDir, '777');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fsPro.copySync(codeDirPath, targetDir);
|
|
74
|
+
}
|
|
75
|
+
console.log('[ee-core] [encrypt] backup end');
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
prepare () {
|
|
80
|
+
if (this.type == 'bytecode') {
|
|
81
|
+
let filename = this.config.mangle || this.config.mangle.file || null;
|
|
82
|
+
if (filename) {
|
|
83
|
+
this.tmpFile = path.join(this.encryptCodeDir, 'electron', 'tmp.json');
|
|
84
|
+
this.mapFile = path.join(this.encryptCodeDir, 'electron', filename);
|
|
85
|
+
fs.writeFileSync(this.mapFile, '');
|
|
86
|
+
const content = {
|
|
87
|
+
nameMap: {}
|
|
88
|
+
};
|
|
89
|
+
utility.writeJSONSync(this.tmpFile, content);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 加密代码
|
|
98
|
+
*/
|
|
99
|
+
encrypt () {
|
|
100
|
+
console.log('[ee-core] [encrypt] start ciphering');
|
|
101
|
+
for (let i = 0; i < this.dirs.length; i++) {
|
|
102
|
+
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
103
|
+
this.loop(codeDirPath);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log('[ee-core] [encrypt] end ciphering');
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 递归
|
|
111
|
+
*/
|
|
112
|
+
loop (dirPath) {
|
|
113
|
+
let files = [];
|
|
114
|
+
if (fs.existsSync(dirPath)) {
|
|
115
|
+
files = fs.readdirSync(dirPath);
|
|
116
|
+
files.forEach((file, index) => {
|
|
117
|
+
let curPath = dirPath + '/' + file;
|
|
118
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
119
|
+
this.loop(curPath);
|
|
120
|
+
} else {
|
|
121
|
+
const extname = path.extname(curPath);
|
|
122
|
+
if (this.filesExt.indexOf(extname) !== -1) {
|
|
123
|
+
this.generate(curPath);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 生成文件
|
|
132
|
+
*/
|
|
133
|
+
generate (curPath) {
|
|
134
|
+
if (this.type == 'bytecode') {
|
|
135
|
+
this.generateBytecodeFile(curPath);
|
|
136
|
+
} else if (this.type == 'confusion') {
|
|
137
|
+
this.generateJSConfuseFile(curPath);
|
|
138
|
+
} else {
|
|
139
|
+
this.generateJSConfuseFile(curPath);
|
|
140
|
+
this.generateBytecodeFile(curPath);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
146
|
+
*/
|
|
147
|
+
generateJSConfuseFile (file) {
|
|
148
|
+
let opt = Object.assign({
|
|
149
|
+
compact: true,
|
|
150
|
+
stringArray: true,
|
|
151
|
+
stringArrayThreshold: 1,
|
|
152
|
+
}, this.cOpt);
|
|
153
|
+
|
|
154
|
+
let code = fs.readFileSync(file, "utf8");
|
|
155
|
+
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
156
|
+
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 生成字节码文件
|
|
161
|
+
*/
|
|
162
|
+
generateBytecodeFile (curPath) {
|
|
163
|
+
if (path.extname(curPath) !== '.js') {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
167
|
+
let jscFile = curPath + 'c';
|
|
168
|
+
let opt = Object.assign({
|
|
169
|
+
filename: curPath,
|
|
170
|
+
output: jscFile,
|
|
171
|
+
electron: true
|
|
172
|
+
}, this.bOpt);
|
|
173
|
+
|
|
174
|
+
bytenode.compileFile(opt);
|
|
175
|
+
|
|
176
|
+
//fs.writeFileSync(curPath, 'require("bytenode");module.exports = require("./'+path.basename(jscFile)+'");', 'utf8');
|
|
177
|
+
|
|
178
|
+
fsPro.removeSync(curPath);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 移除备份
|
|
183
|
+
*/
|
|
184
|
+
rmBackup (dir) {
|
|
185
|
+
if (fs.existsSync(dir)) {
|
|
186
|
+
console.log('[ee-core] [encrypt] clean old directory:', dir);
|
|
187
|
+
fsPro.removeSync(dir);
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 检查文件是否存在
|
|
194
|
+
*/
|
|
195
|
+
fileExist (filePath) {
|
|
196
|
+
try {
|
|
197
|
+
return fs.statSync(filePath).isFile();
|
|
198
|
+
} catch (err) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
mkdir (dirpath, dirname) {
|
|
204
|
+
// 判断是否是第一次调用
|
|
205
|
+
if (typeof dirname === 'undefined') {
|
|
206
|
+
if (fs.existsSync(dirpath)) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.mkdir(dirpath, path.dirname(dirpath));
|
|
210
|
+
} else {
|
|
211
|
+
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
212
|
+
if (dirname !== path.dirname(dirpath)) {
|
|
213
|
+
this.mkdir(dirpath);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (fs.existsSync(dirname)) {
|
|
217
|
+
fs.mkdirSync(dirpath);
|
|
218
|
+
} else {
|
|
219
|
+
this.mkdir(dirname, path.dirname(dirname));
|
|
220
|
+
fs.mkdirSync(dirpath);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
chmodPath (path, mode) {
|
|
226
|
+
let files = [];
|
|
227
|
+
if (fs.existsSync(path)) {
|
|
228
|
+
files = fs.readdirSync(path);
|
|
229
|
+
files.forEach((file, index) => {
|
|
230
|
+
const curPath = path + '/' + file;
|
|
231
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
232
|
+
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
233
|
+
} else {
|
|
234
|
+
fs.chmodSync(curPath, mode);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
fs.chmodSync(path, mode);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
loadConfig (prop) {
|
|
242
|
+
const filepath = path.join(this.basePath, 'electron', 'config', prop);
|
|
243
|
+
if (!fs.existsSync(filepath)) {
|
|
244
|
+
return {};
|
|
245
|
+
}
|
|
246
|
+
const obj = require(filepath);
|
|
247
|
+
if (!obj) return obj;
|
|
248
|
+
|
|
249
|
+
let ret = obj;
|
|
250
|
+
if (is.function(obj) && !is.class(obj)) {
|
|
251
|
+
ret = obj();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return ret || {};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
md5 (file) {
|
|
258
|
+
const buffer = fs.readFileSync(file);
|
|
259
|
+
const hash = crypto.createHash('md5');
|
|
260
|
+
hash.update(buffer, 'utf8');
|
|
261
|
+
const str = hash.digest('hex');
|
|
262
|
+
return str;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const run = () => {
|
|
267
|
+
const e = new Encrypt();
|
|
268
|
+
if (!e.backup()) return;
|
|
269
|
+
//if (!e.prepare()) return;
|
|
270
|
+
e.encrypt();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
module.exports = {
|
|
274
|
+
run
|
|
275
275
|
};
|
package/tools/replaceDist.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 资源替换
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 执行
|
|
15
|
-
*/
|
|
16
|
-
run () {
|
|
17
|
-
console.log('[ee-core] [replace_dist] 开始移动资源');
|
|
18
|
-
const homeDir = process.cwd();
|
|
19
|
-
|
|
20
|
-
// argv
|
|
21
|
-
let distDir = '';
|
|
22
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
23
|
-
let tmpArgv = process.argv[i]
|
|
24
|
-
if (tmpArgv.indexOf('--dist_dir=') !== -1) {
|
|
25
|
-
distDir = tmpArgv.substring(11)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const fileExist = (filePath) => {
|
|
30
|
-
try {
|
|
31
|
-
return fs.statSync(filePath).isFile();
|
|
32
|
-
} catch (err) {
|
|
33
|
-
console.error('[ee-core] [replace_dist] ERROR ', err);
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const sourceDir = path.join(homeDir, distDir);
|
|
39
|
-
const sourceIndexFile = path.join(sourceDir, 'index.html');
|
|
40
|
-
|
|
41
|
-
if (!fileExist(sourceIndexFile)) {
|
|
42
|
-
console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 复制到ee资源目录
|
|
47
|
-
const eeResourceDir = path.join(homeDir, 'public', 'dist');
|
|
48
|
-
|
|
49
|
-
// 清空历史资源
|
|
50
|
-
fs.rmdirSync(eeResourceDir, {recursive: true});
|
|
51
|
-
console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
|
|
52
|
-
|
|
53
|
-
fsPro.copySync(sourceDir, eeResourceDir);
|
|
54
|
-
console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
|
|
55
|
-
|
|
56
|
-
console.log('[ee-core] [replace_dist] 结束');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 资源替换
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 执行
|
|
15
|
+
*/
|
|
16
|
+
run () {
|
|
17
|
+
console.log('[ee-core] [replace_dist] 开始移动资源');
|
|
18
|
+
const homeDir = process.cwd();
|
|
19
|
+
|
|
20
|
+
// argv
|
|
21
|
+
let distDir = '';
|
|
22
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
23
|
+
let tmpArgv = process.argv[i]
|
|
24
|
+
if (tmpArgv.indexOf('--dist_dir=') !== -1) {
|
|
25
|
+
distDir = tmpArgv.substring(11)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fileExist = (filePath) => {
|
|
30
|
+
try {
|
|
31
|
+
return fs.statSync(filePath).isFile();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('[ee-core] [replace_dist] ERROR ', err);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const sourceDir = path.join(homeDir, distDir);
|
|
39
|
+
const sourceIndexFile = path.join(sourceDir, 'index.html');
|
|
40
|
+
|
|
41
|
+
if (!fileExist(sourceIndexFile)) {
|
|
42
|
+
console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 复制到ee资源目录
|
|
47
|
+
const eeResourceDir = path.join(homeDir, 'public', 'dist');
|
|
48
|
+
|
|
49
|
+
// 清空历史资源
|
|
50
|
+
fs.rmdirSync(eeResourceDir, {recursive: true});
|
|
51
|
+
console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
|
|
52
|
+
|
|
53
|
+
fsPro.copySync(sourceDir, eeResourceDir);
|
|
54
|
+
console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
|
|
55
|
+
|
|
56
|
+
console.log('[ee-core] [replace_dist] 结束');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|