ee-bin 4.1.11 → 4.2.0
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/index.js +1 -0
- package/package.json +2 -1
- package/tools/incrUpdater.js +72 -42
package/index.js
CHANGED
|
@@ -114,6 +114,7 @@ program
|
|
|
114
114
|
.option('--config <folder>', 'config file')
|
|
115
115
|
.option('--asar-file <file>', 'asar file path')
|
|
116
116
|
.option('--platform <flag>', 'platform')
|
|
117
|
+
.option('--force <flag>', 'force update full')
|
|
117
118
|
.action(function() {
|
|
118
119
|
incrUpdater.run(this.opts());
|
|
119
120
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-bin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "ee bin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"javascript-obfuscator": "^4.0.2",
|
|
28
28
|
"json5": "^2.2.3",
|
|
29
29
|
"mkdirp": "^2.1.3",
|
|
30
|
+
"js-yaml": "^4.1.0",
|
|
30
31
|
"tree-kill": "^1.2.2"
|
|
31
32
|
}
|
|
32
33
|
}
|
package/tools/incrUpdater.js
CHANGED
|
@@ -5,13 +5,13 @@ const fs = require('fs');
|
|
|
5
5
|
const fsPro = require('fs-extra');
|
|
6
6
|
const crypto = require('crypto');
|
|
7
7
|
const chalk = require('chalk');
|
|
8
|
-
const { loadConfig, getPackage, writeJsonSync } = require('../lib/utils');
|
|
9
8
|
const admZip = require('adm-zip');
|
|
10
9
|
const globby = require('globby');
|
|
11
|
-
|
|
10
|
+
const yaml = require('js-yaml');
|
|
11
|
+
const { loadConfig, writeJsonSync } = require('../lib/utils');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Updater
|
|
15
15
|
* @class
|
|
16
16
|
*/
|
|
17
17
|
|
|
@@ -25,43 +25,57 @@ class IncrUpdater {
|
|
|
25
25
|
'win-ia32-unpacked',
|
|
26
26
|
'linux-unpacked'
|
|
27
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';
|
|
28
33
|
this.nodeModulesString = 'node_modules';
|
|
29
34
|
this.asarUnpackedString = 'app.asar.unpacked';
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
|
-
*
|
|
38
|
+
* run
|
|
34
39
|
*/
|
|
35
40
|
run(options = {}) {
|
|
36
41
|
console.log('[ee-bin] [updater] Start');
|
|
37
|
-
const { config, asarFile, platform } = options;
|
|
42
|
+
const { config, asarFile, platform, force } = options;
|
|
38
43
|
const binCfg = loadConfig(config);
|
|
39
44
|
const cfg = binCfg.updater;
|
|
45
|
+
const forceUpdate = force == 'true' ? true : false;
|
|
40
46
|
|
|
41
47
|
if (!cfg) {
|
|
42
48
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
43
49
|
return;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
this.generateFile(cfg, asarFile, platform);
|
|
52
|
+
this.generateFile(cfg, asarFile, platform, forceUpdate);
|
|
47
53
|
|
|
48
54
|
console.log('[ee-bin] [updater] End');
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
58
|
+
* generate json file
|
|
53
59
|
*/
|
|
54
|
-
generateFile(config, asarFile, platform) {
|
|
60
|
+
generateFile(config, asarFile, platform, force = false) {
|
|
55
61
|
const cfg = config[platform];
|
|
56
62
|
if (!cfg) {
|
|
57
63
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platform} config does not exist`));
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
|
|
61
68
|
let latestVersionInfo = {}
|
|
62
69
|
const homeDir = process.cwd();
|
|
63
70
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
64
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
|
+
|
|
65
79
|
let asarFilePath = "";
|
|
66
80
|
if (asarFile) {
|
|
67
81
|
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
@@ -74,25 +88,26 @@ class IncrUpdater {
|
|
|
74
88
|
return;
|
|
75
89
|
}
|
|
76
90
|
|
|
77
|
-
const
|
|
78
|
-
const version = packageJson.version;
|
|
91
|
+
const version = metadataObj.version;
|
|
79
92
|
let platformForFilename = platform;
|
|
80
93
|
if (platform.indexOf("_") !== -1) {
|
|
81
94
|
const platformArr = platform.split("_");
|
|
95
|
+
// windows_32 -> windows-32
|
|
82
96
|
platformForFilename = platformArr.join("-");
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
//
|
|
99
|
+
// zip
|
|
86
100
|
let zipName = "";
|
|
87
|
-
|
|
101
|
+
const extZip = '.zip';
|
|
102
|
+
zipName = path.basename(cfg.output.zip, extZip) + `-${platformForFilename}-${version}${extZip}`;
|
|
88
103
|
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
89
104
|
if (fs.existsSync(asarZipPath)) {
|
|
90
105
|
fsPro.removeSync(asarZipPath);
|
|
91
106
|
}
|
|
92
107
|
const zip = new admZip();
|
|
93
|
-
//
|
|
108
|
+
// add asar
|
|
94
109
|
zip.addLocalFile(asarFilePath);
|
|
95
|
-
//
|
|
110
|
+
// add extraResources
|
|
96
111
|
if (cfg.extraResources && cfg.extraResources.length > 0) {
|
|
97
112
|
const files = globby.sync(cfg.extraResources, { cwd: homeDir });
|
|
98
113
|
for (const extraRes of files) {
|
|
@@ -108,7 +123,7 @@ class IncrUpdater {
|
|
|
108
123
|
zip.addLocalFile(extraResPath, zipFileDir);
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
|
-
//
|
|
126
|
+
// add asarUnpacked
|
|
112
127
|
if (cfg.asarUnpacked && cfg.asarUnpacked.length > 0) {
|
|
113
128
|
const modules = cfg.asarUnpacked;
|
|
114
129
|
for (const moduleItem of modules) {
|
|
@@ -130,23 +145,48 @@ class IncrUpdater {
|
|
|
130
145
|
}
|
|
131
146
|
});
|
|
132
147
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
const
|
|
148
|
+
// generate latest.json
|
|
149
|
+
// incr file
|
|
150
|
+
const zipSha1 = this.generateHash(asarZipPath, 'sha1', 'hex');
|
|
136
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
|
+
|
|
137
170
|
const item = {
|
|
138
171
|
version: version,
|
|
139
172
|
file: zipName,
|
|
140
173
|
size: fileStat.size,
|
|
141
|
-
sha1:
|
|
142
|
-
|
|
174
|
+
sha1: zipSha1,
|
|
175
|
+
fullFile: {
|
|
176
|
+
fileName: fullFileInfo.url,
|
|
177
|
+
size: fullFileInfo.size,
|
|
178
|
+
sha512: generateSha512,
|
|
179
|
+
},
|
|
180
|
+
force,
|
|
181
|
+
releaseDate: metadataObj.releaseDate,
|
|
143
182
|
};
|
|
144
|
-
const
|
|
183
|
+
const extJson = '.json';
|
|
184
|
+
const jsonName = path.basename(cfg.output.file, extJson) + `-${platformForFilename}${extJson}`;
|
|
145
185
|
latestVersionInfo = item;
|
|
146
186
|
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
147
187
|
writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
148
188
|
|
|
149
|
-
//
|
|
189
|
+
// Delete cache files to prevent generated zip files from being outdated versions
|
|
150
190
|
if (cfg.cleanCache) {
|
|
151
191
|
this.tmpAppDirs.forEach(dir => {
|
|
152
192
|
const dirPath = path.join(homeDir, cfg.output.directory, dir);
|
|
@@ -155,38 +195,28 @@ class IncrUpdater {
|
|
|
155
195
|
}
|
|
156
196
|
}
|
|
157
197
|
|
|
158
|
-
|
|
159
|
-
let
|
|
198
|
+
generateHash(filepath = "", algorithm = "sha512", encoding = "base64") {
|
|
199
|
+
let data = '';
|
|
160
200
|
if (filepath.length == 0) {
|
|
161
|
-
return
|
|
201
|
+
return data;
|
|
162
202
|
}
|
|
163
203
|
|
|
164
204
|
if (!fs.existsSync(filepath)) {
|
|
165
|
-
return
|
|
205
|
+
return data;
|
|
166
206
|
}
|
|
167
207
|
|
|
168
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + `generate
|
|
208
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + `generate ${algorithm} for filepath:${filepath}`);
|
|
169
209
|
try {
|
|
170
210
|
const buffer = fs.readFileSync(filepath);
|
|
171
|
-
const fsHash = crypto.createHash(
|
|
211
|
+
const fsHash = crypto.createHash(algorithm);
|
|
172
212
|
fsHash.update(buffer);
|
|
173
|
-
|
|
174
|
-
return
|
|
175
|
-
|
|
213
|
+
data = fsHash.digest(encoding);
|
|
214
|
+
return data;
|
|
176
215
|
} catch (error) {
|
|
177
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate
|
|
216
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate ${algorithm} error!`));
|
|
178
217
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
179
218
|
}
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_getFormattedDate() {
|
|
184
|
-
const date = new Date(); // 获取当前日期
|
|
185
|
-
const year = date.getFullYear(); // 获取年份
|
|
186
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,月份从0开始计数
|
|
187
|
-
const day = date.getDate().toString().padStart(2, '0'); // 获取日
|
|
188
|
-
|
|
189
|
-
return `${year}-${month}-${day}`;
|
|
219
|
+
return data;
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
|