electron-version-deployer-cli 0.3.2 → 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 CHANGED
@@ -20,7 +20,7 @@ const jsdom = require("jsdom");
20
20
  const DOMPurify = require("dompurify");
21
21
  const archiver = require("archiver");
22
22
  const prompts = require("@inquirer/prompts");
23
- const node_https = require("node:https");
23
+ const electron = require("electron");
24
24
  const node_os = require("node:os");
25
25
  const fs = require("fs");
26
26
  const path = require("path");
@@ -336,23 +336,44 @@ 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
- node_https.get(`${remote_url}/package.json`, (_res) => {
342
- let data = "";
343
- _res.on("data", (chunk) => {
339
+ async function netRequest(options) {
340
+ return new Promise((resolve, reject) => {
341
+ const request = electron.net.request(options.url);
342
+ let data = "";
343
+ request.on("response", (response) => {
344
+ response.on("data", (chunk) => {
345
+ if (options.responseType === "stream") {
346
+ resolve(response);
347
+ return;
348
+ }
344
349
  data += chunk;
345
350
  });
346
- _res.on("end", () => {
347
- try {
348
- res(JSON.parse(data));
349
- } catch (e) {
350
- res(null);
351
+ response.on("end", () => {
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);
351
362
  }
352
363
  });
353
- }).on("error", (err) => {
354
- rej(`自动更新检查请求失败:` + err.toString());
355
364
  });
365
+ request.on("error", (error) => {
366
+ reject(error);
367
+ });
368
+ request.end();
369
+ });
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}`);
356
377
  });
357
378
  }
358
379
  function versionToNum(a) {
@@ -663,4 +684,4 @@ async function installPrebuilt(configs) {
663
684
  }
664
685
  commander.program.description(
665
686
  "Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
666
- ).helpOption("-h, --help", "使用帮助").version("0.3.2", "-V, --version", "显示版本号").parse(process.argv);
687
+ ).helpOption("-h, --help", "使用帮助").version("0.3.4", "-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
@@ -3,48 +3,57 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const electron = require("electron");
4
4
  const node_url = require("node:url");
5
5
  const node_path = require("node:path");
6
- const node_https = require("node:https");
7
6
  const node_fs = require("node:fs");
8
- const extract = require("extract-zip");
9
7
  const node_process = require("node:process");
10
8
  const fs = require("fs");
11
9
  const path = require("path");
12
- function fetchRemoteChangelogJSON(remote_url) {
13
- return new Promise((res, rej) => {
14
- node_https.get(`${remote_url}/changelog.json`, (_res) => {
15
- let data = "";
16
- _res.on("data", (chunk) => {
10
+ const extract = require("extract-zip");
11
+ async function netRequest(options) {
12
+ return new Promise((resolve, reject) => {
13
+ const request = electron.net.request(options.url);
14
+ let data = "";
15
+ request.on("response", (response) => {
16
+ response.on("data", (chunk) => {
17
+ if (options.responseType === "stream") {
18
+ resolve(response);
19
+ return;
20
+ }
17
21
  data += chunk;
18
22
  });
19
- _res.on("end", () => {
20
- try {
21
- res(JSON.parse(data));
22
- } catch (e) {
23
- res(null);
23
+ response.on("end", () => {
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
- }).on("error", (err) => {
27
- rej(`获取 changelog.json 失败:` + err.toString());
28
36
  });
37
+ request.on("error", (error) => {
38
+ reject(error);
39
+ });
40
+ request.end();
41
+ });
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}`);
29
49
  });
30
50
  }
31
51
  function fetchRemotePkgJSON(remote_url) {
32
- return new Promise((res, rej) => {
33
- node_https.get(`${remote_url}/package.json`, (_res) => {
34
- let data = "";
35
- _res.on("data", (chunk) => {
36
- data += chunk;
37
- });
38
- _res.on("end", () => {
39
- try {
40
- res(JSON.parse(data));
41
- } catch (e) {
42
- res(null);
43
- }
44
- });
45
- }).on("error", (err) => {
46
- rej(`自动更新检查请求失败:` + err.toString());
47
- });
52
+ return netRequest({
53
+ url: `${remote_url}/package.json`,
54
+ responseType: "json"
55
+ }).catch((error) => {
56
+ throw new Error(`自动更新检查请求失败: ${error}`);
48
57
  });
49
58
  }
50
59
  function versionToNum(a) {
@@ -244,10 +253,10 @@ async function installPkg(zipFile) {
244
253
  await new Promise(async (res, rej) => {
245
254
  let fullCodeSplitIndexFile = false;
246
255
  try {
247
- const request = await fetch(
248
- `${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`
249
- );
250
- fullCodeSplitIndexFile = await request.json();
256
+ fullCodeSplitIndexFile = await netRequest({
257
+ url: `${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`,
258
+ responseType: "json"
259
+ });
251
260
  } catch (e) {
252
261
  }
253
262
  if (zipFile === "fullCode.zip" && fullCodeSplitIndexFile) {
@@ -255,22 +264,21 @@ async function installPkg(zipFile) {
255
264
  for (let fileName of fullCodeSplitIndexFile) {
256
265
  const tmpFilePath = node_path.join(appPath, fileName);
257
266
  const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
258
- await new Promise((_res) => {
259
- node_https.get(
260
- `${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`,
261
- (response) => {
262
- response.pipe(tmpSplitZip).on("finish", () => {
263
- tmpSplitZip.end(() => {
264
- mergedStream.write(node_fs.readFileSync(tmpFilePath));
265
- _res();
266
- });
267
- }).on("error", (err) => {
268
- rej(err);
269
- });
270
- }
271
- ).on("error", (err) => {
272
- rej(err);
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);
273
274
  });
275
+ response.on("end", () => {
276
+ tmpSplitZip.end(() => {
277
+ mergedStream.write(node_fs.readFileSync(tmpFilePath));
278
+ streamRes();
279
+ });
280
+ });
281
+ response.on("error", streamRej);
274
282
  });
275
283
  forceDeleteSync(tmpFilePath);
276
284
  }
@@ -279,17 +287,22 @@ async function installPkg(zipFile) {
279
287
  });
280
288
  } else {
281
289
  const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
282
- node_https.get(`${remoteUrl}/${zipFile}?hash=${Math.random()}`, (response) => {
283
- response.pipe(tmpZipFilePath).on("finish", () => {
290
+ const response = await netRequest({
291
+ url: `${remoteUrl}/${zipFile}?hash=${Math.random()}`,
292
+ responseType: "stream"
293
+ });
294
+ await new Promise((streamRes, streamRej) => {
295
+ response.on("data", (chunk) => {
296
+ tmpZipFilePath.write(chunk);
297
+ });
298
+ response.on("end", () => {
284
299
  tmpZipFilePath.end(() => {
285
- res();
300
+ streamRes();
286
301
  });
287
- }).on("error", (err) => {
288
- rej(err);
289
302
  });
290
- }).on("error", (err) => {
291
- rej(err);
303
+ response.on("error", streamRej);
292
304
  });
305
+ res();
293
306
  }
294
307
  });
295
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.2",
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"