electron-version-deployer-cli 0.4.4 → 0.4.6
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 +52 -13
- package/dist/main.js +51 -12
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -369,33 +369,68 @@ function genTmpFolder() {
|
|
|
369
369
|
if (!node_fs.existsSync(folderPath))
|
|
370
370
|
node_fs.mkdirSync(folderPath);
|
|
371
371
|
}
|
|
372
|
+
const TIMEOUT_MS = 5e3;
|
|
372
373
|
async function netRequest(options) {
|
|
373
374
|
if (!electron.net) {
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
375
|
+
const abortController = new AbortController();
|
|
376
|
+
const timeoutId = setTimeout(() => {
|
|
377
|
+
abortController.abort();
|
|
378
|
+
}, TIMEOUT_MS);
|
|
379
|
+
try {
|
|
380
|
+
const response = await fetch(options.url, {
|
|
381
|
+
signal: abortController.signal
|
|
382
|
+
});
|
|
383
|
+
clearTimeout(timeoutId);
|
|
384
|
+
if (options.responseType === "json") {
|
|
385
|
+
try {
|
|
386
|
+
return await response.json();
|
|
387
|
+
} catch (e) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
} else if (options.responseType === "stream") {
|
|
391
|
+
return response.body;
|
|
392
|
+
} else {
|
|
393
|
+
return await response.text();
|
|
380
394
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
395
|
+
} catch (error) {
|
|
396
|
+
clearTimeout(timeoutId);
|
|
397
|
+
if (error.name === "AbortError") {
|
|
398
|
+
throw new Error("网络请求超时,请检查网络连接或使用 VPN 后重试");
|
|
399
|
+
}
|
|
400
|
+
throw error;
|
|
385
401
|
}
|
|
386
402
|
}
|
|
387
403
|
return new Promise((resolve, reject) => {
|
|
388
404
|
const request = electron.net.request(options.url);
|
|
389
405
|
let data = "";
|
|
406
|
+
let isResolved = false;
|
|
407
|
+
const timeoutId = setTimeout(() => {
|
|
408
|
+
if (!isResolved) {
|
|
409
|
+
isResolved = true;
|
|
410
|
+
request.abort();
|
|
411
|
+
reject(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
412
|
+
}
|
|
413
|
+
}, TIMEOUT_MS);
|
|
414
|
+
const cleanup = () => {
|
|
415
|
+
clearTimeout(timeoutId);
|
|
416
|
+
};
|
|
390
417
|
request.on("response", (response) => {
|
|
391
418
|
response.on("data", (chunk) => {
|
|
392
419
|
if (options.responseType === "stream") {
|
|
393
|
-
|
|
420
|
+
if (!isResolved) {
|
|
421
|
+
isResolved = true;
|
|
422
|
+
cleanup();
|
|
423
|
+
resolve(response);
|
|
424
|
+
}
|
|
394
425
|
return;
|
|
395
426
|
}
|
|
396
427
|
data += chunk;
|
|
397
428
|
});
|
|
398
429
|
response.on("end", () => {
|
|
430
|
+
if (isResolved)
|
|
431
|
+
return;
|
|
432
|
+
isResolved = true;
|
|
433
|
+
cleanup();
|
|
399
434
|
if (options.responseType === "stream")
|
|
400
435
|
return;
|
|
401
436
|
if (options.responseType === "json") {
|
|
@@ -410,7 +445,11 @@ async function netRequest(options) {
|
|
|
410
445
|
});
|
|
411
446
|
});
|
|
412
447
|
request.on("error", (error) => {
|
|
413
|
-
|
|
448
|
+
if (!isResolved) {
|
|
449
|
+
isResolved = true;
|
|
450
|
+
cleanup();
|
|
451
|
+
reject(error);
|
|
452
|
+
}
|
|
414
453
|
});
|
|
415
454
|
request.end();
|
|
416
455
|
});
|
|
@@ -759,4 +798,4 @@ async function installPrebuilt(configs) {
|
|
|
759
798
|
}
|
|
760
799
|
commander.program.description(
|
|
761
800
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
762
|
-
).helpOption("-h, --help", "使用帮助").version("0.4.
|
|
801
|
+
).helpOption("-h, --help", "使用帮助").version("0.4.6", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.js
CHANGED
|
@@ -8,33 +8,68 @@ 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
|
+
const TIMEOUT_MS = 5e3;
|
|
11
12
|
async function netRequest(options) {
|
|
12
13
|
if (!electron.net) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const abortController = new AbortController();
|
|
15
|
+
const timeoutId = setTimeout(() => {
|
|
16
|
+
abortController.abort();
|
|
17
|
+
}, TIMEOUT_MS);
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(options.url, {
|
|
20
|
+
signal: abortController.signal
|
|
21
|
+
});
|
|
22
|
+
clearTimeout(timeoutId);
|
|
23
|
+
if (options.responseType === "json") {
|
|
24
|
+
try {
|
|
25
|
+
return await response.json();
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
} else if (options.responseType === "stream") {
|
|
30
|
+
return response.body;
|
|
31
|
+
} else {
|
|
32
|
+
return await response.text();
|
|
19
33
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
} catch (error) {
|
|
35
|
+
clearTimeout(timeoutId);
|
|
36
|
+
if (error.name === "AbortError") {
|
|
37
|
+
throw new Error("网络请求超时,请检查网络连接或使用 VPN 后重试");
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
42
|
return new Promise((resolve, reject) => {
|
|
27
43
|
const request = electron.net.request(options.url);
|
|
28
44
|
let data = "";
|
|
45
|
+
let isResolved = false;
|
|
46
|
+
const timeoutId = setTimeout(() => {
|
|
47
|
+
if (!isResolved) {
|
|
48
|
+
isResolved = true;
|
|
49
|
+
request.abort();
|
|
50
|
+
reject(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
51
|
+
}
|
|
52
|
+
}, TIMEOUT_MS);
|
|
53
|
+
const cleanup2 = () => {
|
|
54
|
+
clearTimeout(timeoutId);
|
|
55
|
+
};
|
|
29
56
|
request.on("response", (response) => {
|
|
30
57
|
response.on("data", (chunk) => {
|
|
31
58
|
if (options.responseType === "stream") {
|
|
32
|
-
|
|
59
|
+
if (!isResolved) {
|
|
60
|
+
isResolved = true;
|
|
61
|
+
cleanup2();
|
|
62
|
+
resolve(response);
|
|
63
|
+
}
|
|
33
64
|
return;
|
|
34
65
|
}
|
|
35
66
|
data += chunk;
|
|
36
67
|
});
|
|
37
68
|
response.on("end", () => {
|
|
69
|
+
if (isResolved)
|
|
70
|
+
return;
|
|
71
|
+
isResolved = true;
|
|
72
|
+
cleanup2();
|
|
38
73
|
if (options.responseType === "stream")
|
|
39
74
|
return;
|
|
40
75
|
if (options.responseType === "json") {
|
|
@@ -49,7 +84,11 @@ async function netRequest(options) {
|
|
|
49
84
|
});
|
|
50
85
|
});
|
|
51
86
|
request.on("error", (error) => {
|
|
52
|
-
|
|
87
|
+
if (!isResolved) {
|
|
88
|
+
isResolved = true;
|
|
89
|
+
cleanup2();
|
|
90
|
+
reject(error);
|
|
91
|
+
}
|
|
53
92
|
});
|
|
54
93
|
request.end();
|
|
55
94
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-version-deployer-cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.6",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
7
7
|
"module": "./dist/index.es.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@inquirer/prompts": "^1.2.3",
|
|
22
|
-
"@types/archiver": "^
|
|
22
|
+
"@types/archiver": "^7.0.0",
|
|
23
23
|
"@types/node": "^20.2.5",
|
|
24
24
|
"changelog-parser": "^3.0.1",
|
|
25
25
|
"commander": "^10.0.1",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"electron": "^25.3.2"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"archiver": "^
|
|
41
|
+
"archiver": "^7.0.1",
|
|
42
42
|
"extract-zip": "^2.0.1",
|
|
43
43
|
"pkg-up": "3.1.0"
|
|
44
44
|
},
|