ee-bin 4.2.0 → 5.0.0-beta.1
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/dist/cjs/config/bin_default.js +149 -0
- package/dist/cjs/config/bin_default.js.map +1 -0
- package/dist/cjs/index.js +98 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/extend.js +48 -0
- package/dist/cjs/lib/extend.js.map +1 -0
- package/dist/cjs/lib/helpers.js +92 -0
- package/dist/cjs/lib/helpers.js.map +1 -0
- package/dist/cjs/lib/utils.js +108 -0
- package/dist/cjs/lib/utils.js.map +1 -0
- package/dist/cjs/tools/encrypt.js +121 -0
- package/dist/cjs/tools/encrypt.js.map +1 -0
- package/dist/cjs/tools/iconGen.js +140 -0
- package/dist/cjs/tools/iconGen.js.map +1 -0
- package/dist/cjs/tools/incrUpdater.js +187 -0
- package/dist/cjs/tools/incrUpdater.js.map +1 -0
- package/dist/cjs/tools/move.js +56 -0
- package/dist/cjs/tools/move.js.map +1 -0
- package/dist/cjs/tools/serve.js +286 -0
- package/dist/cjs/tools/serve.js.map +1 -0
- package/dist/esm/config/bin_default.d.ts +148 -0
- package/dist/esm/config/bin_default.d.ts.map +1 -0
- package/dist/esm/config/bin_default.js +149 -0
- package/dist/esm/config/bin_default.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +98 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/extend.d.ts +3 -0
- package/dist/esm/lib/extend.d.ts.map +1 -0
- package/dist/esm/lib/extend.js +48 -0
- package/dist/esm/lib/extend.js.map +1 -0
- package/dist/esm/lib/helpers.d.ts +23 -0
- package/dist/esm/lib/helpers.d.ts.map +1 -0
- package/dist/esm/lib/helpers.js +92 -0
- package/dist/esm/lib/helpers.js.map +1 -0
- package/dist/esm/lib/utils.d.ts +11 -0
- package/dist/esm/lib/utils.d.ts.map +1 -0
- package/dist/esm/lib/utils.js +108 -0
- package/dist/esm/lib/utils.js.map +1 -0
- package/dist/esm/tools/encrypt.d.ts +11 -0
- package/dist/esm/tools/encrypt.d.ts.map +1 -0
- package/dist/esm/tools/encrypt.js +121 -0
- package/dist/esm/tools/encrypt.js.map +1 -0
- package/dist/esm/tools/iconGen.d.ts +2 -0
- package/dist/esm/tools/iconGen.d.ts.map +1 -0
- package/dist/esm/tools/iconGen.js +140 -0
- package/dist/esm/tools/iconGen.js.map +1 -0
- package/dist/esm/tools/incrUpdater.d.ts +32 -0
- package/dist/esm/tools/incrUpdater.d.ts.map +1 -0
- package/dist/esm/tools/incrUpdater.js +187 -0
- package/dist/esm/tools/incrUpdater.js.map +1 -0
- package/dist/esm/tools/move.d.ts +7 -0
- package/dist/esm/tools/move.d.ts.map +1 -0
- package/dist/esm/tools/move.js +56 -0
- package/dist/esm/tools/move.js.map +1 -0
- package/dist/esm/tools/serve.d.ts +42 -0
- package/dist/esm/tools/serve.d.ts.map +1 -0
- package/dist/esm/tools/serve.js +286 -0
- package/dist/esm/tools/serve.js.map +1 -0
- package/package.json +67 -33
- package/config/bin_default.js +0 -182
- package/index.js +0 -122
- package/lib/extend.js +0 -78
- package/lib/pargv.js +0 -263
- package/lib/utils.js +0 -255
- package/readme.md +0 -1
- package/tools/encrypt.js +0 -179
- package/tools/iconGen.js +0 -183
- package/tools/incrUpdater.js +0 -226
- package/tools/move.js +0 -69
- package/tools/serve.js +0 -346
package/tools/encrypt.js
DELETED
|
@@ -1,179 +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 JavaScriptObfuscator = require('javascript-obfuscator');
|
|
9
|
-
const globby = require('globby');
|
|
10
|
-
const chalk = require('chalk');
|
|
11
|
-
const { loadConfig } = require('../lib/utils');
|
|
12
|
-
const { extend } = require('../lib/extend');
|
|
13
|
-
|
|
14
|
-
const EncryptTypes = ['bytecode', 'confusion', 'strict'];
|
|
15
|
-
|
|
16
|
-
class Encrypt {
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
// cli args
|
|
19
|
-
const { config, out, target } = options;
|
|
20
|
-
this.basePath = process.cwd();
|
|
21
|
-
this.target = target;
|
|
22
|
-
|
|
23
|
-
const conf = loadConfig(config).encrypt;
|
|
24
|
-
this.config = conf[target];
|
|
25
|
-
const outputFolder = out || this.config.encryptDir;
|
|
26
|
-
this.encryptDir = path.join(this.basePath, outputFolder);
|
|
27
|
-
this.filesExt = this.config.fileExt;
|
|
28
|
-
this.type = this.config.type;
|
|
29
|
-
this.bOpt = this.config.bytecodeOptions;
|
|
30
|
-
this.cOpt = this.config.confusionOptions;
|
|
31
|
-
this.cleanFiles = this.config.cleanFiles;
|
|
32
|
-
this.patterns = this.config.files || null;
|
|
33
|
-
this.specFiles = this.config.specificFiles;
|
|
34
|
-
|
|
35
|
-
this.codefiles = this._initCodeFiles();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 初始化需要加密的文件列表
|
|
40
|
-
*/
|
|
41
|
-
_initCodeFiles() {
|
|
42
|
-
if (!this.patterns) return;
|
|
43
|
-
|
|
44
|
-
const files = globby.sync(this.patterns, { cwd: this.basePath });
|
|
45
|
-
return files;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 加密代码
|
|
50
|
-
*/
|
|
51
|
-
encrypt() {
|
|
52
|
-
if (EncryptTypes.indexOf(this.type) == -1) return;
|
|
53
|
-
if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
|
|
54
|
-
|
|
55
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
|
|
56
|
-
for (const file of this.codefiles) {
|
|
57
|
-
const fullpath = path.join(this.encryptDir, file);
|
|
58
|
-
if (!fs.statSync(fullpath).isFile()) continue;
|
|
59
|
-
|
|
60
|
-
// 特殊文件处理
|
|
61
|
-
if (this.specFiles.includes(file)) {
|
|
62
|
-
this.generate(fullpath, 'confusion');
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.generate(fullpath);
|
|
67
|
-
}
|
|
68
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 递归
|
|
73
|
-
*/
|
|
74
|
-
loop(dirPath) {
|
|
75
|
-
let files = [];
|
|
76
|
-
if (fs.existsSync(dirPath)) {
|
|
77
|
-
files = fs.readdirSync(dirPath);
|
|
78
|
-
files.forEach((file, index) => {
|
|
79
|
-
let curPath = dirPath + '/' + file;
|
|
80
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
81
|
-
this.loop(curPath);
|
|
82
|
-
} else {
|
|
83
|
-
const extname = path.extname(curPath);
|
|
84
|
-
if (this.filesExt.indexOf(extname) !== -1) {
|
|
85
|
-
this.generate(curPath);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 生成文件
|
|
94
|
-
*/
|
|
95
|
-
generate(curPath, type) {
|
|
96
|
-
let encryptType = type ? type : this.type;
|
|
97
|
-
|
|
98
|
-
let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
|
|
99
|
-
console.log(tips);
|
|
100
|
-
if (encryptType == 'strict') {
|
|
101
|
-
this.generateJSConfuseFile(curPath);
|
|
102
|
-
this.generateBytecodeFile(curPath);
|
|
103
|
-
} else if (encryptType == 'bytecode') {
|
|
104
|
-
this.generateBytecodeFile(curPath);
|
|
105
|
-
} else if (encryptType == 'confusion') {
|
|
106
|
-
this.generateJSConfuseFile(curPath);
|
|
107
|
-
} else {
|
|
108
|
-
// none
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
114
|
-
*/
|
|
115
|
-
generateJSConfuseFile(file) {
|
|
116
|
-
let opt = Object.assign({
|
|
117
|
-
compact: true,
|
|
118
|
-
stringArray: true,
|
|
119
|
-
stringArrayThreshold: 1,
|
|
120
|
-
}, this.cOpt);
|
|
121
|
-
|
|
122
|
-
let code = fs.readFileSync(file, "utf8");
|
|
123
|
-
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
124
|
-
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 生成字节码文件
|
|
129
|
-
*/
|
|
130
|
-
generateBytecodeFile(curPath) {
|
|
131
|
-
if (path.extname(curPath) !== '.js') {
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
135
|
-
let jscFile = curPath + 'c';
|
|
136
|
-
let opt = Object.assign({
|
|
137
|
-
filename: curPath,
|
|
138
|
-
output: jscFile,
|
|
139
|
-
electron: true
|
|
140
|
-
}, this.bOpt);
|
|
141
|
-
|
|
142
|
-
bytenode.compileFile(opt);
|
|
143
|
-
fsPro.removeSync(curPath);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function encrypt(options = {}) {
|
|
148
|
-
const electronOpt = extend(true, {
|
|
149
|
-
target: 'electron',
|
|
150
|
-
}, options);
|
|
151
|
-
const electronEpt = new Encrypt(electronOpt);
|
|
152
|
-
electronEpt.encrypt();
|
|
153
|
-
|
|
154
|
-
const frontendOpt = extend(true, {
|
|
155
|
-
target: 'frontend',
|
|
156
|
-
}, options);
|
|
157
|
-
const frontendEpt = new Encrypt(frontendOpt);
|
|
158
|
-
frontendEpt.encrypt();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function cleanEncrypt(options = {}) {
|
|
162
|
-
// [todo] 删除前端和主进程代码
|
|
163
|
-
return;
|
|
164
|
-
let files = options.dir !== undefined ? options.dir : ['./public/electron'];
|
|
165
|
-
files = is.string(files) ? [files] : files;
|
|
166
|
-
|
|
167
|
-
files.forEach((file) => {
|
|
168
|
-
const tmpFile = path.join(process.cwd(), file);
|
|
169
|
-
if (fs.existsSync(tmpFile)) {
|
|
170
|
-
fsPro.removeSync(tmpFile);
|
|
171
|
-
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
module.exports = {
|
|
177
|
-
encrypt,
|
|
178
|
-
cleanEncrypt,
|
|
179
|
-
};
|
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-bin] [icon-gen] args: ", args);
|
|
56
|
-
console.error("[ee-bin] [icon-gen] ERROR: ", e);
|
|
57
|
-
throw new Error("参数错误!!");
|
|
58
|
-
}
|
|
59
|
-
this.params = params;
|
|
60
|
-
|
|
61
|
-
// ---> 组装参数
|
|
62
|
-
console.log("[ee-bin] [icon-gen] 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-bin] [icon-gen] iconGen 开始处理生成logo图片");
|
|
86
|
-
if (!fs.existsSync(this.input)) {
|
|
87
|
-
console.error("[ee-bin] [icon-gen] 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-bin] [icon-gen] iconGen 已生成下方图片资源");
|
|
102
|
-
console.log(results);
|
|
103
|
-
this._renameForEE(results);
|
|
104
|
-
})
|
|
105
|
-
.catch((err) => {
|
|
106
|
-
console.error(err);
|
|
107
|
-
throw new Error("[ee-bin] [icon-gen] 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-bin] [icon-gen] 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-bin] [icon-gen] iconGen 资源处理完成!");
|
|
169
|
-
} catch (e) {
|
|
170
|
-
console.error("[ee-bin] [icon-gen] 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/incrUpdater.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const crypto = require('crypto');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
const admZip = require('adm-zip');
|
|
9
|
-
const globby = require('globby');
|
|
10
|
-
const yaml = require('js-yaml');
|
|
11
|
-
const { loadConfig, writeJsonSync } = require('../lib/utils');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Updater
|
|
15
|
-
* @class
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
class IncrUpdater {
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.tmpAppDirs = [
|
|
22
|
-
'mac',
|
|
23
|
-
'mac-arm64',
|
|
24
|
-
'win-unpacked',
|
|
25
|
-
'win-ia32-unpacked',
|
|
26
|
-
'linux-unpacked'
|
|
27
|
-
];
|
|
28
|
-
this.windows32Platform = 'windows_32';
|
|
29
|
-
this.windows64Platform = 'windows_64';
|
|
30
|
-
this.macosIntelPlatform = 'macos_intel';
|
|
31
|
-
this.macosApplePlatform = 'macos_apple';
|
|
32
|
-
this.linuxPlatform = 'linux';
|
|
33
|
-
this.nodeModulesString = 'node_modules';
|
|
34
|
-
this.asarUnpackedString = 'app.asar.unpacked';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* run
|
|
39
|
-
*/
|
|
40
|
-
run(options = {}) {
|
|
41
|
-
console.log('[ee-bin] [updater] Start');
|
|
42
|
-
const { config, asarFile, platform, force } = options;
|
|
43
|
-
const binCfg = loadConfig(config);
|
|
44
|
-
const cfg = binCfg.updater;
|
|
45
|
-
const forceUpdate = force == 'true' ? true : false;
|
|
46
|
-
|
|
47
|
-
if (!cfg) {
|
|
48
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.generateFile(cfg, asarFile, platform, forceUpdate);
|
|
53
|
-
|
|
54
|
-
console.log('[ee-bin] [updater] End');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* generate json file
|
|
59
|
-
*/
|
|
60
|
-
generateFile(config, asarFile, platform, force = false) {
|
|
61
|
-
const cfg = config[platform];
|
|
62
|
-
if (!cfg) {
|
|
63
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platform} config does not exist`));
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let latestVersionInfo = {}
|
|
69
|
-
const homeDir = process.cwd();
|
|
70
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
71
|
-
|
|
72
|
-
const metadataPath = path.join(homeDir, cfg.metadata);
|
|
73
|
-
if (!fs.existsSync(metadataPath)) {
|
|
74
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${metadataPath} does not exist!`));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const metadataObj = yaml.load(fs.readFileSync(metadataPath, 'utf8'));
|
|
78
|
-
|
|
79
|
-
let asarFilePath = "";
|
|
80
|
-
if (asarFile) {
|
|
81
|
-
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
82
|
-
} else {
|
|
83
|
-
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!fs.existsSync(asarFilePath)) {
|
|
87
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const version = metadataObj.version;
|
|
92
|
-
let platformForFilename = platform;
|
|
93
|
-
if (platform.indexOf("_") !== -1) {
|
|
94
|
-
const platformArr = platform.split("_");
|
|
95
|
-
// windows_32 -> windows-32
|
|
96
|
-
platformForFilename = platformArr.join("-");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// zip
|
|
100
|
-
let zipName = "";
|
|
101
|
-
const extZip = '.zip';
|
|
102
|
-
zipName = path.basename(cfg.output.zip, extZip) + `-${platformForFilename}-${version}${extZip}`;
|
|
103
|
-
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
104
|
-
if (fs.existsSync(asarZipPath)) {
|
|
105
|
-
fsPro.removeSync(asarZipPath);
|
|
106
|
-
}
|
|
107
|
-
const zip = new admZip();
|
|
108
|
-
// add asar
|
|
109
|
-
zip.addLocalFile(asarFilePath);
|
|
110
|
-
// add extraResources
|
|
111
|
-
if (cfg.extraResources && cfg.extraResources.length > 0) {
|
|
112
|
-
const files = globby.sync(cfg.extraResources, { cwd: homeDir });
|
|
113
|
-
for (const extraRes of files) {
|
|
114
|
-
const extraResPath = path.normalize(path.join(homeDir, extraRes));
|
|
115
|
-
if (!fs.existsSync(extraResPath)) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const extraResDir = path.dirname(extraResPath);
|
|
119
|
-
const index = extraResDir.indexOf('extraResources');
|
|
120
|
-
const zipFileDir = extraResDir.substring(index);
|
|
121
|
-
// 资源路径 extraResPath: D:\www\gofile\src\ee\ee-demo\build\extraResources\hello\c.txt
|
|
122
|
-
// 文件在zip中的路径 zipFileDir: extraResources/hello
|
|
123
|
-
zip.addLocalFile(extraResPath, zipFileDir);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// add asarUnpacked
|
|
127
|
-
if (cfg.asarUnpacked && cfg.asarUnpacked.length > 0) {
|
|
128
|
-
const modules = cfg.asarUnpacked;
|
|
129
|
-
for (const moduleItem of modules) {
|
|
130
|
-
const modulePath = path.normalize(path.join(homeDir, moduleItem));
|
|
131
|
-
if (!fs.existsSync(modulePath)) {
|
|
132
|
-
throw new Error(`${modulePath} is not exists!`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const zipDir = path.join(this.asarUnpackedString, moduleItem);
|
|
136
|
-
// console.log('modulePath', modulePath);
|
|
137
|
-
// console.log('zipDir', zipDir);
|
|
138
|
-
zip.addLocalFolder(modulePath, zipDir);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
zip.writeZip(asarZipPath, (err) => {
|
|
143
|
-
if (err) {
|
|
144
|
-
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// generate latest.json
|
|
149
|
-
// incr file
|
|
150
|
-
const zipSha1 = this.generateHash(asarZipPath, 'sha1', 'hex');
|
|
151
|
-
const fileStat = fs.statSync(asarZipPath);
|
|
152
|
-
// full file
|
|
153
|
-
let fullFileInfo;
|
|
154
|
-
for (const item of metadataObj.files) {
|
|
155
|
-
if (item.url.indexOf('.zip') !== -1) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
fullFileInfo = item;
|
|
159
|
-
}
|
|
160
|
-
const fullFileName = fullFileInfo.url;
|
|
161
|
-
const fullFilePath = path.normalize(path.join(homeDir, cfg.output.directory, fullFileName));
|
|
162
|
-
const generateSha512 = this.generateHash(fullFilePath, 'sha512');
|
|
163
|
-
if (fullFileInfo.sha512 != generateSha512) {
|
|
164
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: metadata sha512 is not equal to generateSha512 !
|
|
165
|
-
at metadata sha512: ${fullFileInfo.sha512}
|
|
166
|
-
at generate Sha512: ${generateSha512}`));
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const item = {
|
|
171
|
-
version: version,
|
|
172
|
-
file: zipName,
|
|
173
|
-
size: fileStat.size,
|
|
174
|
-
sha1: zipSha1,
|
|
175
|
-
fullFile: {
|
|
176
|
-
fileName: fullFileInfo.url,
|
|
177
|
-
size: fullFileInfo.size,
|
|
178
|
-
sha512: generateSha512,
|
|
179
|
-
},
|
|
180
|
-
force,
|
|
181
|
-
releaseDate: metadataObj.releaseDate,
|
|
182
|
-
};
|
|
183
|
-
const extJson = '.json';
|
|
184
|
-
const jsonName = path.basename(cfg.output.file, extJson) + `-${platformForFilename}${extJson}`;
|
|
185
|
-
latestVersionInfo = item;
|
|
186
|
-
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
187
|
-
writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
188
|
-
|
|
189
|
-
// Delete cache files to prevent generated zip files from being outdated versions
|
|
190
|
-
if (cfg.cleanCache) {
|
|
191
|
-
this.tmpAppDirs.forEach(dir => {
|
|
192
|
-
const dirPath = path.join(homeDir, cfg.output.directory, dir);
|
|
193
|
-
fsPro.removeSync(dirPath);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
generateHash(filepath = "", algorithm = "sha512", encoding = "base64") {
|
|
199
|
-
let data = '';
|
|
200
|
-
if (filepath.length == 0) {
|
|
201
|
-
return data;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (!fs.existsSync(filepath)) {
|
|
205
|
-
return data;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + `generate ${algorithm} for filepath:${filepath}`);
|
|
209
|
-
try {
|
|
210
|
-
const buffer = fs.readFileSync(filepath);
|
|
211
|
-
const fsHash = crypto.createHash(algorithm);
|
|
212
|
-
fsHash.update(buffer);
|
|
213
|
-
data = fsHash.digest(encoding);
|
|
214
|
-
return data;
|
|
215
|
-
} catch (error) {
|
|
216
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate ${algorithm} error!`));
|
|
217
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
218
|
-
}
|
|
219
|
-
return data;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
module.exports = {
|
|
224
|
-
IncrUpdater,
|
|
225
|
-
incrUpdater: new IncrUpdater()
|
|
226
|
-
}
|
package/tools/move.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const chalk = require('chalk');
|
|
7
|
-
const { loadConfig, rm } = require('../lib/utils');
|
|
8
|
-
|
|
9
|
-
const homeDir = process.cwd();
|
|
10
|
-
|
|
11
|
-
// 移动资源
|
|
12
|
-
function move(options = {}) {
|
|
13
|
-
console.log('[ee-bin] [move] Start moving resources');
|
|
14
|
-
const { config, flag } = options;
|
|
15
|
-
const binCfg = loadConfig(config);
|
|
16
|
-
const moveConfig = binCfg.move;
|
|
17
|
-
|
|
18
|
-
let flags;
|
|
19
|
-
const flagString = flag.trim();
|
|
20
|
-
if (flagString.indexOf(',') !== -1) {
|
|
21
|
-
flags = flagString.split(',');
|
|
22
|
-
} else {
|
|
23
|
-
flags = [flagString];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < flags.length; i++) {
|
|
27
|
-
let f = flags[i];
|
|
28
|
-
let cfg = moveConfig[f];
|
|
29
|
-
|
|
30
|
-
if (!cfg) {
|
|
31
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { src, dest, dist, target } = cfg;
|
|
36
|
-
const source = dist ? dist : src;
|
|
37
|
-
const destination = target ? target : dest;
|
|
38
|
-
|
|
39
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
40
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
41
|
-
|
|
42
|
-
const srcResource = path.join(homeDir, source);
|
|
43
|
-
if (!fs.existsSync(srcResource)) {
|
|
44
|
-
const errorTips = chalk.bgRed('Error') + ` ${source} resource does not exist !`;
|
|
45
|
-
console.error(errorTips);
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// clear the historical resource and copy it to the ee resource directory
|
|
50
|
-
const destResource = path.join(homeDir, destination);
|
|
51
|
-
if (fs.statSync(srcResource).isDirectory() && !fs.existsSync(destResource)) {
|
|
52
|
-
fs.mkdirSync(destResource, {recursive: true, mode: 0o777});
|
|
53
|
-
} else {
|
|
54
|
-
rm(destResource);
|
|
55
|
-
console.log('[ee-bin] [move] Clear history resources:', destResource);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fsPro.copySync(srcResource, destResource);
|
|
59
|
-
|
|
60
|
-
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
61
|
-
console.log(`[ee-bin] [move] Copy ${srcResource} to ${destResource}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log('[ee-bin] [move] End');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = {
|
|
68
|
-
move
|
|
69
|
-
}
|