electron-smallest-updater 0.1.0 → 0.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # electron-smallest-updater
2
2
 
3
+ [更新日志](./CHANGELOG.md)
4
+
3
5
  用于最小更新 Electron Resources 的更新器。
4
6
 
5
7
  - 与 electron-updater 有相近的配置和用法。
@@ -33,7 +35,7 @@ exports.default = async (context) => {
33
35
  }
34
36
  ```
35
37
 
36
- 以上配置打包后会在指定的输出目录生成 `{productName}-{version}-smallest.zip`(资源压缩包) 和 `latest-smallest.json`(更新频道文件)。然后你可以把生成内容放到文件服务器上。
38
+ 以上配置打包后会在指定的输出目录生成 `{name}-{version}-smallest.zip`(资源压缩包) 和 `latest-smallest.json`(更新频道文件)。然后你可以把生成内容放到文件服务器上。
37
39
 
38
40
  ```json
39
41
  // latest-smallest.json
@@ -46,7 +48,7 @@ exports.default = async (context) => {
46
48
  },
47
49
  "releaseDate": "2024-04-08T02:23:43.648Z",
48
50
  "releaseName": "Update 1.1.0",
49
- "releaseNotes": "Update for version 1.1.0 is available"
51
+ // "releaseNotes": "Update for version 1.1.0 is available"
50
52
  }
51
53
  ```
52
54
 
@@ -201,5 +203,6 @@ export interface ProgressInfo {
201
203
  total: number
202
204
  percent: number
203
205
  transferred: number
206
+ bytesPerSecond: number
204
207
  }
205
208
  ```
package/dist/builder.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.smallestBuilder = void 0;
15
+ exports.smallestBuilder = smallestBuilder;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const adm_zip_1 = __importDefault(require("adm-zip"));
18
18
  const fast_glob_1 = __importDefault(require("fast-glob"));
@@ -27,12 +27,12 @@ function smallestBuilder(context, options) {
27
27
  const resources = (options === null || options === void 0 ? void 0 : options.resources) || defaultResources;
28
28
  const outChannelName = (options === null || options === void 0 ? void 0 : options.channel) || defaultChannel;
29
29
  const outChannelPath = path_1.default.join(context.outDir, outChannelName);
30
- const outResourceFileName = `${appInfo.productName}-${appInfo.version}-smallest.zip`;
30
+ const outResourceFileName = `${appInfo.name}-${appInfo.version}-smallest.zip`;
31
31
  const outResourceFilePath = path_1.default.join(context.outDir, outResourceFileName);
32
32
  // find resources
33
33
  let resourcesPath;
34
34
  if (platform === 'darwin') {
35
- resourcesPath = path_1.default.join(context.appOutDir, `${appInfo.productName}.app`, 'Contents', 'Resources');
35
+ resourcesPath = path_1.default.join(context.appOutDir, `${appInfo.name}.app`, 'Contents', 'Resources');
36
36
  }
37
37
  else {
38
38
  resourcesPath = path_1.default.join(context.appOutDir, 'resources');
@@ -58,9 +58,8 @@ function smallestBuilder(context, options) {
58
58
  },
59
59
  releaseDate: new Date().toISOString(),
60
60
  releaseName: `Update ${appInfo.version}`,
61
- releaseNotes: `Update for version ${appInfo.version} is available`,
61
+ // releaseNotes: `Update for version ${appInfo.version} is available`,
62
62
  };
63
63
  yield fs_extra_1.default.writeJSON(outChannelPath, publishJSON, { spaces: 2 });
64
64
  });
65
65
  }
66
- exports.smallestBuilder = smallestBuilder;
package/dist/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface ProgressInfo {
14
14
  total: number;
15
15
  percent: number;
16
16
  transferred: number;
17
+ bytesPerSecond: number;
17
18
  }
18
19
  export interface UpdateDownloadedInfo extends UpdateInfo {
19
20
  downloadFilePath: string;
package/dist/updater.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class SmallestUpdater extends TypedEmitter<SmallestUpdaterEvents>
4
4
  private logger;
5
5
  private channel;
6
6
  private publish;
7
+ private reqOptions;
7
8
  private updateInfo;
8
9
  private downloadUrl;
9
10
  private downloadDir;
package/dist/updater.js CHANGED
@@ -26,7 +26,7 @@ const tiny_typed_emitter_1 = require("tiny-typed-emitter");
26
26
  const utils_1 = require("./utils");
27
27
  class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
28
28
  constructor(options) {
29
- var _a, _b, _c, _d, _e;
29
+ var _a, _b, _c, _d, _e, _f;
30
30
  super();
31
31
  this.downloadUrl = '';
32
32
  this.downloadDir = '';
@@ -41,10 +41,11 @@ class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
41
41
  this.logger = (_a = options.logger) !== null && _a !== void 0 ? _a : console;
42
42
  this.channel = (_b = options.channel) !== null && _b !== void 0 ? _b : 'latest-smallest.json';
43
43
  this.publish = options.publish;
44
- this.autoDownload = (_c = options.autoDownload) !== null && _c !== void 0 ? _c : true;
45
- this.autoInstallOnAppQuit = (_d = options.autoInstallOnAppQuit) !== null && _d !== void 0 ? _d : true;
46
- this.forceDevUpdateConfig = (_e = options.forceDevUpdateConfig) !== null && _e !== void 0 ? _e : false;
47
- this.downloadDir = electron_1.app.getPath('userData');
44
+ this.reqOptions = (_c = options.publish.options) !== null && _c !== void 0 ? _c : {};
45
+ this.autoDownload = (_d = options.autoDownload) !== null && _d !== void 0 ? _d : true;
46
+ this.autoInstallOnAppQuit = (_e = options.autoInstallOnAppQuit) !== null && _e !== void 0 ? _e : true;
47
+ this.forceDevUpdateConfig = (_f = options.forceDevUpdateConfig) !== null && _f !== void 0 ? _f : false;
48
+ this.downloadDir = (0, node_path_1.join)(electron_1.app.getPath('userData'), 'SmallestUpdater');
48
49
  this.resourcesPath = process.resourcesPath;
49
50
  }
50
51
  /**
@@ -69,7 +70,7 @@ class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
69
70
  let updateInfo;
70
71
  try {
71
72
  this.emit('checking-for-update');
72
- updateInfo = yield (0, got_1.default)(Object.assign(Object.assign({}, this.publish), { url: `${url}/${this.channel}` })).json();
73
+ updateInfo = yield (0, got_1.default)(`${url}/${this.channel}`, Object.assign(Object.assign({}, this.reqOptions), { isStream: false, resolveBodyOnly: false, responseType: 'text' })).json();
73
74
  if (!(updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.version) || !updateInfo.releaseFile) {
74
75
  throw new Error('Invalid response content');
75
76
  }
@@ -89,6 +90,7 @@ class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
89
90
  else {
90
91
  this.emit('update-not-available', updateInfo);
91
92
  this.logger.info(`Update for version ${currentVersion} is not available (latest version: ${latestVersion}`);
93
+ return;
92
94
  }
93
95
  this.updateInfo = updateInfo;
94
96
  this.downloadUrl = this.formatDownloadUrl(updateInfo.releaseFile.url);
@@ -125,11 +127,17 @@ class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
125
127
  // download
126
128
  try {
127
129
  this.logger.info(`Download to ${downloadFilePath}`);
128
- const resStream = got_1.default.stream(downloadUrl);
129
- const writeStream = (0, node_fs_1.createWriteStream)(downloadFilePath);
130
+ const resStream = got_1.default.stream(downloadUrl, Object.assign(Object.assign({}, this.reqOptions), { isStream: true }));
131
+ const startTime = Date.now();
132
+ let nextUpdate = startTime;
130
133
  resStream.on('downloadProgress', (progress) => {
131
- this.emit('download-progress', progress);
134
+ const nowTime = Date.now();
135
+ if (nowTime >= nextUpdate || progress.percent >= 1) {
136
+ nextUpdate = nowTime + 1000;
137
+ this.emit('download-progress', Object.assign(Object.assign({}, progress), { percent: progress.percent * 100, bytesPerSecond: Math.round(progress.transferred / ((nowTime - startTime) / 1000)) }));
138
+ }
132
139
  });
140
+ const writeStream = (0, node_fs_1.createWriteStream)(downloadFilePath);
133
141
  yield (0, promises_1.pipeline)(resStream, writeStream);
134
142
  }
135
143
  catch (error) {
@@ -153,9 +161,14 @@ class SmallestUpdater extends tiny_typed_emitter_1.TypedEmitter {
153
161
  }
154
162
  // unzip
155
163
  try {
164
+ /**
165
+ * @link https://stackoverflow.com/questions/43645745/electron-invalid-package-on-unzip
166
+ */
167
+ process.noAsar = true;
156
168
  this.logger.info(`Extract to ${downloadUnzipPath}`);
157
169
  const zip = new adm_zip_1.default(downloadFilePath);
158
170
  zip.extractAllTo(downloadUnzipPath, true);
171
+ process.noAsar = false;
159
172
  }
160
173
  catch (error) {
161
174
  this.emit('error', error, `Extract error: ${error.message}`);
package/dist/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calcSha512 = void 0;
6
+ exports.calcSha512 = calcSha512;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  function calcSha512(filePath) {
@@ -20,4 +20,3 @@ function calcSha512(filePath) {
20
20
  });
21
21
  });
22
22
  }
23
- exports.calcSha512 = calcSha512;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-smallest-updater",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Electron Resources 按需最小更新、自动构建发布包及信息。",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist",