electron-version-deployer-cli 0.3.3 → 0.3.5

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 CHANGED
@@ -336,28 +336,60 @@ function genTmpFolder() {
336
336
  if (!node_fs.existsSync(folderPath))
337
337
  node_fs.mkdirSync(folderPath);
338
338
  }
339
- function fetchRemotePkgJSON(remote_url) {
340
- return new Promise((res, rej) => {
341
- const request = electron.net.request(`${remote_url}/package.json`);
339
+ async function netRequest(options) {
340
+ if (!electron.net) {
341
+ const response = await fetch(options.url);
342
+ if (options.responseType === "json") {
343
+ try {
344
+ return await response.json();
345
+ } catch (e) {
346
+ return null;
347
+ }
348
+ } else if (options.responseType === "stream") {
349
+ return response.body;
350
+ } else {
351
+ return await response.text();
352
+ }
353
+ }
354
+ return new Promise((resolve, reject) => {
355
+ const request = electron.net.request(options.url);
342
356
  let data = "";
343
357
  request.on("response", (response) => {
344
358
  response.on("data", (chunk) => {
359
+ if (options.responseType === "stream") {
360
+ resolve(response);
361
+ return;
362
+ }
345
363
  data += chunk;
346
364
  });
347
365
  response.on("end", () => {
348
- try {
349
- res(JSON.parse(data));
350
- } catch (e) {
351
- res(null);
366
+ if (options.responseType === "stream")
367
+ return;
368
+ if (options.responseType === "json") {
369
+ try {
370
+ resolve(JSON.parse(data));
371
+ } catch (e) {
372
+ resolve(null);
373
+ }
374
+ } else {
375
+ resolve(data);
352
376
  }
353
377
  });
354
378
  });
355
379
  request.on("error", (error) => {
356
- rej(`自动更新检查请求失败:` + error.toString());
380
+ reject(error);
357
381
  });
358
382
  request.end();
359
383
  });
360
384
  }
385
+ function fetchRemotePkgJSON(remote_url) {
386
+ return netRequest({
387
+ url: `${remote_url}/package.json`,
388
+ responseType: "json"
389
+ }).catch((error) => {
390
+ throw new Error(`自动更新检查请求失败: ${error}`);
391
+ });
392
+ }
361
393
  function versionToNum(a) {
362
394
  let c = a.split(".");
363
395
  let num_place = ["", "0", "00", "000", "0000"], r2 = num_place.reverse();
@@ -666,4 +698,4 @@ async function installPrebuilt(configs) {
666
698
  }
667
699
  commander.program.description(
668
700
  "Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
669
- ).helpOption("-h, --help", "使用帮助").version("0.3.3", "-V, --version", "显示版本号").parse(process.argv);
701
+ ).helpOption("-h, --help", "使用帮助").version("0.3.5", "-V, --version", "显示版本号").parse(process.argv);
@@ -0,0 +1,6 @@
1
+ interface RequestOptions {
2
+ url: string;
3
+ responseType?: 'json' | 'stream' | 'text';
4
+ }
5
+ export declare function netRequest<T = any>(options: RequestOptions): Promise<T>;
6
+ export {};
package/dist/main.js CHANGED
@@ -8,48 +8,66 @@ 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 fetchRemoteChangelogJSON(remote_url) {
12
- return new Promise((res, rej) => {
13
- const request = electron.net.request(`${remote_url}/changelog.json`);
11
+ async function netRequest(options) {
12
+ if (!electron.net) {
13
+ const response = await fetch(options.url);
14
+ if (options.responseType === "json") {
15
+ try {
16
+ return await response.json();
17
+ } catch (e) {
18
+ return null;
19
+ }
20
+ } else if (options.responseType === "stream") {
21
+ return response.body;
22
+ } else {
23
+ return await response.text();
24
+ }
25
+ }
26
+ return new Promise((resolve, reject) => {
27
+ const request = electron.net.request(options.url);
14
28
  let data = "";
15
29
  request.on("response", (response) => {
16
30
  response.on("data", (chunk) => {
31
+ if (options.responseType === "stream") {
32
+ resolve(response);
33
+ return;
34
+ }
17
35
  data += chunk;
18
36
  });
19
37
  response.on("end", () => {
20
- try {
21
- res(JSON.parse(data));
22
- } catch (e) {
23
- res(null);
38
+ if (options.responseType === "stream")
39
+ return;
40
+ if (options.responseType === "json") {
41
+ try {
42
+ resolve(JSON.parse(data));
43
+ } catch (e) {
44
+ resolve(null);
45
+ }
46
+ } else {
47
+ resolve(data);
24
48
  }
25
49
  });
26
50
  });
27
51
  request.on("error", (error) => {
28
- rej(`获取 changelog.json 失败:` + error.toString());
52
+ reject(error);
29
53
  });
30
54
  request.end();
31
55
  });
32
56
  }
57
+ function fetchRemoteChangelogJSON(remote_url) {
58
+ return netRequest({
59
+ url: `${remote_url}/changelog.json`,
60
+ responseType: "json"
61
+ }).catch((error) => {
62
+ throw new Error(`获取 changelog.json 失败: ${error}`);
63
+ });
64
+ }
33
65
  function fetchRemotePkgJSON(remote_url) {
34
- return new Promise((res, rej) => {
35
- const request = electron.net.request(`${remote_url}/package.json`);
36
- let data = "";
37
- request.on("response", (response) => {
38
- response.on("data", (chunk) => {
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();
66
+ return netRequest({
67
+ url: `${remote_url}/package.json`,
68
+ responseType: "json"
69
+ }).catch((error) => {
70
+ throw new Error(`自动更新检查请求失败: ${error}`);
53
71
  });
54
72
  }
55
73
  function versionToNum(a) {
@@ -249,10 +267,10 @@ async function installPkg(zipFile) {
249
267
  await new Promise(async (res, rej) => {
250
268
  let fullCodeSplitIndexFile = false;
251
269
  try {
252
- const request = await fetch(
253
- `${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`
254
- );
255
- fullCodeSplitIndexFile = await request.json();
270
+ fullCodeSplitIndexFile = await netRequest({
271
+ url: `${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`,
272
+ responseType: "json"
273
+ });
256
274
  } catch (e) {
257
275
  }
258
276
  if (zipFile === "fullCode.zip" && fullCodeSplitIndexFile) {
@@ -260,25 +278,21 @@ async function installPkg(zipFile) {
260
278
  for (let fileName of fullCodeSplitIndexFile) {
261
279
  const tmpFilePath = node_path.join(appPath, fileName);
262
280
  const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
263
- await new Promise((_res, _rej) => {
264
- const request = electron.net.request({
265
- url: `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`
281
+ const response = await netRequest({
282
+ url: `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`,
283
+ responseType: "stream"
284
+ });
285
+ await new Promise((streamRes, streamRej) => {
286
+ response.on("data", (chunk) => {
287
+ tmpSplitZip.write(chunk);
266
288
  });
267
- request.on("response", (response) => {
268
- response.on("data", (chunk) => {
269
- tmpSplitZip.write(chunk);
289
+ response.on("end", () => {
290
+ tmpSplitZip.end(() => {
291
+ mergedStream.write(node_fs.readFileSync(tmpFilePath));
292
+ streamRes();
270
293
  });
271
- response.on("end", () => {
272
- tmpSplitZip.end(() => {
273
- mergedStream.write(node_fs.readFileSync(tmpFilePath));
274
- _res();
275
- });
276
- });
277
- });
278
- request.on("error", (error) => {
279
- _rej(error);
280
294
  });
281
- request.end();
295
+ response.on("error", streamRej);
282
296
  });
283
297
  forceDeleteSync(tmpFilePath);
284
298
  }
@@ -287,23 +301,22 @@ async function installPkg(zipFile) {
287
301
  });
288
302
  } else {
289
303
  const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
290
- const request = electron.net.request({
291
- url: `${remoteUrl}/${zipFile}?hash=${Math.random()}`
304
+ const response = await netRequest({
305
+ url: `${remoteUrl}/${zipFile}?hash=${Math.random()}`,
306
+ responseType: "stream"
292
307
  });
293
- request.on("response", (response) => {
308
+ await new Promise((streamRes, streamRej) => {
294
309
  response.on("data", (chunk) => {
295
310
  tmpZipFilePath.write(chunk);
296
311
  });
297
312
  response.on("end", () => {
298
313
  tmpZipFilePath.end(() => {
299
- res();
314
+ streamRes();
300
315
  });
301
316
  });
317
+ response.on("error", streamRej);
302
318
  });
303
- request.on("error", (error) => {
304
- rej(error);
305
- });
306
- request.end();
319
+ res();
307
320
  }
308
321
  });
309
322
  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.3",
4
+ "version": "0.3.5",
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"