ee-bin 1.7.1 → 1.7.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/lib/utils.js CHANGED
@@ -7,6 +7,7 @@ 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');
10
11
 
11
12
  const _basePath = process.cwd();
12
13
 
@@ -108,10 +109,30 @@ function compareVersion(v1, v2) {
108
109
  return 0
109
110
  }
110
111
 
111
- function isWindows(prop) {
112
+ function isWindows() {
112
113
  return process.platform === 'win32'
113
114
  }
114
115
 
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
+
115
136
  /**
116
137
  * Delete a file or folder
117
138
  */
@@ -160,6 +181,32 @@ function writeJsonSync (filepath, str, options) {
160
181
  fs.writeFileSync(filepath, str);
161
182
  };
162
183
 
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
+
163
210
  module.exports = {
164
211
  loadConfig,
165
212
  checkConfig,
@@ -167,6 +214,12 @@ module.exports = {
167
214
  getElectronProgram,
168
215
  compareVersion,
169
216
  isWindows,
217
+ isOSX,
218
+ isMacOS,
219
+ isLinux,
220
+ isx86,
221
+ isx64,
222
+ getPlatform,
170
223
  rm,
171
224
  getPackage,
172
225
  readJsonSync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@ module.exports = {
35
35
  },
36
36
 
37
37
  generateFile(cfg, asarFile) {
38
- const latestVersionInfo = {}
38
+ var latestVersionInfo = {}
39
39
  const homeDir = process.cwd();
40
40
 
41
41
  let asarFilePath = "";
@@ -60,9 +60,17 @@ module.exports = {
60
60
 
61
61
  const packageJson = Utils.getPackage();
62
62
  const version = packageJson.version;
63
+ const platformForFilename = Utils.getPlatform("-");
64
+ const platformForKey = Utils.getPlatform("_");
63
65
 
64
66
  // 生成 zip
65
- const zipName = path.basename(cfg.output.zip, '.zip') + `-${version}.zip`;
67
+ let zipName = "";
68
+ if (cfg.output.noPlatform === true) {
69
+ zipName = path.basename(cfg.output.zip, '.zip') + `-${version}.zip`;
70
+ } else {
71
+ zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
72
+ }
73
+
66
74
  const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
67
75
  if (fs.existsSync(asarZipPath) && cfg.cleanCache) {
68
76
  Utils.rm(asarZipPath);
@@ -79,23 +87,36 @@ module.exports = {
79
87
  const date = this._getFormattedDate();
80
88
  const fileStat = fs.statSync(asarFilePath);
81
89
 
82
- for (const item of cfg.platform) {
83
- latestVersionInfo[item] = {
84
- version: version,
85
- file: zipName,
86
- size: fileStat.size,
87
- sha1: sha1,
88
- releaseDate: date,
89
- };
90
+ const item = {
91
+ version: version,
92
+ file: zipName,
93
+ size: fileStat.size,
94
+ sha1: sha1,
95
+ releaseDate: date,
96
+ };
97
+ let jsonName = "";
98
+ if (cfg.output.noPlatform === true) {
99
+ jsonName = cfg.output.file;
100
+ latestVersionInfo = item;
101
+ } else {
102
+ // 生成与系统有关的文件
103
+ jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
104
+ if (platformForKey !== "") {
105
+ latestVersionInfo[platformForKey] = item;
106
+ } else {
107
+ console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platformForFilename} is not supported`));
108
+ }
90
109
  }
91
110
 
92
- const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, cfg.output.file);
111
+ const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
93
112
  Utils.writeJsonSync(updaterJsonFilePath, latestVersionInfo);
94
113
 
95
114
  // 删除缓存文件,防止生成的 zip 是旧版本
96
115
  if (cfg.cleanCache) {
97
116
  Utils.rm(path.join(homeDir, cfg.output.directory, 'mac'));
117
+ Utils.rm(path.join(homeDir, cfg.output.directory, 'mac-arm64'));
98
118
  Utils.rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
119
+ Utils.rm(path.join(homeDir, cfg.output.directory, 'linux-unpacked'));
99
120
  }
100
121
  },
101
122