ee-core 2.3.1 → 2.4.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/bin/tools.js +4 -23
- package/electron/window/index.js +1 -1
- package/jobs/child/forkProcess.js +1 -0
- package/jobs/renderer/index.js +3 -2
- package/jobs/renderer/loadView.js +1 -0
- package/package.json +2 -3
- package/tools/encrypt.js +0 -335
- package/tools/iconGen.js +0 -183
- package/tools/replaceDist.js +0 -99
package/bin/tools.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const encrypt = require('../tools/encrypt');
|
|
5
|
-
//const iconGen = require('../tools/iconGen');
|
|
3
|
+
const chalk = require('chalk');
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// console.log('[ee-core] args:', args);
|
|
10
|
-
const cmd = args[2];
|
|
11
|
-
console.log('[ee-core] [bin/tools] cmd:', cmd);
|
|
5
|
+
let tip = chalk.bgYellow('Warning') + ' please use ' + chalk.blue('ee-bin') + ', See: ';
|
|
6
|
+
tip += chalk.underline('https://www.kaka996.com/pages/85c531/');
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
replaceDist.run();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (cmd == 'encrypt') {
|
|
18
|
-
encrypt.run();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (cmd == 'clean') {
|
|
22
|
-
encrypt.clean();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// if (cmd == 'icon') {
|
|
26
|
-
// iconGen.run();
|
|
27
|
-
// }
|
|
8
|
+
console.log(tip);
|
package/electron/window/index.js
CHANGED
package/jobs/renderer/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//require('bytenode');
|
|
2
1
|
const { BrowserWindow } = require('electron');
|
|
3
2
|
const fs = require('fs');
|
|
4
3
|
const LoadView = require('./loadView');
|
|
4
|
+
const Loader = require('../../loader');
|
|
5
5
|
|
|
6
6
|
class RendererJob {
|
|
7
7
|
|
|
@@ -12,6 +12,7 @@ class RendererJob {
|
|
|
12
12
|
* @param {Object} options - options to create BrowserWindow
|
|
13
13
|
*/
|
|
14
14
|
constructor(name, filepath, opt = {}) {
|
|
15
|
+
// TODO Object.assign 只能单层对象结构,多层的对象会直接覆盖
|
|
15
16
|
let options = Object.assign({
|
|
16
17
|
show: false,
|
|
17
18
|
webPreferences: {
|
|
@@ -25,7 +26,7 @@ class RendererJob {
|
|
|
25
26
|
this.subWin = new BrowserWindow(options);
|
|
26
27
|
|
|
27
28
|
this.jobReady = false;
|
|
28
|
-
this.exec = filepath
|
|
29
|
+
this.exec = Loader.getFullpath(filepath);;
|
|
29
30
|
this.name = name;
|
|
30
31
|
this.listeners = [];
|
|
31
32
|
this.callbacks = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-beta.2",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,14 +14,13 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"agentkeepalive": "^4.2.0",
|
|
16
16
|
"bytenode": "^1.3.6",
|
|
17
|
+
"chalk": "^4.1.2",
|
|
17
18
|
"dayjs": "^1.11.7",
|
|
18
19
|
"debug": "^4.3.3",
|
|
19
20
|
"egg-errors": "^2.3.0",
|
|
20
21
|
"egg-logger": "^2.7.1",
|
|
21
|
-
"fs-extra": "^10.0.0",
|
|
22
22
|
"globby": "^10.0.0",
|
|
23
23
|
"is-type-of": "^1.2.1",
|
|
24
|
-
"javascript-obfuscator": "^4.0.2",
|
|
25
24
|
"koa": "^2.13.4",
|
|
26
25
|
"koa-body": "^5.0.0",
|
|
27
26
|
"koa-convert": "^2.0.0",
|
package/tools/encrypt.js
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
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 crypto = require('crypto');
|
|
9
|
-
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
10
|
-
const globby = require('globby');
|
|
11
|
-
const UtilsJson = require('../utils/json');
|
|
12
|
-
|
|
13
|
-
class Encrypt {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.basePath = process.cwd();
|
|
16
|
-
this.dirs = [];
|
|
17
|
-
this.encryptCodeDir = path.join(this.basePath, 'public');
|
|
18
|
-
this.config = this.loadConfig('encrypt.js');
|
|
19
|
-
this.filesExt = this.config.fileExt || ['.js'];
|
|
20
|
-
this.type = this.config.type || 'confusion';
|
|
21
|
-
this.bOpt = this.config.bytecodeOptions || {};
|
|
22
|
-
this.cOpt = this.config.confusionOptions || {};
|
|
23
|
-
this.cleanFiles = this.config.cleanFiles || ['electron'];
|
|
24
|
-
|
|
25
|
-
const directory = this.config.directory || ['electron'];
|
|
26
|
-
this.patterns = this.config.files || null;
|
|
27
|
-
this.specificFiles = [ 'electron/preload/bridge.js' ];
|
|
28
|
-
this.tmpFile = ''; // todo
|
|
29
|
-
this.mapFile = ''; // todo
|
|
30
|
-
|
|
31
|
-
// cli
|
|
32
|
-
if (Object.keys(this.config).length == 0) {
|
|
33
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
34
|
-
let tmpArgv = process.argv[i];
|
|
35
|
-
if (tmpArgv.indexOf('--type=') !== -1) {
|
|
36
|
-
this.type = tmpArgv.substring(7);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (let i = 0; i < directory.length; i++) {
|
|
42
|
-
let codeDirPath = path.join(this.basePath, directory[i]);
|
|
43
|
-
if (fs.existsSync(codeDirPath)) {
|
|
44
|
-
this.dirs.push(directory[i]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.codefiles = this._initCodeFiles();
|
|
49
|
-
//console.log('[ee-core] [tools/encrypt] codefiles:', this.codefiles);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 初始化需要加密的文件列表
|
|
54
|
-
*/
|
|
55
|
-
_initCodeFiles() {
|
|
56
|
-
if (!this.patterns) return;
|
|
57
|
-
|
|
58
|
-
const files = globby.sync(this.patterns, { cwd: this.basePath });
|
|
59
|
-
return files;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 备份代码
|
|
64
|
-
*/
|
|
65
|
-
backup() {
|
|
66
|
-
// clean
|
|
67
|
-
this.cleanCode();
|
|
68
|
-
|
|
69
|
-
console.log('[ee-core] [tools/encrypt] backup start');
|
|
70
|
-
if (this.patterns) {
|
|
71
|
-
this.codefiles.forEach((filepath) => {
|
|
72
|
-
let source = path.join(this.basePath, filepath);
|
|
73
|
-
if (fs.existsSync(source)) {
|
|
74
|
-
let target = path.join(this.encryptCodeDir, filepath);
|
|
75
|
-
fsPro.copySync(source, target);
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
} else {
|
|
79
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
80
|
-
// check code dir
|
|
81
|
-
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
82
|
-
if (!fs.existsSync(codeDirPath)) {
|
|
83
|
-
console.log('[ee-core] [tools/encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// copy
|
|
88
|
-
let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
89
|
-
console.log('[ee-core] [tools/encrypt] backup target Dir:', targetDir);
|
|
90
|
-
if (!fs.existsSync(targetDir)) {
|
|
91
|
-
this.mkdir(targetDir);
|
|
92
|
-
this.chmodPath(targetDir, '777');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
fsPro.copySync(codeDirPath, targetDir);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
console.log('[ee-core] [tools/encrypt] backup end');
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 清除加密代码
|
|
105
|
-
*/
|
|
106
|
-
cleanCode() {
|
|
107
|
-
this.cleanFiles.forEach((file) => {
|
|
108
|
-
let tmpFile = path.join(this.encryptCodeDir, file);
|
|
109
|
-
this.rmBackup(tmpFile);
|
|
110
|
-
console.log('[ee-core] [tools/encrypt] clean up tmp files:', tmpFile);
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
prepare() {
|
|
115
|
-
if (this.type == 'bytecode') {
|
|
116
|
-
let filename = this.config.mangle || this.config.mangle.file || null;
|
|
117
|
-
if (filename) {
|
|
118
|
-
this.tmpFile = path.join(this.encryptCodeDir, 'electron', 'tmp.json');
|
|
119
|
-
this.mapFile = path.join(this.encryptCodeDir, 'electron', filename);
|
|
120
|
-
fs.writeFileSync(this.mapFile, '');
|
|
121
|
-
const content = {
|
|
122
|
-
nameMap: {}
|
|
123
|
-
};
|
|
124
|
-
UtilsJson.writeSync(this.tmpFile, content);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 加密代码
|
|
133
|
-
*/
|
|
134
|
-
encrypt() {
|
|
135
|
-
console.log('[ee-core] [tools/encrypt] start ciphering');
|
|
136
|
-
if (this.patterns) {
|
|
137
|
-
for (const file of this.codefiles) {
|
|
138
|
-
const fullpath = path.join(this.encryptCodeDir, file);
|
|
139
|
-
if (!fs.statSync(fullpath).isFile()) continue;
|
|
140
|
-
|
|
141
|
-
// 特殊文件处理
|
|
142
|
-
if (this.specificFiles.includes(file)) {
|
|
143
|
-
this.generate(fullpath, 'confusion');
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
this.generate(fullpath);
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
console.log('[ee-core] [tools/encrypt] !!!!!! please use the new encryption method !!!!!!');
|
|
151
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
152
|
-
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
153
|
-
this.loop(codeDirPath);
|
|
154
|
-
}
|
|
155
|
-
console.log('[ee-core] [tools/encrypt] !!!!!! please use the new encryption method !!!!!!');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
console.log('[ee-core] [tools/encrypt] end ciphering');
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 递归
|
|
163
|
-
*/
|
|
164
|
-
loop(dirPath) {
|
|
165
|
-
let files = [];
|
|
166
|
-
if (fs.existsSync(dirPath)) {
|
|
167
|
-
files = fs.readdirSync(dirPath);
|
|
168
|
-
files.forEach((file, index) => {
|
|
169
|
-
let curPath = dirPath + '/' + file;
|
|
170
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
171
|
-
this.loop(curPath);
|
|
172
|
-
} else {
|
|
173
|
-
const extname = path.extname(curPath);
|
|
174
|
-
if (this.filesExt.indexOf(extname) !== -1) {
|
|
175
|
-
this.generate(curPath);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 生成文件
|
|
184
|
-
*/
|
|
185
|
-
generate(curPath, type) {
|
|
186
|
-
let encryptType = type ? type : this.type;
|
|
187
|
-
console.log(`[ee-core] [tools/encrypt] file: ${curPath} (${encryptType})`);
|
|
188
|
-
|
|
189
|
-
if (encryptType == 'bytecode') {
|
|
190
|
-
this.generateBytecodeFile(curPath);
|
|
191
|
-
} else if (encryptType == 'confusion') {
|
|
192
|
-
this.generateJSConfuseFile(curPath);
|
|
193
|
-
} else {
|
|
194
|
-
this.generateJSConfuseFile(curPath);
|
|
195
|
-
this.generateBytecodeFile(curPath);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
201
|
-
*/
|
|
202
|
-
generateJSConfuseFile(file) {
|
|
203
|
-
let opt = Object.assign({
|
|
204
|
-
compact: true,
|
|
205
|
-
stringArray: true,
|
|
206
|
-
stringArrayThreshold: 1,
|
|
207
|
-
}, this.cOpt);
|
|
208
|
-
|
|
209
|
-
let code = fs.readFileSync(file, "utf8");
|
|
210
|
-
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
211
|
-
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* 生成字节码文件
|
|
216
|
-
*/
|
|
217
|
-
generateBytecodeFile(curPath) {
|
|
218
|
-
if (path.extname(curPath) !== '.js') {
|
|
219
|
-
return
|
|
220
|
-
}
|
|
221
|
-
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
222
|
-
let jscFile = curPath + 'c';
|
|
223
|
-
let opt = Object.assign({
|
|
224
|
-
filename: curPath,
|
|
225
|
-
output: jscFile,
|
|
226
|
-
electron: true
|
|
227
|
-
}, this.bOpt);
|
|
228
|
-
|
|
229
|
-
bytenode.compileFile(opt);
|
|
230
|
-
|
|
231
|
-
//fs.writeFileSync(curPath, 'require("bytenode");module.exports = require("./'+path.basename(jscFile)+'");', 'utf8');
|
|
232
|
-
|
|
233
|
-
fsPro.removeSync(curPath);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* 移除备份
|
|
238
|
-
*/
|
|
239
|
-
rmBackup(file) {
|
|
240
|
-
if (fs.existsSync(file)) {
|
|
241
|
-
fsPro.removeSync(file);
|
|
242
|
-
}
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 检查文件是否存在
|
|
248
|
-
*/
|
|
249
|
-
fileExist(filePath) {
|
|
250
|
-
try {
|
|
251
|
-
return fs.statSync(filePath).isFile();
|
|
252
|
-
} catch (err) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
mkdir(dirpath, dirname) {
|
|
258
|
-
// 判断是否是第一次调用
|
|
259
|
-
if (typeof dirname === 'undefined') {
|
|
260
|
-
if (fs.existsSync(dirpath)) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
this.mkdir(dirpath, path.dirname(dirpath));
|
|
264
|
-
} else {
|
|
265
|
-
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
266
|
-
if (dirname !== path.dirname(dirpath)) {
|
|
267
|
-
this.mkdir(dirpath);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (fs.existsSync(dirname)) {
|
|
271
|
-
fs.mkdirSync(dirpath);
|
|
272
|
-
} else {
|
|
273
|
-
this.mkdir(dirname, path.dirname(dirname));
|
|
274
|
-
fs.mkdirSync(dirpath);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
chmodPath(path, mode) {
|
|
280
|
-
let files = [];
|
|
281
|
-
if (fs.existsSync(path)) {
|
|
282
|
-
files = fs.readdirSync(path);
|
|
283
|
-
files.forEach((file, index) => {
|
|
284
|
-
const curPath = path + '/' + file;
|
|
285
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
286
|
-
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
287
|
-
} else {
|
|
288
|
-
fs.chmodSync(curPath, mode);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
fs.chmodSync(path, mode);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
loadConfig(prop) {
|
|
296
|
-
const filepath = path.join(this.basePath, 'electron', 'config', prop);
|
|
297
|
-
if (!fs.existsSync(filepath)) {
|
|
298
|
-
return {};
|
|
299
|
-
}
|
|
300
|
-
const obj = require(filepath);
|
|
301
|
-
if (!obj) return obj;
|
|
302
|
-
|
|
303
|
-
let ret = obj;
|
|
304
|
-
if (is.function(obj) && !is.class(obj)) {
|
|
305
|
-
ret = obj();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return ret || {};
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
md5(file) {
|
|
312
|
-
const buffer = fs.readFileSync(file);
|
|
313
|
-
const hash = crypto.createHash('md5');
|
|
314
|
-
hash.update(buffer, 'utf8');
|
|
315
|
-
const str = hash.digest('hex');
|
|
316
|
-
return str;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const run = () => {
|
|
321
|
-
const e = new Encrypt();
|
|
322
|
-
if (!e.backup()) return;
|
|
323
|
-
//if (!e.prepare()) return;
|
|
324
|
-
e.encrypt();
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const clean = () => {
|
|
328
|
-
const e = new Encrypt();
|
|
329
|
-
e.cleanCode();
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
module.exports = {
|
|
333
|
-
run,
|
|
334
|
-
clean,
|
|
335
|
-
};
|
package/tools/iconGen.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const icongen = require("icon-gen");
|
|
6
|
-
|
|
7
|
-
class IconGen {
|
|
8
|
-
constructor() {
|
|
9
|
-
this._init();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* _init
|
|
14
|
-
*/
|
|
15
|
-
_init() {
|
|
16
|
-
// ---> 处理参数
|
|
17
|
-
const args = process.argv.splice(3);
|
|
18
|
-
let params = {
|
|
19
|
-
input: "/public/images/logo.png",
|
|
20
|
-
output: "/build/icons/",
|
|
21
|
-
size: "16,32,64,256,512",
|
|
22
|
-
clear: false,
|
|
23
|
-
imagesDir: "/public/images/",
|
|
24
|
-
};
|
|
25
|
-
try {
|
|
26
|
-
const len = args.length;
|
|
27
|
-
for (let i = 0; i < len; i++) {
|
|
28
|
-
const arg = args[i];
|
|
29
|
-
if (arg.match(/^-i/) || arg.match(/^-input/)) {
|
|
30
|
-
params["input"] = args[i + 1];
|
|
31
|
-
i++;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (arg.match(/^-o/) || arg.match(/^-output/)) {
|
|
35
|
-
params["output"] = args[i + 1];
|
|
36
|
-
i++;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (arg.match(/^-s/) || arg.match(/^-size/)) {
|
|
40
|
-
params["size"] = args[i + 1];
|
|
41
|
-
i++;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (arg.match(/^-c/) || arg.match(/^-clear/)) {
|
|
45
|
-
params["clear"] = true;
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (arg.match(/^-img/) || arg.match(/^-images/)) {
|
|
49
|
-
params["imagesDir"] = args[i + 1];
|
|
50
|
-
i++;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} catch (e) {
|
|
55
|
-
console.error("[ee-core] [tools/iconGen] args: ", args);
|
|
56
|
-
console.error("[ee-core] [tools/iconGen] ERROR: ", e);
|
|
57
|
-
throw new Error("参数错误!!");
|
|
58
|
-
}
|
|
59
|
-
this.params = params;
|
|
60
|
-
|
|
61
|
-
// ---> 组装参数
|
|
62
|
-
console.log("[ee-core] [tools/iconGen] icon 当前路径: ", process.cwd());
|
|
63
|
-
this.input = path.join(process.cwd(), params.input);
|
|
64
|
-
this.output = path.join(process.cwd(), params.output);
|
|
65
|
-
this.imagesDir = path.join(process.cwd(), params.imagesDir);
|
|
66
|
-
|
|
67
|
-
const sizeList = params.size.split(",").map((item) => parseInt(item));
|
|
68
|
-
this.iconOptions = {
|
|
69
|
-
report: false,
|
|
70
|
-
ico: {
|
|
71
|
-
name: "icon",
|
|
72
|
-
sizes: [256],
|
|
73
|
-
},
|
|
74
|
-
favicon: {
|
|
75
|
-
name: "logo-",
|
|
76
|
-
pngSizes: sizeList,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 生成图标
|
|
83
|
-
*/
|
|
84
|
-
generateIcons() {
|
|
85
|
-
console.log("[ee-core] [tools/iconGen] iconGen 开始处理生成logo图片");
|
|
86
|
-
if (!fs.existsSync(this.input)) {
|
|
87
|
-
console.error("[ee-core] [tools/iconGen] input: ", this.input);
|
|
88
|
-
throw new Error("输入的图片不存在或路径错误");
|
|
89
|
-
}
|
|
90
|
-
if (!fs.existsSync(this.output)) {
|
|
91
|
-
fs.mkdirSync(this.output, { recursive: true });
|
|
92
|
-
} else {
|
|
93
|
-
// 清空目录
|
|
94
|
-
this.params.clear && this.deleteGenFile(this.output);
|
|
95
|
-
}
|
|
96
|
-
if (!fs.existsSync(this.imagesDir)) {
|
|
97
|
-
fs.mkdirSync(this.imagesDir, { recursive: true });
|
|
98
|
-
}
|
|
99
|
-
icongen(this.input, this.output, this.iconOptions)
|
|
100
|
-
.then((results) => {
|
|
101
|
-
console.log("[ee-core] [tools/iconGen] iconGen 已生成下方图片资源");
|
|
102
|
-
console.log(results);
|
|
103
|
-
this._renameForEE(results);
|
|
104
|
-
})
|
|
105
|
-
.catch((err) => {
|
|
106
|
-
console.error(err);
|
|
107
|
-
throw new Error("[ee-core] [tools/iconGen] iconGen 生成失败!");
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 删除生成的文件(.ico .png)
|
|
113
|
-
*/
|
|
114
|
-
deleteGenFile(dirPath) {
|
|
115
|
-
if (fs.existsSync(dirPath)) {
|
|
116
|
-
// 读取文件夹下的文件目录
|
|
117
|
-
const files = fs.readdirSync(dirPath);
|
|
118
|
-
files.forEach((file) => {
|
|
119
|
-
const curPath = path.join(dirPath, file);
|
|
120
|
-
// 判断是不是文件夹,如果是,继续递归
|
|
121
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
|
122
|
-
this.deleteGenFile(curPath);
|
|
123
|
-
} else {
|
|
124
|
-
// 删除文件
|
|
125
|
-
if ([".ico", ".png"].includes(path.extname(curPath))) {
|
|
126
|
-
fs.unlinkSync(curPath);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 为生成的资源重命名 (logo-32.png -> 32x32.png)
|
|
135
|
-
*/
|
|
136
|
-
_renameForEE(filesPath) {
|
|
137
|
-
console.log("[ee-core] [tools/iconGen] iconGen 开始重新命名logo图片资源");
|
|
138
|
-
try {
|
|
139
|
-
const len = filesPath.length;
|
|
140
|
-
for (let i = 0; i < len; i++) {
|
|
141
|
-
const filePath = filesPath[i];
|
|
142
|
-
const extname = path.extname(filePath);
|
|
143
|
-
if ([".png"].includes(extname)) {
|
|
144
|
-
const filename = path.basename(filePath, extname);
|
|
145
|
-
const basename = filename.split("-")[1];
|
|
146
|
-
const dirname = path.dirname(filePath);
|
|
147
|
-
// 处理 tray 图标 --> 复制到 public/images 目录下
|
|
148
|
-
if ("16" === basename) {
|
|
149
|
-
const newName = "tray" + extname;
|
|
150
|
-
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
151
|
-
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
152
|
-
fs.unlinkSync(filePath);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
// 处理 win 窗口图标 --> 复制到 public/images 目录下
|
|
156
|
-
if ("32" === basename) {
|
|
157
|
-
const newName = filename + extname;
|
|
158
|
-
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
159
|
-
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
160
|
-
}
|
|
161
|
-
// 重命名 --> 32x32.png
|
|
162
|
-
const newName = basename + "x" + basename + extname;
|
|
163
|
-
const newPath = path.join(dirname, newName);
|
|
164
|
-
fs.renameSync(filePath, newPath);
|
|
165
|
-
console.log(`${filename}${extname} --> ${newName} 重命名成功!`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
console.log("[ee-core] [tools/iconGen] iconGen 资源处理完成!");
|
|
169
|
-
} catch (e) {
|
|
170
|
-
console.error("[ee-core] [tools/iconGen] ERROR: ", e);
|
|
171
|
-
throw new Error("重命名logo图片资源失败!!");
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const run = () => {
|
|
177
|
-
const i = new IconGen();
|
|
178
|
-
i.generateIcons();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
module.exports = {
|
|
182
|
-
run,
|
|
183
|
-
};
|
package/tools/replaceDist.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
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] [tools/rd] 开始移动资源');
|
|
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] [tools/rd] 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] [tools/rd] ERROR 前端资源不存在,请构建!!!');
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 清空历史资源 并 复制到ee资源目录
|
|
47
|
-
const eeResourceDir = path.join(homeDir, 'public', 'dist');
|
|
48
|
-
if (!fs.existsSync(eeResourceDir)) {
|
|
49
|
-
fs.mkdirSync(eeResourceDir, {recursive: true, mode: 0o777});
|
|
50
|
-
}
|
|
51
|
-
this._rmFolder(eeResourceDir);
|
|
52
|
-
console.log('[ee-core] [tools/rd] 清空历史资源:', eeResourceDir);
|
|
53
|
-
|
|
54
|
-
fsPro.copySync(sourceDir, eeResourceDir);
|
|
55
|
-
console.log('[ee-core] [tools/rd] 复制资源到:', eeResourceDir);
|
|
56
|
-
console.log('[ee-core] [tools/rd] 结束');
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 删除文件夹
|
|
61
|
-
*/
|
|
62
|
-
_rmFolder(folder) {
|
|
63
|
-
const nodeVersion = (process.versions && process.versions.node) || null;
|
|
64
|
-
if (nodeVersion && this._compareVersion(nodeVersion, '14.14.0') == 1) {
|
|
65
|
-
fs.rmSync(folder, {recursive: true});
|
|
66
|
-
} else {
|
|
67
|
-
fs.rmdirSync(folder, {recursive: true});
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 版本号比较
|
|
73
|
-
*/
|
|
74
|
-
_compareVersion(v1, v2) {
|
|
75
|
-
v1 = v1.split('.')
|
|
76
|
-
v2 = v2.split('.')
|
|
77
|
-
const len = Math.max(v1.length, v2.length)
|
|
78
|
-
|
|
79
|
-
while (v1.length < len) {
|
|
80
|
-
v1.push('0')
|
|
81
|
-
}
|
|
82
|
-
while (v2.length < len) {
|
|
83
|
-
v2.push('0')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (let i = 0; i < len; i++) {
|
|
87
|
-
const num1 = parseInt(v1[i])
|
|
88
|
-
const num2 = parseInt(v2[i])
|
|
89
|
-
|
|
90
|
-
if (num1 > num2) {
|
|
91
|
-
return 1
|
|
92
|
-
} else if (num1 < num2) {
|
|
93
|
-
return -1
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return 0
|
|
98
|
-
}
|
|
99
|
-
}
|