ee-bin 1.7.1 → 1.8.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/index.js +1 -0
- package/package.json +1 -1
- package/tools/incrUpdater.js +132 -15
package/index.js
CHANGED
|
@@ -128,6 +128,7 @@ program
|
|
|
128
128
|
.description('updater commands')
|
|
129
129
|
.option('--config <folder>', 'config file', './electron/config/bin.js')
|
|
130
130
|
.option('--asar-file <file>', 'asar file path')
|
|
131
|
+
.option('--platform <flag>', 'platform')
|
|
131
132
|
.action(function() {
|
|
132
133
|
const updater = require('./tools/incrUpdater');
|
|
133
134
|
updater.run(this.opts());
|
package/package.json
CHANGED
package/tools/incrUpdater.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
*/
|
|
20
20
|
run(options = {}) {
|
|
21
21
|
console.log('[ee-bin] [updater] Start');
|
|
22
|
-
const { config, asarFile } = options;
|
|
22
|
+
const { config, asarFile, platform } = options;
|
|
23
23
|
const binCfg = Utils.loadConfig(config);
|
|
24
24
|
const cfg = binCfg.updater;
|
|
25
25
|
|
|
@@ -27,16 +27,24 @@ module.exports = {
|
|
|
27
27
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green('config:'), cfg);
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
if (platform) {
|
|
32
|
+
this.generateFile(cfg, asarFile, platform);
|
|
33
|
+
} else {
|
|
34
|
+
this.generateFileOld(cfg, asarFile);
|
|
35
|
+
}
|
|
33
36
|
|
|
34
37
|
console.log('[ee-bin] [updater] End');
|
|
35
38
|
},
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 生成增量升级文件
|
|
42
|
+
*/
|
|
43
|
+
generateFile(config, asarFile, platform) {
|
|
44
|
+
const cfg = config[platform];
|
|
45
|
+
let latestVersionInfo = {}
|
|
39
46
|
const homeDir = process.cwd();
|
|
47
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
40
48
|
|
|
41
49
|
let asarFilePath = "";
|
|
42
50
|
if (asarFile) {
|
|
@@ -60,9 +68,105 @@ module.exports = {
|
|
|
60
68
|
|
|
61
69
|
const packageJson = Utils.getPackage();
|
|
62
70
|
const version = packageJson.version;
|
|
71
|
+
let platformForFilename = platform;
|
|
72
|
+
if (platform.indexOf("_") !== -1) {
|
|
73
|
+
const platformArr = platform.split("_");
|
|
74
|
+
platformForFilename = platformArr.join("-");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 生成 zip
|
|
78
|
+
let zipName = "";
|
|
79
|
+
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
80
|
+
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
81
|
+
if (fs.existsSync(asarZipPath)) {
|
|
82
|
+
Utils.rm(asarZipPath);
|
|
83
|
+
}
|
|
84
|
+
const zip = new admZip();
|
|
85
|
+
// 添加 asar 文件
|
|
86
|
+
zip.addLocalFile(asarFilePath);
|
|
87
|
+
// 添加 extraResources
|
|
88
|
+
if (cfg.extraResources.length > 0) {
|
|
89
|
+
for (const extraRes of cfg.extraResources) {
|
|
90
|
+
const extraResPath = path.normalize(path.join(homeDir, extraRes));
|
|
91
|
+
if (fs.existsSync(extraResPath)) {
|
|
92
|
+
zip.addLocalFile(extraResPath, "extraResources");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
zip.writeZip(asarZipPath, (err) => {
|
|
98
|
+
if (err) {
|
|
99
|
+
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// 生成 latest.json
|
|
104
|
+
const sha1 = this.generateSha1(asarFilePath);
|
|
105
|
+
const date = this._getFormattedDate();
|
|
106
|
+
const fileStat = fs.statSync(asarFilePath);
|
|
107
|
+
const item = {
|
|
108
|
+
version: version,
|
|
109
|
+
file: zipName,
|
|
110
|
+
size: fileStat.size,
|
|
111
|
+
sha1: sha1,
|
|
112
|
+
releaseDate: date,
|
|
113
|
+
};
|
|
114
|
+
const jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
115
|
+
latestVersionInfo = item;
|
|
116
|
+
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
117
|
+
Utils.writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
118
|
+
|
|
119
|
+
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
120
|
+
if (cfg.cleanCache) {
|
|
121
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac'));
|
|
122
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac-arm64'));
|
|
123
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
|
|
124
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'win-ia32-unpacked'));
|
|
125
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'linux-unpacked'));
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 将废弃
|
|
131
|
+
*/
|
|
132
|
+
generateFileOld(cfg, asarFile) {
|
|
133
|
+
var latestVersionInfo = {}
|
|
134
|
+
const homeDir = process.cwd();
|
|
135
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green('config:'), cfg);
|
|
136
|
+
|
|
137
|
+
let asarFilePath = "";
|
|
138
|
+
if (asarFile) {
|
|
139
|
+
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
140
|
+
} else if (Array.isArray(cfg.asarFile)) {
|
|
141
|
+
// 检查文件列表,如果存在就跳出
|
|
142
|
+
for (const filep of cfg.asarFile) {
|
|
143
|
+
asarFilePath = path.normalize(path.join(homeDir, filep));
|
|
144
|
+
if (fs.existsSync(asarFilePath)) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!fs.existsSync(asarFilePath)) {
|
|
153
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const packageJson = Utils.getPackage();
|
|
158
|
+
const version = packageJson.version;
|
|
159
|
+
const platformForFilename = Utils.getPlatform("-");
|
|
160
|
+
const platformForKey = Utils.getPlatform("_");
|
|
63
161
|
|
|
64
162
|
// 生成 zip
|
|
65
|
-
|
|
163
|
+
let zipName = "";
|
|
164
|
+
if (cfg.output.noPlatform === true) {
|
|
165
|
+
zipName = path.basename(cfg.output.zip, '.zip') + `-${version}.zip`;
|
|
166
|
+
} else {
|
|
167
|
+
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
168
|
+
}
|
|
169
|
+
|
|
66
170
|
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
67
171
|
if (fs.existsSync(asarZipPath) && cfg.cleanCache) {
|
|
68
172
|
Utils.rm(asarZipPath);
|
|
@@ -79,23 +183,36 @@ module.exports = {
|
|
|
79
183
|
const date = this._getFormattedDate();
|
|
80
184
|
const fileStat = fs.statSync(asarFilePath);
|
|
81
185
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
186
|
+
const item = {
|
|
187
|
+
version: version,
|
|
188
|
+
file: zipName,
|
|
189
|
+
size: fileStat.size,
|
|
190
|
+
sha1: sha1,
|
|
191
|
+
releaseDate: date,
|
|
192
|
+
};
|
|
193
|
+
let jsonName = "";
|
|
194
|
+
if (cfg.output.noPlatform === true) {
|
|
195
|
+
jsonName = cfg.output.file;
|
|
196
|
+
latestVersionInfo = item;
|
|
197
|
+
} else {
|
|
198
|
+
// 生成与系统有关的文件
|
|
199
|
+
jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
200
|
+
if (platformForKey !== "") {
|
|
201
|
+
latestVersionInfo[platformForKey] = item;
|
|
202
|
+
} else {
|
|
203
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platformForFilename} is not supported`));
|
|
204
|
+
}
|
|
90
205
|
}
|
|
91
206
|
|
|
92
|
-
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory,
|
|
207
|
+
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
93
208
|
Utils.writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
94
209
|
|
|
95
210
|
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
96
211
|
if (cfg.cleanCache) {
|
|
97
212
|
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac'));
|
|
213
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac-arm64'));
|
|
98
214
|
Utils.rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
|
|
215
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'linux-unpacked'));
|
|
99
216
|
}
|
|
100
217
|
},
|
|
101
218
|
|