electron-incremental-update 0.2.1 → 0.2.2

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/index.cjs CHANGED
@@ -34,8 +34,9 @@ __export(src_exports, {
34
34
  getAppAsarPath: () => getAppAsarPath,
35
35
  getAppVersion: () => getAppVersion,
36
36
  getEntryVersion: () => getEntryVersion,
37
- getReleaseCdnLink: () => getReleaseCdnLink,
37
+ getGithubReleaseCdnGroup: () => getGithubReleaseCdnGroup,
38
38
  initApp: () => initApp,
39
+ parseGithubCdnURL: () => parseGithubCdnURL,
39
40
  requireNative: () => requireNative
40
41
  });
41
42
  module.exports = __toCommonJS(src_exports);
@@ -130,37 +131,37 @@ function getEntryVersion() {
130
131
  return import_electron.app.getVersion();
131
132
  }
132
133
  function getAppVersion(name) {
133
- return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getAppAsarPath(name), "version"), "utf-8").trim() : getEntryVersion();
134
+ return import_electron.app.isPackaged ? (0, import_node_fs.readFileSync)((0, import_node_path.join)(getAppAsarPath(name), "version"), "utf-8") : getEntryVersion();
134
135
  }
135
136
  function requireNative(packageName) {
136
137
  const path = import_electron.app.isPackaged ? (0, import_node_path.join)(import_electron.app.getAppPath(), "node_modules", packageName) : packageName;
137
138
  return require(path);
138
139
  }
139
- function getReleaseCdnLink(url) {
140
- const hub = "https://github.com/";
141
- if (!url.startsWith(hub)) {
142
- throw new Error("URL must start with 'https://github.com/'");
140
+ function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
141
+ if (!repository.startsWith("https://github.com/")) {
142
+ throw new Error("url must start with https://github.com/");
143
143
  }
144
- if (url.endsWith("/")) {
145
- url = url.slice(0, -1);
146
- }
147
- const _url = url.replace(hub, "");
144
+ repository = repository.trim().replace(/\/?$/, "/").trim();
145
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
146
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
147
+ return repository.replace("github.com", cdnPrefix) + relativeFilePath;
148
+ }
149
+ function getGithubReleaseCdnGroup() {
148
150
  return [
149
- { url: `https://gh.gh2233.ml/${url}`, maintainer: "@X.I.U/XIU2" },
150
- { url: `https://ghproxy.com/${url}`, maintainer: "gh-proxy" },
151
- { url: `https://gh.ddlc.top/${url}`, maintainer: "@mtr-static-official" },
152
- { url: `https://ghdl.feizhuqwq.cf/${url}`, maintainer: "feizhuqwq.com" },
153
- { url: `https://slink.ltd/${url}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
154
- { url: `https://git.xfj0.cn/${url}`, maintainer: "anonymous1" },
155
- { url: `https://gh.con.sh/${url}`, maintainer: "anonymous2" },
156
- { url: `https://ghps.cc/${url}`, maintainer: "anonymous3" },
157
- { url: `https://cors.isteed.cc/github.com/${_url}`, maintainer: "Lufs's" },
158
- { url: `https://hub.gitmirror.com/${url}`, maintainer: "GitMirror" },
159
- { url: `https://js.xxooo.ml/${url}`, maintainer: "\u996D\u592A\u786C" },
160
- { url: `https://proxy.freecdn.ml/?url=${url}`, maintainer: "anonymous4" },
161
- { url: `https://download.njuu.cf/${_url}`, maintainer: "LibraryCloud-njuu" },
162
- { url: `https://download.yzuu.cf/${_url}`, maintainer: "LibraryCloud-yzuu" },
163
- { url: `https://download.nuaa.cf/${_url}`, maintainer: "LibraryCloud-nuaa" }
151
+ { cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
152
+ { cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
153
+ { cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
154
+ { cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
155
+ { cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
156
+ { cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
157
+ { cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
158
+ { cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
159
+ { cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
160
+ { cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
161
+ { cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
162
+ { cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
163
+ { cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
164
+ { cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
164
165
  ];
165
166
  }
166
167
 
@@ -310,7 +311,8 @@ function initApp(productName, updater, option) {
310
311
  getAppAsarPath,
311
312
  getAppVersion,
312
313
  getEntryVersion,
313
- getReleaseCdnLink,
314
+ getGithubReleaseCdnGroup,
314
315
  initApp,
316
+ parseGithubCdnURL,
315
317
  requireNative
316
318
  });
package/dist/index.d.ts CHANGED
@@ -123,10 +123,14 @@ declare function getAppVersion(name: string): string;
123
123
  */
124
124
  declare function requireNative<T = any>(packageName: string): T;
125
125
  /**
126
- * get group of parsed github release CDN links for accelerating the speed of downloading release
126
+ * get github version.json CDN URL for accelerating the speed of downloading version info
127
127
  */
128
- declare function getReleaseCdnLink(url: string): {
129
- url: string;
128
+ declare function parseGithubCdnURL(repository: string, cdnPrefix: string, relativeFilePath: string): string;
129
+ /**
130
+ * get group of github release CDN prefix for accelerating the speed of downloading release
131
+ */
132
+ declare function getGithubReleaseCdnGroup(): {
133
+ cdnPrefix: string;
130
134
  maintainer: string;
131
135
  }[];
132
136
 
@@ -189,4 +193,4 @@ declare function initApp(productName: string, updater: Updater | Omit<UpdaterOpt
189
193
  productName?: string;
190
194
  }, option?: AppOption): any;
191
195
 
192
- export { BaseOption, CheckResultType, UpdateJSON, Updater, UpdaterOption, createUpdater, getAppAsarPath, getAppVersion, getEntryVersion, getReleaseCdnLink, initApp, requireNative };
196
+ export { BaseOption, CheckResultType, UpdateJSON, Updater, UpdaterOption, createUpdater, getAppAsarPath, getAppVersion, getEntryVersion, getGithubReleaseCdnGroup, initApp, parseGithubCdnURL, requireNative };
package/dist/index.mjs CHANGED
@@ -94,37 +94,37 @@ function getEntryVersion() {
94
94
  return app.getVersion();
95
95
  }
96
96
  function getAppVersion(name) {
97
- return app.isPackaged ? readFileSync(join(getAppAsarPath(name), "version"), "utf-8").trim() : getEntryVersion();
97
+ return app.isPackaged ? readFileSync(join(getAppAsarPath(name), "version"), "utf-8") : getEntryVersion();
98
98
  }
99
99
  function requireNative(packageName) {
100
100
  const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
101
101
  return __require(path);
102
102
  }
103
- function getReleaseCdnLink(url) {
104
- const hub = "https://github.com/";
105
- if (!url.startsWith(hub)) {
106
- throw new Error("URL must start with 'https://github.com/'");
103
+ function parseGithubCdnURL(repository, cdnPrefix, relativeFilePath) {
104
+ if (!repository.startsWith("https://github.com/")) {
105
+ throw new Error("url must start with https://github.com/");
107
106
  }
108
- if (url.endsWith("/")) {
109
- url = url.slice(0, -1);
110
- }
111
- const _url = url.replace(hub, "");
107
+ repository = repository.trim().replace(/\/?$/, "/").trim();
108
+ relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
109
+ cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
110
+ return repository.replace("github.com", cdnPrefix) + relativeFilePath;
111
+ }
112
+ function getGithubReleaseCdnGroup() {
112
113
  return [
113
- { url: `https://gh.gh2233.ml/${url}`, maintainer: "@X.I.U/XIU2" },
114
- { url: `https://ghproxy.com/${url}`, maintainer: "gh-proxy" },
115
- { url: `https://gh.ddlc.top/${url}`, maintainer: "@mtr-static-official" },
116
- { url: `https://ghdl.feizhuqwq.cf/${url}`, maintainer: "feizhuqwq.com" },
117
- { url: `https://slink.ltd/${url}`, maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
118
- { url: `https://git.xfj0.cn/${url}`, maintainer: "anonymous1" },
119
- { url: `https://gh.con.sh/${url}`, maintainer: "anonymous2" },
120
- { url: `https://ghps.cc/${url}`, maintainer: "anonymous3" },
121
- { url: `https://cors.isteed.cc/github.com/${_url}`, maintainer: "Lufs's" },
122
- { url: `https://hub.gitmirror.com/${url}`, maintainer: "GitMirror" },
123
- { url: `https://js.xxooo.ml/${url}`, maintainer: "\u996D\u592A\u786C" },
124
- { url: `https://proxy.freecdn.ml/?url=${url}`, maintainer: "anonymous4" },
125
- { url: `https://download.njuu.cf/${_url}`, maintainer: "LibraryCloud-njuu" },
126
- { url: `https://download.yzuu.cf/${_url}`, maintainer: "LibraryCloud-yzuu" },
127
- { url: `https://download.nuaa.cf/${_url}`, maintainer: "LibraryCloud-nuaa" }
114
+ { cdnPrefix: "gh.gh2233.ml", maintainer: "@X.I.U/XIU2" },
115
+ { cdnPrefix: "ghproxy.com", maintainer: "gh-proxy" },
116
+ { cdnPrefix: "gh.ddlc.top", maintainer: "@mtr-static-official" },
117
+ { cdnPrefix: "ghdl.feizhuqwq.cf", maintainer: "feizhuqwq.com" },
118
+ { cdnPrefix: "slink.ltd", maintainer: "\u77E5\u4E86\u5C0F\u7AD9" },
119
+ { cdnPrefix: "git.xfj0.cn", maintainer: "anonymous1" },
120
+ { cdnPrefix: "gh.con.sh", maintainer: "anonymous2" },
121
+ { cdnPrefix: "ghps.cc", maintainer: "anonymous3" },
122
+ { cdnPrefix: "cors.isteed.cc/github.com", maintainer: "Lufs's" },
123
+ { cdnPrefix: "hub.gitmirror.com", maintainer: "GitMirror" },
124
+ { cdnPrefix: "js.xxooo.ml", maintainer: "\u996D\u592A\u786C" },
125
+ { cdnPrefix: "download.njuu.cf", maintainer: "LibraryCloud-njuu" },
126
+ { cdnPrefix: "download.yzuu.cf", maintainer: "LibraryCloud-yzuu" },
127
+ { cdnPrefix: "download.nuaa.cf", maintainer: "LibraryCloud-nuaa" }
128
128
  ];
129
129
  }
130
130
 
@@ -273,7 +273,8 @@ export {
273
273
  getAppAsarPath,
274
274
  getAppVersion,
275
275
  getEntryVersion,
276
- getReleaseCdnLink,
276
+ getGithubReleaseCdnGroup,
277
277
  initApp,
278
+ parseGithubCdnURL,
278
279
  requireNative
279
280
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "electron incremental update tools, powered by vite",
5
5
  "scripts": {
6
6
  "build": "tsup",