electron-version-deployer-cli 0.3.3 → 0.3.4
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/dist/cli.cjs +27 -9
- package/dist/helpers/netRequest.d.ts +6 -0
- package/dist/main.js +54 -55
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -336,28 +336,46 @@ function genTmpFolder() {
|
|
|
336
336
|
if (!node_fs.existsSync(folderPath))
|
|
337
337
|
node_fs.mkdirSync(folderPath);
|
|
338
338
|
}
|
|
339
|
-
function
|
|
340
|
-
return new Promise((
|
|
341
|
-
const request = electron.net.request(
|
|
339
|
+
async function netRequest(options) {
|
|
340
|
+
return new Promise((resolve, reject) => {
|
|
341
|
+
const request = electron.net.request(options.url);
|
|
342
342
|
let data = "";
|
|
343
343
|
request.on("response", (response) => {
|
|
344
344
|
response.on("data", (chunk) => {
|
|
345
|
+
if (options.responseType === "stream") {
|
|
346
|
+
resolve(response);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
345
349
|
data += chunk;
|
|
346
350
|
});
|
|
347
351
|
response.on("end", () => {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
+
if (options.responseType === "stream")
|
|
353
|
+
return;
|
|
354
|
+
if (options.responseType === "json") {
|
|
355
|
+
try {
|
|
356
|
+
resolve(JSON.parse(data));
|
|
357
|
+
} catch (e) {
|
|
358
|
+
resolve(null);
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
resolve(data);
|
|
352
362
|
}
|
|
353
363
|
});
|
|
354
364
|
});
|
|
355
365
|
request.on("error", (error) => {
|
|
356
|
-
|
|
366
|
+
reject(error);
|
|
357
367
|
});
|
|
358
368
|
request.end();
|
|
359
369
|
});
|
|
360
370
|
}
|
|
371
|
+
function fetchRemotePkgJSON(remote_url) {
|
|
372
|
+
return netRequest({
|
|
373
|
+
url: `${remote_url}/package.json`,
|
|
374
|
+
responseType: "json"
|
|
375
|
+
}).catch((error) => {
|
|
376
|
+
throw new Error(`自动更新检查请求失败: ${error}`);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
361
379
|
function versionToNum(a) {
|
|
362
380
|
let c = a.split(".");
|
|
363
381
|
let num_place = ["", "0", "00", "000", "0000"], r2 = num_place.reverse();
|
|
@@ -666,4 +684,4 @@ async function installPrebuilt(configs) {
|
|
|
666
684
|
}
|
|
667
685
|
commander.program.description(
|
|
668
686
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
669
|
-
).helpOption("-h, --help", "使用帮助").version("0.3.
|
|
687
|
+
).helpOption("-h, --help", "使用帮助").version("0.3.4", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.js
CHANGED
|
@@ -8,48 +8,52 @@ const node_process = require("node:process");
|
|
|
8
8
|
const fs = require("fs");
|
|
9
9
|
const path = require("path");
|
|
10
10
|
const extract = require("extract-zip");
|
|
11
|
-
function
|
|
12
|
-
return new Promise((
|
|
13
|
-
const request = electron.net.request(
|
|
11
|
+
async function netRequest(options) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const request = electron.net.request(options.url);
|
|
14
14
|
let data = "";
|
|
15
15
|
request.on("response", (response) => {
|
|
16
16
|
response.on("data", (chunk) => {
|
|
17
|
+
if (options.responseType === "stream") {
|
|
18
|
+
resolve(response);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
17
21
|
data += chunk;
|
|
18
22
|
});
|
|
19
23
|
response.on("end", () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
if (options.responseType === "stream")
|
|
25
|
+
return;
|
|
26
|
+
if (options.responseType === "json") {
|
|
27
|
+
try {
|
|
28
|
+
resolve(JSON.parse(data));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
resolve(null);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
resolve(data);
|
|
24
34
|
}
|
|
25
35
|
});
|
|
26
36
|
});
|
|
27
37
|
request.on("error", (error) => {
|
|
28
|
-
|
|
38
|
+
reject(error);
|
|
29
39
|
});
|
|
30
40
|
request.end();
|
|
31
41
|
});
|
|
32
42
|
}
|
|
43
|
+
function fetchRemoteChangelogJSON(remote_url) {
|
|
44
|
+
return netRequest({
|
|
45
|
+
url: `${remote_url}/changelog.json`,
|
|
46
|
+
responseType: "json"
|
|
47
|
+
}).catch((error) => {
|
|
48
|
+
throw new Error(`获取 changelog.json 失败: ${error}`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
33
51
|
function fetchRemotePkgJSON(remote_url) {
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
data += chunk;
|
|
40
|
-
});
|
|
41
|
-
response.on("end", () => {
|
|
42
|
-
try {
|
|
43
|
-
res(JSON.parse(data));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
res(null);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
request.on("error", (error) => {
|
|
50
|
-
rej(`自动更新检查请求失败:` + error.toString());
|
|
51
|
-
});
|
|
52
|
-
request.end();
|
|
52
|
+
return netRequest({
|
|
53
|
+
url: `${remote_url}/package.json`,
|
|
54
|
+
responseType: "json"
|
|
55
|
+
}).catch((error) => {
|
|
56
|
+
throw new Error(`自动更新检查请求失败: ${error}`);
|
|
53
57
|
});
|
|
54
58
|
}
|
|
55
59
|
function versionToNum(a) {
|
|
@@ -249,10 +253,10 @@ async function installPkg(zipFile) {
|
|
|
249
253
|
await new Promise(async (res, rej) => {
|
|
250
254
|
let fullCodeSplitIndexFile = false;
|
|
251
255
|
try {
|
|
252
|
-
|
|
253
|
-
`${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
+
fullCodeSplitIndexFile = await netRequest({
|
|
257
|
+
url: `${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`,
|
|
258
|
+
responseType: "json"
|
|
259
|
+
});
|
|
256
260
|
} catch (e) {
|
|
257
261
|
}
|
|
258
262
|
if (zipFile === "fullCode.zip" && fullCodeSplitIndexFile) {
|
|
@@ -260,25 +264,21 @@ async function installPkg(zipFile) {
|
|
|
260
264
|
for (let fileName of fullCodeSplitIndexFile) {
|
|
261
265
|
const tmpFilePath = node_path.join(appPath, fileName);
|
|
262
266
|
const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
const response = await netRequest({
|
|
268
|
+
url: `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`,
|
|
269
|
+
responseType: "stream"
|
|
270
|
+
});
|
|
271
|
+
await new Promise((streamRes, streamRej) => {
|
|
272
|
+
response.on("data", (chunk) => {
|
|
273
|
+
tmpSplitZip.write(chunk);
|
|
266
274
|
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
response.on("end", () => {
|
|
272
|
-
tmpSplitZip.end(() => {
|
|
273
|
-
mergedStream.write(node_fs.readFileSync(tmpFilePath));
|
|
274
|
-
_res();
|
|
275
|
-
});
|
|
275
|
+
response.on("end", () => {
|
|
276
|
+
tmpSplitZip.end(() => {
|
|
277
|
+
mergedStream.write(node_fs.readFileSync(tmpFilePath));
|
|
278
|
+
streamRes();
|
|
276
279
|
});
|
|
277
280
|
});
|
|
278
|
-
|
|
279
|
-
_rej(error);
|
|
280
|
-
});
|
|
281
|
-
request.end();
|
|
281
|
+
response.on("error", streamRej);
|
|
282
282
|
});
|
|
283
283
|
forceDeleteSync(tmpFilePath);
|
|
284
284
|
}
|
|
@@ -287,23 +287,22 @@ async function installPkg(zipFile) {
|
|
|
287
287
|
});
|
|
288
288
|
} else {
|
|
289
289
|
const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
|
|
290
|
-
const
|
|
291
|
-
url: `${remoteUrl}/${zipFile}?hash=${Math.random()}
|
|
290
|
+
const response = await netRequest({
|
|
291
|
+
url: `${remoteUrl}/${zipFile}?hash=${Math.random()}`,
|
|
292
|
+
responseType: "stream"
|
|
292
293
|
});
|
|
293
|
-
|
|
294
|
+
await new Promise((streamRes, streamRej) => {
|
|
294
295
|
response.on("data", (chunk) => {
|
|
295
296
|
tmpZipFilePath.write(chunk);
|
|
296
297
|
});
|
|
297
298
|
response.on("end", () => {
|
|
298
299
|
tmpZipFilePath.end(() => {
|
|
299
|
-
|
|
300
|
+
streamRes();
|
|
300
301
|
});
|
|
301
302
|
});
|
|
303
|
+
response.on("error", streamRej);
|
|
302
304
|
});
|
|
303
|
-
|
|
304
|
-
rej(error);
|
|
305
|
-
});
|
|
306
|
-
request.end();
|
|
305
|
+
res();
|
|
307
306
|
}
|
|
308
307
|
});
|
|
309
308
|
await extract(unzipPath + ".zip", { dir: unzipPath });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-version-deployer-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
7
7
|
"module": "./dist/index.es.js",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"commander": "^10.0.1",
|
|
26
26
|
"dompurify": "^3.0.3",
|
|
27
27
|
"download": "^8.0.0",
|
|
28
|
-
"electron": "^25.0.1",
|
|
29
28
|
"esno": "^0.16.3",
|
|
30
29
|
"jsdom": "^22.1.0",
|
|
31
30
|
"log-symbols": "=4.1.0",
|
|
@@ -38,6 +37,7 @@
|
|
|
38
37
|
"wrangler": "^3.3.0"
|
|
39
38
|
},
|
|
40
39
|
"dependencies": {
|
|
40
|
+
"electron": "^25.3.2",
|
|
41
41
|
"archiver": "^5.3.1",
|
|
42
42
|
"extract-zip": "^2.0.1",
|
|
43
43
|
"pkg-up": "3.1.0"
|