ee-core 1.2.10-beta.1 → 1.2.10-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/package.json +1 -1
- package/tools/encrypt.js +45 -9
package/package.json
CHANGED
package/tools/encrypt.js
CHANGED
|
@@ -4,6 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const fsPro = require('fs-extra');
|
|
6
6
|
const UglifyJS = require('uglify-js');
|
|
7
|
+
const bytenode = require('bytenode');
|
|
7
8
|
|
|
8
9
|
class Encrypt {
|
|
9
10
|
constructor() {
|
|
@@ -39,7 +40,7 @@ class Encrypt {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
* 备份 electron目录代码
|
|
43
|
+
* 备份 electron 目录代码
|
|
43
44
|
*/
|
|
44
45
|
backup () {
|
|
45
46
|
console.log('[ee-core] [encrypt] backup start');
|
|
@@ -58,7 +59,7 @@ class Encrypt {
|
|
|
58
59
|
this.rmBackup(targetDir);
|
|
59
60
|
|
|
60
61
|
// copy
|
|
61
|
-
console.log('[ee-core] [encrypt] backup
|
|
62
|
+
console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
|
|
62
63
|
if (!fs.existsSync(targetDir)) {
|
|
63
64
|
this.mkdir(targetDir);
|
|
64
65
|
this.chmodPath(targetDir, '777');
|
|
@@ -70,17 +71,21 @@ class Encrypt {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
|
-
*
|
|
74
|
+
* 加密代码
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
-
console.log('[ee-core] [encrypt]
|
|
76
|
+
encrypt () {
|
|
77
|
+
console.log('[ee-core] [encrypt] start ciphering');
|
|
77
78
|
for (let i = 0; i < this.dirs.length; i++) {
|
|
78
79
|
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
79
80
|
this.compressLoop(codeDirPath);
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
console.log('[ee-core] [encrypt] end ciphering');
|
|
82
84
|
};
|
|
83
85
|
|
|
86
|
+
/**
|
|
87
|
+
* 递归
|
|
88
|
+
*/
|
|
84
89
|
compressLoop (dirPath) {
|
|
85
90
|
let files = [];
|
|
86
91
|
if (fs.existsSync(dirPath)) {
|
|
@@ -91,14 +96,28 @@ class Encrypt {
|
|
|
91
96
|
this.compressLoop(curPath);
|
|
92
97
|
} else {
|
|
93
98
|
if (path.extname(curPath) === '.js') {
|
|
94
|
-
this.
|
|
99
|
+
this.generate(curPath);
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
});
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
/**
|
|
107
|
+
* 生成文件
|
|
108
|
+
*/
|
|
109
|
+
generate (curPath) {
|
|
110
|
+
if (this.type == 'bytecode') {
|
|
111
|
+
this.generateBytecodeFile(curPath);
|
|
112
|
+
} else {
|
|
113
|
+
this.generateBytecodeFile(curPath);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 生成压缩/混淆文件
|
|
119
|
+
*/
|
|
120
|
+
generateConfuseFile (file) {
|
|
102
121
|
let code = fs.readFileSync(file, "utf8");
|
|
103
122
|
const options = {
|
|
104
123
|
mangle: {
|
|
@@ -110,6 +129,23 @@ class Encrypt {
|
|
|
110
129
|
fs.writeFileSync(file, result.code, "utf8");
|
|
111
130
|
}
|
|
112
131
|
|
|
132
|
+
/**
|
|
133
|
+
* 生成字节码文件
|
|
134
|
+
*/
|
|
135
|
+
generateBytecodeFile (curPath) {
|
|
136
|
+
if (path.extname(curPath) !== '.js') {
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
140
|
+
let jscFile = curPath + 'c';
|
|
141
|
+
bytenode.compileFile({
|
|
142
|
+
filename: curPath,
|
|
143
|
+
output: jscFile,
|
|
144
|
+
});
|
|
145
|
+
fs.rmSync(curPath, {force: true});
|
|
146
|
+
console.log('[ee-core] [encrypt] generate ', jscFile);
|
|
147
|
+
}
|
|
148
|
+
|
|
113
149
|
/**
|
|
114
150
|
* 移除备份
|
|
115
151
|
*/
|
|
@@ -174,7 +210,7 @@ class Encrypt {
|
|
|
174
210
|
const run = () => {
|
|
175
211
|
const e = new Encrypt();
|
|
176
212
|
e.backup();
|
|
177
|
-
e.
|
|
213
|
+
e.encrypt();
|
|
178
214
|
}
|
|
179
215
|
|
|
180
216
|
module.exports = {
|