ee-core 1.3.4-beta.1 → 1.3.4-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 +0 -9
- package/package.json +1 -1
- package/tools/codeCompress.js +0 -204
package/bin/tools.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const codeCompress = require('../tools/codeCompress');
|
|
4
3
|
const replaceDist = require('../tools/replaceDist');
|
|
5
4
|
const encrypt = require('../tools/encrypt');
|
|
6
5
|
|
|
@@ -14,14 +13,6 @@ if (cmd == 'rd') {
|
|
|
14
13
|
replaceDist.run();
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
if (cmd == 'compress') {
|
|
18
|
-
codeCompress.compress();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (cmd == 'restore') {
|
|
22
|
-
codeCompress.restore();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
16
|
if (cmd == 'encrypt') {
|
|
26
17
|
encrypt.run();
|
|
27
18
|
}
|
package/package.json
CHANGED
package/tools/codeCompress.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const UglifyJS = require('uglify-js');
|
|
7
|
-
|
|
8
|
-
class CodeCompress {
|
|
9
|
-
constructor() {
|
|
10
|
-
const directory = [
|
|
11
|
-
'app',
|
|
12
|
-
'electron',
|
|
13
|
-
'config'
|
|
14
|
-
];
|
|
15
|
-
this.dirs = [];
|
|
16
|
-
|
|
17
|
-
this.basePath = process.cwd();
|
|
18
|
-
this.backupCodeDir = path.join(this.basePath, 'run', 'backup_code');
|
|
19
|
-
|
|
20
|
-
// 检查存在的目录
|
|
21
|
-
for (let i = 0; i < directory.length; i++) {
|
|
22
|
-
let codeDirPath = path.join(this.basePath, directory[i]);
|
|
23
|
-
if (fs.existsSync(codeDirPath)) {
|
|
24
|
-
this.dirs.push(directory[i]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
console.log('dirs:', this.dirs);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 备份 app、electron目录代码
|
|
32
|
-
*/
|
|
33
|
-
backup () {
|
|
34
|
-
console.log('[ee-core] [code_compress] [backup] start');
|
|
35
|
-
this.rmBackup();
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
38
|
-
// check code dir
|
|
39
|
-
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
40
|
-
if (!fs.existsSync(codeDirPath)) {
|
|
41
|
-
console.log('[ee-core] [code_compress] [backup] ERROR: %s is not exist', codeDirPath);
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// copy
|
|
46
|
-
let targetDir = path.join(this.backupCodeDir, this.dirs[i]);
|
|
47
|
-
console.log('[ee-core] [code_compress] [backup] targetDir:', targetDir);
|
|
48
|
-
if (!fs.existsSync(targetDir)) {
|
|
49
|
-
this.mkdir(targetDir);
|
|
50
|
-
this.chmodPath(targetDir, '777');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fsPro.copySync(codeDirPath, targetDir);
|
|
54
|
-
}
|
|
55
|
-
console.log('[ee-core] [code_compress] [backup] success');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 还原代码
|
|
60
|
-
*/
|
|
61
|
-
restore () {
|
|
62
|
-
console.log('[ee-core] [code_compress] [restore] start');
|
|
63
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
64
|
-
let codeDirPath = path.join(this.backupCodeDir, this.dirs[i]);
|
|
65
|
-
let targetDir = path.join(this.basePath, this.dirs[i]);
|
|
66
|
-
fsPro.copySync(codeDirPath, targetDir);
|
|
67
|
-
}
|
|
68
|
-
console.log('[ee-core] [code_compress] [restore] success');
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 压缩代码
|
|
73
|
-
*/
|
|
74
|
-
compress () {
|
|
75
|
-
console.log('[ee-core] [code_compress] [compress] start');
|
|
76
|
-
for (let i = 0; i < this.dirs.length; i++) {
|
|
77
|
-
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
78
|
-
this.compressLoop(codeDirPath);
|
|
79
|
-
}
|
|
80
|
-
console.log('[ee-core] [code_compress] [compress] success');
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
compressLoop (dirPath) {
|
|
84
|
-
let files = [];
|
|
85
|
-
if (fs.existsSync(dirPath)) {
|
|
86
|
-
files = fs.readdirSync(dirPath);
|
|
87
|
-
files.forEach((file, index) => {
|
|
88
|
-
let curPath = dirPath + '/' + file;
|
|
89
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
90
|
-
this.compressLoop(curPath);
|
|
91
|
-
} else {
|
|
92
|
-
if (path.extname(curPath) === '.js') {
|
|
93
|
-
this.miniFile(curPath);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
miniFile (file) {
|
|
101
|
-
let code = fs.readFileSync(file, "utf8");
|
|
102
|
-
const options = {
|
|
103
|
-
mangle: {
|
|
104
|
-
toplevel: false,
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
let result = UglifyJS.minify(code, options);
|
|
109
|
-
fs.writeFileSync(file, result.code, "utf8");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 格式化参数
|
|
114
|
-
*/
|
|
115
|
-
formatArgvs () {
|
|
116
|
-
// argv
|
|
117
|
-
let argvs = [];
|
|
118
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
119
|
-
const tmpArgv = process.argv[i]
|
|
120
|
-
if (tmpArgv.indexOf('--') !== -1) {
|
|
121
|
-
argvs.push(tmpArgv.substring(2))
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return argvs;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 移除备份
|
|
129
|
-
*/
|
|
130
|
-
rmBackup () {
|
|
131
|
-
if (fs.existsSync(this.backupCodeDir)) {
|
|
132
|
-
fs.rmSync(this.backupCodeDir, {recursive: true, force: true});
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 检查文件是否存在
|
|
139
|
-
*/
|
|
140
|
-
fileExist (filePath) {
|
|
141
|
-
try {
|
|
142
|
-
return fs.statSync(filePath).isFile();
|
|
143
|
-
} catch (err) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
mkdir (dirpath, dirname) {
|
|
149
|
-
// 判断是否是第一次调用
|
|
150
|
-
if (typeof dirname === 'undefined') {
|
|
151
|
-
if (fs.existsSync(dirpath)) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this.mkdir(dirpath, path.dirname(dirpath));
|
|
155
|
-
} else {
|
|
156
|
-
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
157
|
-
if (dirname !== path.dirname(dirpath)) {
|
|
158
|
-
this.mkdir(dirpath);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (fs.existsSync(dirname)) {
|
|
162
|
-
fs.mkdirSync(dirpath);
|
|
163
|
-
} else {
|
|
164
|
-
this.mkdir(dirname, path.dirname(dirname));
|
|
165
|
-
fs.mkdirSync(dirpath);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
chmodPath (path, mode) {
|
|
171
|
-
let files = [];
|
|
172
|
-
if (fs.existsSync(path)) {
|
|
173
|
-
files = fs.readdirSync(path);
|
|
174
|
-
files.forEach((file, index) => {
|
|
175
|
-
const curPath = path + '/' + file;
|
|
176
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
177
|
-
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
178
|
-
} else {
|
|
179
|
-
fs.chmodSync(curPath, mode);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
fs.chmodSync(path, mode);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const compress = () => {
|
|
188
|
-
const cc = new CodeCompress();
|
|
189
|
-
cc.backup();
|
|
190
|
-
cc.compress();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const restore = () => {
|
|
194
|
-
const cc = new CodeCompress();
|
|
195
|
-
cc.restore();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
module.exports = {
|
|
199
|
-
compress,
|
|
200
|
-
restore
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|