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 +5 -2
- package/dist/builder.js +4 -5
- package/dist/types.d.ts +1 -0
- package/dist/updater.d.ts +1 -0
- package/dist/updater.js +22 -9
- package/dist/utils.js +1 -2
- package/package.json +1 -1
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
|
-
以上配置打包后会在指定的输出目录生成 `{
|
|
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 =
|
|
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.
|
|
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.
|
|
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
package/dist/updater.d.ts
CHANGED
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.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
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.
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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;
|