electron-version-deployer-cli 0.4.8 → 0.4.9
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 +45 -25
- package/dist/main.js +44 -24
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -406,27 +406,44 @@ async function netRequest(options) {
|
|
|
406
406
|
request.setHeader("Cache-Control", "no-cache");
|
|
407
407
|
let data = "";
|
|
408
408
|
let isResolved = false;
|
|
409
|
+
const failOnce = (error) => {
|
|
410
|
+
if (isResolved)
|
|
411
|
+
return;
|
|
412
|
+
isResolved = true;
|
|
413
|
+
cleanup();
|
|
414
|
+
reject(error);
|
|
415
|
+
};
|
|
409
416
|
const timeoutId = setTimeout(() => {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
request.abort();
|
|
413
|
-
reject(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
414
|
-
}
|
|
417
|
+
request.abort();
|
|
418
|
+
failOnce(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
415
419
|
}, TIMEOUT_MS);
|
|
416
420
|
const cleanup = () => {
|
|
417
421
|
clearTimeout(timeoutId);
|
|
418
422
|
};
|
|
419
423
|
request.on("response", (response) => {
|
|
424
|
+
const statusCode = response.statusCode ?? 0;
|
|
425
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
426
|
+
failOnce(
|
|
427
|
+
new Error(
|
|
428
|
+
`请求失败,状态码: ${statusCode} ${response.statusMessage ?? ""}`.trim()
|
|
429
|
+
)
|
|
430
|
+
);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
420
433
|
response.on("data", (chunk) => {
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
isResolved
|
|
424
|
-
|
|
425
|
-
|
|
434
|
+
try {
|
|
435
|
+
if (options.responseType === "stream") {
|
|
436
|
+
if (!isResolved) {
|
|
437
|
+
isResolved = true;
|
|
438
|
+
cleanup();
|
|
439
|
+
resolve(response);
|
|
440
|
+
}
|
|
441
|
+
return;
|
|
426
442
|
}
|
|
427
|
-
|
|
443
|
+
data += chunk;
|
|
444
|
+
} catch (error) {
|
|
445
|
+
failOnce(error);
|
|
428
446
|
}
|
|
429
|
-
data += chunk;
|
|
430
447
|
});
|
|
431
448
|
response.on("end", () => {
|
|
432
449
|
if (isResolved)
|
|
@@ -435,23 +452,26 @@ async function netRequest(options) {
|
|
|
435
452
|
cleanup();
|
|
436
453
|
if (options.responseType === "stream")
|
|
437
454
|
return;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
455
|
+
try {
|
|
456
|
+
if (options.responseType === "json") {
|
|
457
|
+
try {
|
|
458
|
+
resolve(JSON.parse(data));
|
|
459
|
+
} catch (e) {
|
|
460
|
+
resolve(null);
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
resolve(data);
|
|
443
464
|
}
|
|
444
|
-
}
|
|
445
|
-
|
|
465
|
+
} catch (error) {
|
|
466
|
+
failOnce(error);
|
|
446
467
|
}
|
|
447
468
|
});
|
|
469
|
+
response.on("error", (error) => {
|
|
470
|
+
failOnce(error);
|
|
471
|
+
});
|
|
448
472
|
});
|
|
449
473
|
request.on("error", (error) => {
|
|
450
|
-
|
|
451
|
-
isResolved = true;
|
|
452
|
-
cleanup();
|
|
453
|
-
reject(error);
|
|
454
|
-
}
|
|
474
|
+
failOnce(error);
|
|
455
475
|
});
|
|
456
476
|
request.end();
|
|
457
477
|
});
|
|
@@ -800,4 +820,4 @@ async function installPrebuilt(configs) {
|
|
|
800
820
|
}
|
|
801
821
|
commander.program.description(
|
|
802
822
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
803
|
-
).helpOption("-h, --help", "使用帮助").version("0.4.
|
|
823
|
+
).helpOption("-h, --help", "使用帮助").version("0.4.9", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.js
CHANGED
|
@@ -45,27 +45,44 @@ async function netRequest(options) {
|
|
|
45
45
|
request.setHeader("Cache-Control", "no-cache");
|
|
46
46
|
let data = "";
|
|
47
47
|
let isResolved = false;
|
|
48
|
+
const failOnce = (error) => {
|
|
49
|
+
if (isResolved)
|
|
50
|
+
return;
|
|
51
|
+
isResolved = true;
|
|
52
|
+
cleanup2();
|
|
53
|
+
reject(error);
|
|
54
|
+
};
|
|
48
55
|
const timeoutId = setTimeout(() => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
request.abort();
|
|
52
|
-
reject(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
53
|
-
}
|
|
56
|
+
request.abort();
|
|
57
|
+
failOnce(new Error("网络请求超时,请检查网络连接或使用 VPN 后重试"));
|
|
54
58
|
}, TIMEOUT_MS);
|
|
55
59
|
const cleanup2 = () => {
|
|
56
60
|
clearTimeout(timeoutId);
|
|
57
61
|
};
|
|
58
62
|
request.on("response", (response) => {
|
|
63
|
+
const statusCode = response.statusCode ?? 0;
|
|
64
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
65
|
+
failOnce(
|
|
66
|
+
new Error(
|
|
67
|
+
`请求失败,状态码: ${statusCode} ${response.statusMessage ?? ""}`.trim()
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
59
72
|
response.on("data", (chunk) => {
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
isResolved
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
try {
|
|
74
|
+
if (options.responseType === "stream") {
|
|
75
|
+
if (!isResolved) {
|
|
76
|
+
isResolved = true;
|
|
77
|
+
cleanup2();
|
|
78
|
+
resolve(response);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
65
81
|
}
|
|
66
|
-
|
|
82
|
+
data += chunk;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
failOnce(error);
|
|
67
85
|
}
|
|
68
|
-
data += chunk;
|
|
69
86
|
});
|
|
70
87
|
response.on("end", () => {
|
|
71
88
|
if (isResolved)
|
|
@@ -74,23 +91,26 @@ async function netRequest(options) {
|
|
|
74
91
|
cleanup2();
|
|
75
92
|
if (options.responseType === "stream")
|
|
76
93
|
return;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
try {
|
|
95
|
+
if (options.responseType === "json") {
|
|
96
|
+
try {
|
|
97
|
+
resolve(JSON.parse(data));
|
|
98
|
+
} catch (e) {
|
|
99
|
+
resolve(null);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
resolve(data);
|
|
82
103
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
104
|
+
} catch (error) {
|
|
105
|
+
failOnce(error);
|
|
85
106
|
}
|
|
86
107
|
});
|
|
108
|
+
response.on("error", (error) => {
|
|
109
|
+
failOnce(error);
|
|
110
|
+
});
|
|
87
111
|
});
|
|
88
112
|
request.on("error", (error) => {
|
|
89
|
-
|
|
90
|
-
isResolved = true;
|
|
91
|
-
cleanup2();
|
|
92
|
-
reject(error);
|
|
93
|
-
}
|
|
113
|
+
failOnce(error);
|
|
94
114
|
});
|
|
95
115
|
request.end();
|
|
96
116
|
});
|