electron-incremental-update 0.1.0 → 0.1.1
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 +11 -8
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +11 -8
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -91,9 +91,10 @@ var import_node_https = __toESM(require("https"), 1);
|
|
|
91
91
|
var import_electron2 = require("electron");
|
|
92
92
|
function createUpdater({
|
|
93
93
|
SIGNATURE_PUB,
|
|
94
|
-
githubRepository
|
|
94
|
+
githubRepository,
|
|
95
95
|
productName,
|
|
96
|
-
releaseCdnPrefix
|
|
96
|
+
releaseCdnPrefix: _release,
|
|
97
|
+
updateJsonURL: _update
|
|
97
98
|
}) {
|
|
98
99
|
const updater = new import_node_events.EventEmitter();
|
|
99
100
|
async function download(url, format) {
|
|
@@ -162,12 +163,14 @@ function createUpdater({
|
|
|
162
163
|
};
|
|
163
164
|
return import_electron2.app.isPackaged && parseVersion(import_electron2.app.getVersion()) < parseVersion(version);
|
|
164
165
|
}
|
|
165
|
-
async function checkUpdate(
|
|
166
|
+
async function checkUpdate(option) {
|
|
167
|
+
const { releaseCdnPrefix, updateJsonURL } = option || {};
|
|
166
168
|
const gzipPath = `../${productName}.asar.gz`;
|
|
167
169
|
const tmpFile = gzipPath.replace(".asar.gz", ".tmp.gz");
|
|
168
|
-
const base =
|
|
169
|
-
const updateJSONUrl = `https://cdn.jsdelivr.net/gh/${base}/version.json`;
|
|
170
|
-
const
|
|
170
|
+
const base = githubRepository.replace("https://github.com", "");
|
|
171
|
+
const updateJSONUrl = updateJsonURL ?? _update ?? `https://cdn.jsdelivr.net/gh/${base}/version.json`;
|
|
172
|
+
const prefix = releaseCdnPrefix ?? _release;
|
|
173
|
+
const downloadUrl = `${prefix ? `${prefix}/${base}` : githubRepository}/releases/download/latest/${productName}.asar.gz`;
|
|
171
174
|
if ((0, import_node_fs2.existsSync)(tmpFile)) {
|
|
172
175
|
await (0, import_promises.rm)(tmpFile);
|
|
173
176
|
}
|
|
@@ -193,9 +196,9 @@ function createUpdater({
|
|
|
193
196
|
await extractFile(gzipPath);
|
|
194
197
|
return "success";
|
|
195
198
|
}
|
|
196
|
-
const onCheck = async () => {
|
|
199
|
+
const onCheck = async (option) => {
|
|
197
200
|
try {
|
|
198
|
-
const result = await checkUpdate(
|
|
201
|
+
const result = await checkUpdate(option);
|
|
199
202
|
updater.emit("checkResult", result);
|
|
200
203
|
} catch (error) {
|
|
201
204
|
updater.emit("checkResult", "fail", error);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ type UpdateEvents = {
|
|
|
8
8
|
donwnloadError: [error: unknown];
|
|
9
9
|
};
|
|
10
10
|
type MaybeArray<T> = T extends undefined | null | never ? [] : T extends any[] ? T['length'] extends 1 ? [data: T[0]] : T : [data: T];
|
|
11
|
+
interface CheckUpdateOption {
|
|
12
|
+
updateJsonURL?: string;
|
|
13
|
+
releaseCdnPrefix?: string;
|
|
14
|
+
}
|
|
11
15
|
interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event extends Exclude<keyof T, number> = Exclude<keyof T, number>> {
|
|
12
16
|
removeAllListeners<E extends Event>(event?: E): this;
|
|
13
17
|
listeners<E extends Event>(eventName: E): Function[];
|
|
@@ -16,16 +20,15 @@ interface TypedUpdater<T extends Record<string | symbol, MaybeArray<any>>, Event
|
|
|
16
20
|
once<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
|
|
17
21
|
emit<E extends Event>(eventName: E, ...args: MaybeArray<T[E]>): boolean;
|
|
18
22
|
off<E extends Event>(eventName: E, listener: (...args: MaybeArray<T[E]>) => void): this;
|
|
19
|
-
checkUpdate(
|
|
23
|
+
checkUpdate(options?: CheckUpdateOption): Promise<void>;
|
|
20
24
|
}
|
|
21
25
|
type Updater = TypedUpdater<UpdateEvents>;
|
|
22
|
-
interface Options {
|
|
26
|
+
interface Options extends CheckUpdateOption {
|
|
23
27
|
SIGNATURE_PUB: string;
|
|
24
28
|
productName: string;
|
|
25
29
|
githubRepository: string;
|
|
26
|
-
releaseCdnPrefix?: string;
|
|
27
30
|
}
|
|
28
|
-
declare function createUpdater({ SIGNATURE_PUB, githubRepository
|
|
31
|
+
declare function createUpdater({ SIGNATURE_PUB, githubRepository, productName, releaseCdnPrefix: _release, updateJsonURL: _update, }: Options): Updater;
|
|
29
32
|
|
|
30
33
|
declare function getAppAsarPath(name: string): string;
|
|
31
34
|
declare function getElectronVersion(): string;
|
package/dist/index.mjs
CHANGED
|
@@ -55,9 +55,10 @@ import https from "node:https";
|
|
|
55
55
|
import { app as app2 } from "electron";
|
|
56
56
|
function createUpdater({
|
|
57
57
|
SIGNATURE_PUB,
|
|
58
|
-
githubRepository
|
|
58
|
+
githubRepository,
|
|
59
59
|
productName,
|
|
60
|
-
releaseCdnPrefix
|
|
60
|
+
releaseCdnPrefix: _release,
|
|
61
|
+
updateJsonURL: _update
|
|
61
62
|
}) {
|
|
62
63
|
const updater = new EventEmitter();
|
|
63
64
|
async function download(url, format) {
|
|
@@ -126,12 +127,14 @@ function createUpdater({
|
|
|
126
127
|
};
|
|
127
128
|
return app2.isPackaged && parseVersion(app2.getVersion()) < parseVersion(version);
|
|
128
129
|
}
|
|
129
|
-
async function checkUpdate(
|
|
130
|
+
async function checkUpdate(option) {
|
|
131
|
+
const { releaseCdnPrefix, updateJsonURL } = option || {};
|
|
130
132
|
const gzipPath = `../${productName}.asar.gz`;
|
|
131
133
|
const tmpFile = gzipPath.replace(".asar.gz", ".tmp.gz");
|
|
132
|
-
const base =
|
|
133
|
-
const updateJSONUrl = `https://cdn.jsdelivr.net/gh/${base}/version.json`;
|
|
134
|
-
const
|
|
134
|
+
const base = githubRepository.replace("https://github.com", "");
|
|
135
|
+
const updateJSONUrl = updateJsonURL ?? _update ?? `https://cdn.jsdelivr.net/gh/${base}/version.json`;
|
|
136
|
+
const prefix = releaseCdnPrefix ?? _release;
|
|
137
|
+
const downloadUrl = `${prefix ? `${prefix}/${base}` : githubRepository}/releases/download/latest/${productName}.asar.gz`;
|
|
135
138
|
if (existsSync(tmpFile)) {
|
|
136
139
|
await rm(tmpFile);
|
|
137
140
|
}
|
|
@@ -157,9 +160,9 @@ function createUpdater({
|
|
|
157
160
|
await extractFile(gzipPath);
|
|
158
161
|
return "success";
|
|
159
162
|
}
|
|
160
|
-
const onCheck = async () => {
|
|
163
|
+
const onCheck = async (option) => {
|
|
161
164
|
try {
|
|
162
|
-
const result = await checkUpdate(
|
|
165
|
+
const result = await checkUpdate(option);
|
|
163
166
|
updater.emit("checkResult", result);
|
|
164
167
|
} catch (error) {
|
|
165
168
|
updater.emit("checkResult", "fail", error);
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
7
|
-
"release": "bumpp"
|
|
7
|
+
"release": "tsup && bumpp"
|
|
8
8
|
},
|
|
9
|
+
"repository": "https://github.com/subframe7536/electron-incremental-update",
|
|
9
10
|
"type": "module",
|
|
10
11
|
"license": "MIT",
|
|
11
12
|
"files": [
|