ee-bin 1.7.2 → 1.8.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 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/lib/utils.js CHANGED
@@ -7,7 +7,6 @@ const is = require('is-type-of');
7
7
  const { loadTsConfig } = require('config-file-ts');
8
8
  const JsonLib = require('json5');
9
9
  const mkdirp = require('mkdirp');
10
- const OS = require('os');
11
10
 
12
11
  const _basePath = process.cwd();
13
12
 
@@ -109,30 +108,10 @@ function compareVersion(v1, v2) {
109
108
  return 0
110
109
  }
111
110
 
112
- function isWindows() {
111
+ function isWindows(prop) {
113
112
  return process.platform === 'win32'
114
113
  }
115
114
 
116
- function isOSX() {
117
- return process.platform === 'darwin'
118
- }
119
-
120
- function isMacOS() {
121
- return isOSX()
122
- }
123
-
124
- function isLinux() {
125
- return process.platform === 'linux'
126
- }
127
-
128
- function isx86() {
129
- return process.arch === 'ia32'
130
- }
131
-
132
- function isx64() {
133
- return process.arch === 'x64'
134
- }
135
-
136
115
  /**
137
116
  * Delete a file or folder
138
117
  */
@@ -181,32 +160,6 @@ function writeJsonSync (filepath, str, options) {
181
160
  fs.writeFileSync(filepath, str);
182
161
  };
183
162
 
184
- function getPlatform(delimiter = "_", isDiffArch = false) {
185
- let os = "";
186
- if (isWindows()) {
187
- os = "windows";
188
- if (isDiffArch) {
189
- const arch = isx64() ? "64" : "32";
190
- os += delimiter + arch;
191
- }
192
- } else if (isMacOS()) {
193
- let isAppleSilicon = false;
194
- const cpus = OS.cpus();
195
- for (let cpu of cpus) {
196
- if (cpu.model.includes('Apple')) {
197
- isAppleSilicon = true;
198
- break;
199
- }
200
- }
201
- const core = isAppleSilicon? "apple" : "intel";
202
- os = "macos" + delimiter + core;
203
- } else if (isLinux()) {
204
- os = "linux";
205
- }
206
-
207
- return os;
208
- }
209
-
210
163
  module.exports = {
211
164
  loadConfig,
212
165
  checkConfig,
@@ -214,12 +167,6 @@ module.exports = {
214
167
  getElectronProgram,
215
168
  compareVersion,
216
169
  isWindows,
217
- isOSX,
218
- isMacOS,
219
- isLinux,
220
- isx86,
221
- isx64,
222
- getPlatform,
223
170
  rm,
224
171
  getPackage,
225
172
  readJsonSync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,112 @@ 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
- this.generateFile(cfg, asarFile);
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
- generateFile(cfg, asarFile) {
40
+ /**
41
+ * 生成增量升级文件
42
+ */
43
+ generateFile(config, asarFile, platform) {
44
+ const cfg = config[platform];
45
+ let latestVersionInfo = {}
46
+ const homeDir = process.cwd();
47
+ console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
48
+
49
+ let asarFilePath = "";
50
+ if (asarFile) {
51
+ asarFilePath = path.normalize(path.join(homeDir, asarFile));
52
+ } else if (Array.isArray(cfg.asarFile)) {
53
+ // 检查文件列表,如果存在就跳出
54
+ for (const filep of cfg.asarFile) {
55
+ asarFilePath = path.normalize(path.join(homeDir, filep));
56
+ if (fs.existsSync(asarFilePath)) {
57
+ break;
58
+ }
59
+ }
60
+ } else {
61
+ asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
62
+ }
63
+
64
+ if (!fs.existsSync(asarFilePath)) {
65
+ console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
66
+ return;
67
+ }
68
+
69
+ const packageJson = Utils.getPackage();
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) {
38
133
  var latestVersionInfo = {}
39
134
  const homeDir = process.cwd();
135
+ console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green('config:'), cfg);
40
136
 
41
137
  let asarFilePath = "";
42
138
  if (asarFile) {