electron-version-deployer-cli 0.0.18 → 0.1.0

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
@@ -1,10 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => {
6
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ return value;
8
+ };
3
9
  const commander = require("commander");
4
10
  const pkgUp = require("pkg-up");
5
11
  const node_fs = require("node:fs");
6
12
  const logSymbols = require("log-symbols");
7
- const prompts = require("@inquirer/prompts");
8
13
  const node_path = require("node:path");
9
14
  const vite = require("vite");
10
15
  const vm = require("node:vm");
@@ -14,6 +19,7 @@ const marked = require("marked");
14
19
  const jsdom = require("jsdom");
15
20
  const DOMPurify = require("dompurify");
16
21
  const archiver = require("archiver");
22
+ const prompts = require("@inquirer/prompts");
17
23
  const node_https = require("node:https");
18
24
  const node_os = require("node:os");
19
25
  const download = require("download");
@@ -36,7 +42,7 @@ function formatBytes(bytes) {
36
42
  }
37
43
  const CLI_NAME = "electron-version-deployer-cli";
38
44
  const CONFIG_FILE_NAME = "evd.config.js";
39
- commander.program.command("init").option("-y", "自动确认初始化", false).description("生成配置文件").action(async (source, destination) => {
45
+ commander.program.command("init").description("生成配置文件").action(async (source, destination) => {
40
46
  const pkgPath2 = pkgUp.sync();
41
47
  if (!pkgPath2)
42
48
  return console.log(
@@ -59,58 +65,13 @@ commander.program.command("init").option("-y", "自动确认初始化", false).d
59
65
  token: "",
60
66
  siteID: ""
61
67
  },
68
+ cloudflare: {
69
+ url: "",
70
+ token: "",
71
+ projectName: ""
72
+ },
62
73
  prebuiltConfig: {}
63
74
  };
64
- if (!source.y) {
65
- defaultConfig.compileCommand = await prompts.input({
66
- message: "请输入编译命令",
67
- default: defaultConfig.compileCommand
68
- // validate(str) {
69
- // const scripts = pkgContent.scripts ?? {};
70
- // return Promise.resolve(
71
- // scripts[str] ? true : `无法在 package.json 中找到该命令!`
72
- // );
73
- // },
74
- });
75
- defaultConfig.changelogsPath = await prompts.input({
76
- message: "请输入 changelogs 文件位置(以项目根目录为准的相对路径)",
77
- default: defaultConfig.changelogsPath
78
- // validate(str) {
79
- // return Promise.resolve(
80
- // existsSync(r(str))
81
- // ? /\.md$/.test(str)
82
- // ? true
83
- // : "该文件必须是以 .md 结尾的 Markdown 文件"
84
- // : "该文件不存在!"
85
- // );
86
- // },
87
- });
88
- defaultConfig.sources.folder = await prompts.input({
89
- message: "请输入源文件目录",
90
- default: `dist/mac-arm64/myapp.app/Resources/app`
91
- });
92
- defaultConfig.sources.nodeModules = await prompts.input({
93
- message: "请输入源文件 node_modules 目录",
94
- default: defaultConfig.sources.nodeModules
95
- });
96
- defaultConfig.sources.codes = await prompts.input({
97
- message: "请输入源文件 逻辑代码目录",
98
- default: defaultConfig.sources.codes
99
- });
100
- defaultConfig.sources.packageJSON = await prompts.input({
101
- message: "请输入源文件 package.json 路径",
102
- default: defaultConfig.sources.packageJSON
103
- });
104
- defaultConfig.netlify.url = await prompts.input({
105
- message: "请输入 Netlify 网站域名"
106
- });
107
- defaultConfig.netlify.token = await prompts.input({
108
- message: "请输入 Netlify Token"
109
- });
110
- defaultConfig.netlify.siteID = await prompts.input({
111
- message: "请输入 Netlify SiteID"
112
- });
113
- }
114
75
  let evdConfigContent = node_fs.readFileSync(
115
76
  node_path.join(node_path.resolve(__dirname), "templates", "evd.config.ts"),
116
77
  "utf-8"
@@ -379,6 +340,120 @@ function versionToNum(a) {
379
340
  let res = c.join("");
380
341
  return res;
381
342
  }
343
+ const _Netlify = class {
344
+ static get instance() {
345
+ if (!this._instance) {
346
+ this._instance = new _Netlify();
347
+ }
348
+ return this._instance;
349
+ }
350
+ getUrl(configs) {
351
+ var _a;
352
+ return (_a = configs.netlify) == null ? void 0 : _a.url;
353
+ }
354
+ deploy(props) {
355
+ const netlifyConfig = props.configs.netlify;
356
+ if (!netlifyConfig)
357
+ throw new Error("netlify 配置为空");
358
+ return new Promise((res) => {
359
+ const cmd = node_os.platform() === "win32" ? "netlify.cmd" : "netlify";
360
+ const output = node_child_process.spawn(cmd, [
361
+ "deploy",
362
+ "--dir",
363
+ props.folder,
364
+ "--site",
365
+ netlifyConfig.siteID,
366
+ "--auth",
367
+ netlifyConfig.token,
368
+ "--prod",
369
+ "--debug"
370
+ ], {
371
+ stdio: ["pipe", "inherit", "inherit"]
372
+ });
373
+ output.on("exit", function(code) {
374
+ if (code === 0) {
375
+ console.log(logSymbols.success, "部署完成!");
376
+ res();
377
+ return;
378
+ }
379
+ throw new Error("部署失败!");
380
+ });
381
+ });
382
+ }
383
+ validateConfig(configs) {
384
+ if (configs.netlify) {
385
+ if (!configs.netlify.url || !/^https/.test(configs.netlify.url)) {
386
+ return `configs.netlify.url 配置不正确`;
387
+ }
388
+ if (!configs.netlify.token) {
389
+ return `configs.netlify.token 未配置`;
390
+ }
391
+ if (!configs.netlify.siteID) {
392
+ return `configs.netlify.siteID 未配置`;
393
+ }
394
+ }
395
+ return `configs.netlify 配置不存在`;
396
+ }
397
+ };
398
+ let Netlify = _Netlify;
399
+ __publicField(Netlify, "_instance");
400
+ const _Cloudflare = class {
401
+ static get instance() {
402
+ if (!this._instance) {
403
+ this._instance = new _Cloudflare();
404
+ }
405
+ return this._instance;
406
+ }
407
+ getUrl(configs) {
408
+ var _a;
409
+ return (_a = configs.cloudflare) == null ? void 0 : _a.url;
410
+ }
411
+ deploy(props) {
412
+ const cloudflareConfig = props.configs.cloudflare;
413
+ if (!cloudflareConfig)
414
+ throw new Error("cloudflare 配置为空");
415
+ return new Promise((res) => {
416
+ const cmd = node_os.platform() === "win32" ? "wrangler.cmd" : "wrangler";
417
+ const output = node_child_process.spawn(cmd, [
418
+ "pages",
419
+ "deploy",
420
+ props.folder,
421
+ "--project-name",
422
+ cloudflareConfig.projectName
423
+ ], {
424
+ stdio: ["pipe", "inherit", "inherit"],
425
+ env: {
426
+ ...process.env,
427
+ "CLOUDFLARE_API_TOKEN": cloudflareConfig.token
428
+ }
429
+ });
430
+ output.on("exit", function(code) {
431
+ if (code === 0) {
432
+ console.log(logSymbols.success, "部署完成!");
433
+ res();
434
+ return;
435
+ }
436
+ throw new Error("部署失败!");
437
+ });
438
+ });
439
+ }
440
+ validateConfig(configs) {
441
+ if (configs.cloudflare) {
442
+ if (!configs.cloudflare.url || !/^https/.test(configs.cloudflare.url)) {
443
+ return `configs.cloudflare.url 配置不正确`;
444
+ }
445
+ if (!configs.cloudflare.token) {
446
+ return `configs.cloudflare.token 未配置`;
447
+ }
448
+ if (!configs.cloudflare.projectName) {
449
+ return `configs.cloudflare.projectName 未配置`;
450
+ }
451
+ }
452
+ return `configs.cloudflare 配置不存在`;
453
+ }
454
+ };
455
+ let Cloudflare = _Cloudflare;
456
+ __publicField(Cloudflare, "_instance");
382
457
  commander.program.command("deploy").description("执行部署").action(async (source, destination) => {
383
458
  const configs = await getConfigs();
384
459
  try {
@@ -393,34 +468,18 @@ commander.program.command("deploy").description("执行部署").action(async (so
393
468
  });
394
469
  async function deploy(configs) {
395
470
  console.log(logSymbols.info, "开始部署", r());
396
- const cmd = node_os.platform() === "win32" ? "netlify.cmd" : "netlify";
397
- const output = node_child_process.spawn(cmd, [
398
- "deploy",
399
- "--dir",
400
- r("node_modules/.evd"),
401
- "--site",
402
- configs.netlify.siteID,
403
- "--auth",
404
- configs.netlify.token,
405
- "--prod",
406
- "--debug"
407
- ], {
408
- stdio: ["pipe", "inherit", "inherit"]
409
- });
410
- output.on("exit", function(code) {
411
- if (code === 0) {
412
- console.log(logSymbols.success, "部署完成!");
413
- return;
414
- }
415
- throw new Error("部署失败!");
471
+ await getWhichProvider(configs).deploy({
472
+ folder: r("node_modules/.evd"),
473
+ configs
416
474
  });
417
475
  }
418
476
  async function validateRemotePackageJSON(configs) {
477
+ const url = getWhichProvider(configs).getUrl(configs);
419
478
  const compiledPackageJSON = JSON.parse(
420
479
  node_fs.readFileSync(r("node_modules/.evd/package.json"), "utf-8")
421
480
  );
422
481
  const compiledName = compiledPackageJSON.name;
423
- const remotePKG = await fetchRemotePkgJSON(configs.netlify.url);
482
+ const remotePKG = await fetchRemotePkgJSON(url);
424
483
  if (!remotePKG)
425
484
  return;
426
485
  const remoteName = remotePKG.name;
@@ -453,10 +512,11 @@ async function validateRemotePackageJSON(configs) {
453
512
  }
454
513
  }
455
514
  async function checkIsFirstTimeDeploy(configs) {
456
- const remotePKG = await fetchRemotePkgJSON(configs.netlify.url);
515
+ const url = getWhichProvider(configs).getUrl(configs);
516
+ const remotePKG = await fetchRemotePkgJSON(url);
457
517
  if (!remotePKG) {
458
518
  const answer = await prompts.confirm({
459
- message: `似乎 ${configs.netlify.url} 还未部署过任何版本,确认继续吗?`
519
+ message: `似乎 ${url} 还未部署过任何版本,确认继续吗?`
460
520
  });
461
521
  if (!answer) {
462
522
  throw new Error("部署已停止!");
@@ -464,15 +524,16 @@ async function checkIsFirstTimeDeploy(configs) {
464
524
  }
465
525
  }
466
526
  async function validateConfigs(configs) {
467
- if (!configs.netlify.url || !/^https/.test(configs.netlify.url)) {
468
- throw new Error(`configs.netlify.url 配置不正确`);
469
- }
470
- if (!configs.netlify.token) {
471
- throw new Error(`configs.netlify.token 未配置`);
472
- }
473
- if (!configs.netlify.siteID) {
474
- throw new Error(`configs.netlify.siteID 未配置`);
475
- }
527
+ const error = getWhichProvider(configs).validateConfig(configs);
528
+ if (error)
529
+ throw new Error(error);
530
+ }
531
+ function getWhichProvider(configs) {
532
+ if (configs.netlify && configs.netlify.url && configs.netlify.siteID && configs.netlify.token)
533
+ return Netlify.instance;
534
+ if (configs.cloudflare && configs.cloudflare.projectName && configs.cloudflare.token && configs.cloudflare.url)
535
+ return Cloudflare.instance;
536
+ throw new Error("未提供/配置不正确 configs.netlify / configs.cloudflare");
476
537
  }
477
538
  async function checkEVDFolderExist() {
478
539
  if (!node_fs.existsSync(r("node_modules/.evd"))) {
@@ -507,4 +568,4 @@ async function installPrebuilt(configs) {
507
568
  }
508
569
  commander.program.description(
509
570
  "Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
510
- ).helpOption("-h, --help", "使用帮助").version("0.0.18", "-V, --version", "显示版本号").parse(process.argv);
571
+ ).helpOption("-h, --help", "使用帮助").version("0.1.0", "-V, --version", "显示版本号").parse(process.argv);
package/dist/main.d.ts CHANGED
@@ -7,13 +7,14 @@ export declare enum EVDEventEnum {
7
7
  }
8
8
  type EVDInitPropsType = {
9
9
  netlifyUrl: string;
10
+ remoteUrl: string;
10
11
  windowWidth?: number;
11
12
  windowHeight?: number;
12
13
  logo?: string;
13
14
  detectionFrequency?: number;
14
15
  detectAtStart?: boolean;
15
16
  onError?: (err: unknown) => void;
16
- onBeforeNewPkgInstall?: (next: () => any) => void;
17
+ onBeforeNewPkgInstall?: (next: () => any, version: string) => void;
17
18
  };
18
19
  export declare function EVDInit(props: EVDInitPropsType): void;
19
20
  export declare function EVDCheckUpdate(): Promise<boolean>;
package/dist/main.js CHANGED
@@ -82,6 +82,12 @@ var EVDEventEnum = /* @__PURE__ */ ((EVDEventEnum2) => {
82
82
  let globalArgs = null;
83
83
  let cacheCurrentPkgJSON = null;
84
84
  function EVDInit(props) {
85
+ if (props.netlifyUrl) {
86
+ props.remoteUrl = props.netlifyUrl;
87
+ console.warn(
88
+ "EVDInit 中的 netlifyUrl 参数已废弃,将会在下个主版本更新时删除,请使用 remoteUrl 代替"
89
+ );
90
+ }
85
91
  globalArgs = props;
86
92
  const { detectionFrequency, detectAtStart, onError } = getConfigs();
87
93
  setInterval(async () => {
@@ -106,11 +112,11 @@ function EVDInit(props) {
106
112
  );
107
113
  }
108
114
  async function EVDCheckUpdate() {
109
- const { netlifyUrl } = getConfigs();
115
+ const { remoteUrl } = getConfigs();
110
116
  const { version } = cacheCurrentPkgJSON;
111
- const remoteJSON = await fetchRemotePkgJSON(netlifyUrl);
117
+ const remoteJSON = await fetchRemotePkgJSON(remoteUrl);
112
118
  if (!remoteJSON)
113
- throw new Error(`${netlifyUrl}package.json 文件不存在`);
119
+ throw new Error(`${remoteUrl}package.json 文件不存在`);
114
120
  const localVersion = versionToNum(version);
115
121
  const remoteVersion = versionToNum(remoteJSON.version);
116
122
  if (remoteVersion > localVersion) {
@@ -184,8 +190,8 @@ async function showNewVersionDialog() {
184
190
  });
185
191
  }
186
192
  async function installNewVersion() {
187
- const { netlifyUrl, onError } = getConfigs();
188
- const remoteJSON = await fetchRemotePkgJSON(netlifyUrl);
193
+ const { remoteUrl, onError } = getConfigs();
194
+ const remoteJSON = await fetchRemotePkgJSON(remoteUrl);
189
195
  const needInstallFullSize = compareObjectsIsEqual(
190
196
  remoteJSON.dependencies,
191
197
  cacheCurrentPkgJSON.dependencies
@@ -197,7 +203,7 @@ async function installNewVersion() {
197
203
  }
198
204
  }
199
205
  async function installPkg(zipFile) {
200
- const { netlifyUrl } = getConfigs();
206
+ const { remoteUrl } = getConfigs();
201
207
  const appPath = electron.app.getAppPath();
202
208
  const unzipPath = node_path.join(appPath, "evdUnzip");
203
209
  const installerFile = node_path.join(appPath, "_evdInstallerTmp.js");
@@ -211,7 +217,7 @@ async function installPkg(zipFile) {
211
217
  node_fs.mkdirSync(unzipPath);
212
218
  const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
213
219
  await new Promise(
214
- (res, rej) => node_https.get(`${netlifyUrl}/${zipFile}`, (response) => {
220
+ (res, rej) => node_https.get(`${remoteUrl}/${zipFile}`, (response) => {
215
221
  response.pipe(tmpZipFilePath).on("finish", () => {
216
222
  res();
217
223
  }).on("error", (err) => {
@@ -250,7 +256,7 @@ async function installPkg(zipFile) {
250
256
  ]);
251
257
  }
252
258
  function bindEvent(promptWindow, onError) {
253
- const { logo, onBeforeNewPkgInstall } = getConfigs();
259
+ const { logo, onBeforeNewPkgInstall, remoteUrl } = getConfigs();
254
260
  electron.ipcMain.on("evd-open-link", (_, link) => {
255
261
  electron.shell.openExternal(link);
256
262
  });
@@ -258,22 +264,24 @@ function bindEvent(promptWindow, onError) {
258
264
  promptWindow.close();
259
265
  });
260
266
  electron.ipcMain.on("evd-update-now", (_) => {
261
- onBeforeNewPkgInstall(() => {
262
- installNewVersion().then(() => {
263
- setTimeout(() => promptWindow.close(), 1);
264
- setTimeout(() => electron.app.relaunch(), 1);
265
- setTimeout(() => electron.app.exit(), 1);
266
- }).catch((e) => {
267
- onError(e);
268
- });
267
+ fetchRemotePkgJSON(remoteUrl).then((pkg) => {
268
+ onBeforeNewPkgInstall(() => {
269
+ installNewVersion().then(() => {
270
+ setTimeout(() => promptWindow.close(), 1);
271
+ setTimeout(() => electron.app.relaunch(), 1);
272
+ setTimeout(() => electron.app.exit(), 1);
273
+ }).catch((e) => {
274
+ onError(e);
275
+ });
276
+ }, pkg.version);
269
277
  });
270
278
  });
271
279
  electron.ipcMain.handle("evd-get-logo", () => {
272
280
  return logo;
273
281
  });
274
282
  electron.ipcMain.handle("evd-get-change-logs", async () => {
275
- const { netlifyUrl } = getConfigs();
276
- return await fetchRemoteChangelogJSON(netlifyUrl);
283
+ const { remoteUrl: remoteUrl2 } = getConfigs();
284
+ return await fetchRemoteChangelogJSON(remoteUrl2);
277
285
  });
278
286
  }
279
287
  function cleanup(promptWindow) {
@@ -310,7 +318,7 @@ function getConfigs() {
310
318
  ...{
311
319
  onError: () => {
312
320
  },
313
- onBeforeNewPkgInstall: (next) => {
321
+ onBeforeNewPkgInstall: (next, version) => {
314
322
  next();
315
323
  },
316
324
  windowHeight: 360,
@@ -15,5 +15,10 @@ export default defineEVDConfig({
15
15
  token: __netlify_token__,
16
16
  siteID: __netlify_siteID__,
17
17
  },
18
+ cloudflare: {
19
+ url: __cloudflare_url__,
20
+ token: __cloudflare_token__,
21
+ projectName: __cloudflare_projectName__,
22
+ },
18
23
  prebuiltConfig: {},
19
24
  });
@@ -11,10 +11,15 @@ export type EVDConfigType = {
11
11
  codes: string;
12
12
  packageJSON: string;
13
13
  };
14
- netlify: {
14
+ netlify?: {
15
15
  url: string;
16
16
  token: string;
17
17
  siteID: string;
18
18
  };
19
+ cloudflare?: {
20
+ url: string;
21
+ token: string;
22
+ projectName: string;
23
+ };
19
24
  prebuiltConfig: PrebuiltConfigType;
20
25
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-version-deployer-cli",
3
3
  "private": false,
4
- "version": "0.0.18",
4
+ "version": "0.1.0",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.cjs.js",
7
7
  "module": "./dist/index.es.js",
@@ -18,23 +18,24 @@
18
18
  "dist"
19
19
  ],
20
20
  "devDependencies": {
21
+ "@inquirer/prompts": "^1.2.3",
21
22
  "@types/archiver": "^5.3.2",
22
23
  "@types/node": "^20.2.5",
23
- "electron": "^25.0.1",
24
- "prettier": "^2.8.8",
25
- "tsc-alias": "^1.8.6",
26
- "typescript": "^5.0.2",
27
- "vite": "^4.3.9",
28
- "@inquirer/prompts": "^1.2.3",
29
24
  "changelog-parser": "^3.0.1",
30
25
  "commander": "^10.0.1",
31
26
  "dompurify": "^3.0.3",
32
27
  "download": "^8.0.0",
28
+ "electron": "^25.0.1",
33
29
  "esno": "^0.16.3",
34
30
  "jsdom": "^22.1.0",
35
31
  "log-symbols": "=4.1.0",
36
32
  "marked": "^5.0.4",
37
- "netlify-cli": "^15.2.0"
33
+ "netlify-cli": "^15.2.0",
34
+ "prettier": "^2.8.8",
35
+ "tsc-alias": "^1.8.6",
36
+ "typescript": "^5.0.2",
37
+ "vite": "^4.3.9",
38
+ "wrangler": "^3.3.0"
38
39
  },
39
40
  "dependencies": {
40
41
  "archiver": "^5.3.1",
@@ -42,17 +43,18 @@
42
43
  "pkg-up": "3.1.0"
43
44
  },
44
45
  "peerDependencies": {
45
- "electron": ">=10.0.0",
46
46
  "@inquirer/prompts": "^1.2.3",
47
47
  "changelog-parser": "^3.0.1",
48
48
  "commander": "^10.0.1",
49
49
  "dompurify": "^3.0.3",
50
50
  "download": "^8.0.0",
51
+ "electron": ">=10.0.0",
51
52
  "esno": "^0.16.3",
52
53
  "jsdom": "^22.1.0",
53
54
  "log-symbols": "=4.1.0",
54
55
  "marked": "^5.0.4",
55
56
  "netlify-cli": "^15.2.0",
56
- "vite": "^4.3.9"
57
+ "vite": "^4.3.9",
58
+ "wrangler": "^3.3.0"
57
59
  }
58
60
  }