electron-incremental-update 0.9.1 → 1.0.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/README.md +159 -111
- package/dist/{chunk-CMBFI77K.mjs → chunk-GB6VLKJZ.mjs} +48 -28
- package/dist/{chunk-5BZLJPHJ.mjs → chunk-GXZSAUBR.mjs} +1 -8
- package/dist/chunk-OUZLSVQC.mjs +148 -0
- package/dist/index.d.mts +102 -80
- package/dist/index.d.ts +102 -80
- package/dist/index.js +134 -71
- package/dist/index.mjs +97 -43
- package/dist/noDep-TvZoKVF8.d.mts +31 -0
- package/dist/noDep-TvZoKVF8.d.ts +31 -0
- package/dist/utils.d.mts +85 -48
- package/dist/utils.d.ts +85 -48
- package/dist/utils.js +127 -86
- package/dist/utils.mjs +14 -20
- package/dist/vite.d.mts +208 -41
- package/dist/vite.d.ts +208 -41
- package/dist/vite.js +243 -122
- package/dist/vite.mjs +220 -98
- package/package.json +18 -11
- package/dist/chunk-SPZL37O5.mjs +0 -124
- package/dist/updateJson-synsK-Pt.d.mts +0 -11
- package/dist/updateJson-synsK-Pt.d.ts +0 -11
package/dist/vite.mjs
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isUpdateJSON,
|
|
3
2
|
signature
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GXZSAUBR.mjs";
|
|
5
4
|
import {
|
|
5
|
+
isUpdateJSON,
|
|
6
6
|
parseVersion,
|
|
7
7
|
zipFile
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GB6VLKJZ.mjs";
|
|
9
9
|
|
|
10
10
|
// src/vite.ts
|
|
11
|
-
import {
|
|
11
|
+
import { join as join2, resolve } from "node:path";
|
|
12
|
+
import { rmSync } from "node:fs";
|
|
13
|
+
import { createLogger, mergeConfig, normalizePath } from "vite";
|
|
14
|
+
import ElectronSimple from "vite-plugin-electron/simple";
|
|
15
|
+
import { startup } from "vite-plugin-electron";
|
|
16
|
+
import { notBundle } from "vite-plugin-electron/plugin";
|
|
12
17
|
|
|
13
18
|
// src/build-plugins/build.ts
|
|
14
19
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
15
|
-
import { existsSync } from "node:fs";
|
|
20
|
+
import { cpSync, existsSync } from "node:fs";
|
|
21
|
+
import { basename, join } from "node:path";
|
|
16
22
|
import Asar from "@electron/asar";
|
|
17
23
|
import { build } from "esbuild";
|
|
18
24
|
async function buildAsar({
|
|
@@ -22,8 +28,8 @@ async function buildAsar({
|
|
|
22
28
|
electronDistPath,
|
|
23
29
|
rendererDistPath
|
|
24
30
|
}) {
|
|
25
|
-
await rename(rendererDistPath,
|
|
26
|
-
await writeFile(
|
|
31
|
+
await rename(rendererDistPath, join(electronDistPath, "renderer"));
|
|
32
|
+
await writeFile(join(electronDistPath, "version"), version);
|
|
27
33
|
await Asar.createPackage(electronDistPath, asarOutputPath);
|
|
28
34
|
await zipFile(asarOutputPath, gzipPath);
|
|
29
35
|
}
|
|
@@ -51,13 +57,15 @@ async function buildVersion({
|
|
|
51
57
|
};
|
|
52
58
|
if (existsSync(versionPath)) {
|
|
53
59
|
try {
|
|
54
|
-
|
|
60
|
+
const oldVersionJson = JSON.parse(await readFile(versionPath, "utf-8"));
|
|
61
|
+
if (isUpdateJSON(oldVersionJson)) {
|
|
62
|
+
_json = oldVersionJson;
|
|
63
|
+
} else {
|
|
64
|
+
console.warn("old version json is invalid, ignore it");
|
|
65
|
+
}
|
|
55
66
|
} catch (error) {
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
|
-
if (!isUpdateJSON(_json)) {
|
|
59
|
-
throw new Error("invalid version file");
|
|
60
|
-
}
|
|
61
69
|
const buffer = await readFile(gzipPath);
|
|
62
70
|
const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
|
|
63
71
|
if (generateVersionJson) {
|
|
@@ -66,10 +74,12 @@ async function buildVersion({
|
|
|
66
74
|
throw new Error("invalid version info");
|
|
67
75
|
}
|
|
68
76
|
} else {
|
|
69
|
-
_json.beta
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
_json.beta = {
|
|
78
|
+
version,
|
|
79
|
+
minimumVersion,
|
|
80
|
+
signature: sig,
|
|
81
|
+
size: buffer.length
|
|
82
|
+
};
|
|
73
83
|
if (!parseVersion(version).stage) {
|
|
74
84
|
_json.version = version;
|
|
75
85
|
_json.minimumVersion = minimumVersion;
|
|
@@ -80,17 +90,44 @@ async function buildVersion({
|
|
|
80
90
|
await writeFile(versionPath, JSON.stringify(_json, null, 2));
|
|
81
91
|
}
|
|
82
92
|
async function buildEntry({
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
sourcemap,
|
|
94
|
+
minify,
|
|
95
|
+
appEntryPath,
|
|
96
|
+
entryOutputDirPath,
|
|
97
|
+
nativeModuleEntryMap,
|
|
98
|
+
overrideEsbuildOptions,
|
|
99
|
+
postBuild
|
|
86
100
|
}) {
|
|
87
101
|
await build({
|
|
88
|
-
entryPoints:
|
|
102
|
+
entryPoints: {
|
|
103
|
+
entry: appEntryPath,
|
|
104
|
+
...nativeModuleEntryMap
|
|
105
|
+
},
|
|
89
106
|
bundle: true,
|
|
90
107
|
platform: "node",
|
|
91
|
-
|
|
108
|
+
outdir: entryOutputDirPath,
|
|
92
109
|
minify,
|
|
93
|
-
|
|
110
|
+
sourcemap,
|
|
111
|
+
entryNames: "[dir]/[name]",
|
|
112
|
+
assetNames: "[dir]/[name]",
|
|
113
|
+
external: ["electron", "original-fs"],
|
|
114
|
+
loader: {
|
|
115
|
+
".node": "empty"
|
|
116
|
+
},
|
|
117
|
+
...overrideEsbuildOptions
|
|
118
|
+
});
|
|
119
|
+
await postBuild?.({
|
|
120
|
+
getPathFromEntryOutputDir(...paths) {
|
|
121
|
+
return join(entryOutputDirPath, ...paths);
|
|
122
|
+
},
|
|
123
|
+
existsAndCopyToEntryOutputDir({ from, to, skipIfExist = true }) {
|
|
124
|
+
if (existsSync(from)) {
|
|
125
|
+
const target = join(entryOutputDirPath, to ?? basename(from));
|
|
126
|
+
if (!skipIfExist || !existsSync(target)) {
|
|
127
|
+
cpSync(from, target);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
94
131
|
});
|
|
95
132
|
}
|
|
96
133
|
|
|
@@ -115,31 +152,21 @@ function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
|
|
|
115
152
|
writeFileSync(privateKeyPath, privateKey.replace(/\r\n?/g, "\n"));
|
|
116
153
|
writeFileSync(certPath, cert.replace(/\r\n?/g, "\n"));
|
|
117
154
|
}
|
|
118
|
-
|
|
155
|
+
var noCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)['"]{2}/m;
|
|
156
|
+
var existCertRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
157
|
+
function writeCertToEntry(entryPath, cert) {
|
|
158
|
+
if (!existsSync2(entryPath)) {
|
|
159
|
+
throw new Error(`entry not exist: ${entryPath}`);
|
|
160
|
+
}
|
|
119
161
|
const file = readFileSync(entryPath, "utf-8");
|
|
120
|
-
const
|
|
121
|
-
const existRegex = /(?<=const SIGNATURE_CERT\s*=\s*)(['"]-----BEGIN CERTIFICATE-----[\s\S]*-----END CERTIFICATE-----\\n['"])/m;
|
|
122
|
-
const eol = file.includes("\r") ? "\r\n" : "\n";
|
|
123
|
-
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join(`${eol} + `);
|
|
162
|
+
const replacement = cert.split("\n").filter(Boolean).map((s) => `'${s}\\n'`).join("\n + ");
|
|
124
163
|
let replaced = file;
|
|
125
|
-
if (
|
|
126
|
-
replaced = file.replace(
|
|
127
|
-
} else if (
|
|
128
|
-
replaced = file.replace(
|
|
164
|
+
if (noCertRegex.test(file)) {
|
|
165
|
+
replaced = file.replace(noCertRegex, replacement);
|
|
166
|
+
} else if (existCertRegex.test(file)) {
|
|
167
|
+
replaced = file.replace(existCertRegex, replacement);
|
|
129
168
|
} else {
|
|
130
|
-
|
|
131
|
-
const r = `${eol}const SIGNATURE_CERT = ${replacement}${eol}`;
|
|
132
|
-
let isMatched = false;
|
|
133
|
-
for (let i = 0; i < lines.length; i++) {
|
|
134
|
-
const line = lines[i];
|
|
135
|
-
if (!line.startsWith("import") && !line.startsWith("/")) {
|
|
136
|
-
lines.splice(i, 0, r);
|
|
137
|
-
isMatched = true;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
!isMatched && lines.push(r);
|
|
142
|
-
replaced = lines.join(eol);
|
|
169
|
+
throw new Error("no `SIGNATURE_CERT` found in entry");
|
|
143
170
|
}
|
|
144
171
|
writeFileSync(entryPath, replaced);
|
|
145
172
|
}
|
|
@@ -147,45 +174,40 @@ function parseKeys({
|
|
|
147
174
|
keyLength,
|
|
148
175
|
privateKeyPath,
|
|
149
176
|
certPath,
|
|
150
|
-
|
|
177
|
+
appEntryPath,
|
|
151
178
|
subject,
|
|
152
179
|
days
|
|
153
180
|
}) {
|
|
154
181
|
const keysDir = dirname(privateKeyPath);
|
|
155
182
|
!existsSync2(keysDir) && mkdirSync(keysDir);
|
|
156
183
|
if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
|
|
184
|
+
console.warn("no key pair found, generate new key pair");
|
|
157
185
|
generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
|
|
158
186
|
}
|
|
159
187
|
const privateKey = process.env.UPDATER_PK || readFileSync(privateKeyPath, "utf-8");
|
|
160
188
|
const cert = process.env.UPDATER_CERT || readFileSync(certPath, "utf-8");
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
privateKey,
|
|
164
|
-
cert
|
|
165
|
-
};
|
|
189
|
+
writeCertToEntry(appEntryPath, cert);
|
|
190
|
+
return { privateKey, cert };
|
|
166
191
|
}
|
|
167
192
|
function parseSubjects(subject) {
|
|
168
|
-
|
|
169
|
-
Object.keys(subject).forEach((name) => {
|
|
170
|
-
const value = subject[name];
|
|
171
|
-
value && ret.push({ name, value });
|
|
172
|
-
});
|
|
173
|
-
return ret;
|
|
193
|
+
return Object.entries(subject).filter(([_, value]) => !!value).map(([name, value]) => ({ name, value }));
|
|
174
194
|
}
|
|
175
195
|
|
|
176
196
|
// src/build-plugins/option.ts
|
|
177
|
-
function parseOptions(options) {
|
|
197
|
+
function parseOptions(isBuild, pkg, options = {}) {
|
|
178
198
|
const {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
minimumVersion = "0.0.0",
|
|
200
|
+
entry: {
|
|
201
|
+
minify = isBuild,
|
|
202
|
+
sourcemap = isBuild,
|
|
203
|
+
entryOutputDirPath = "dist-entry",
|
|
204
|
+
appEntryPath = "electron/entry.ts",
|
|
205
|
+
nativeModuleEntryMap = {},
|
|
206
|
+
postBuild
|
|
207
|
+
} = {},
|
|
184
208
|
paths: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
asarOutputPath = `release/${productName}.asar`,
|
|
188
|
-
gzipPath = `release/${productName}-${version}.asar.gz`,
|
|
209
|
+
asarOutputPath = `release/${pkg.name}.asar`,
|
|
210
|
+
gzipPath = `release/${pkg.name}-${pkg.version}.asar.gz`,
|
|
189
211
|
electronDistPath = "dist-electron",
|
|
190
212
|
rendererDistPath = "dist",
|
|
191
213
|
versionPath = "version.json"
|
|
@@ -195,39 +217,42 @@ function parseOptions(options) {
|
|
|
195
217
|
certPath = "keys/cert.pem",
|
|
196
218
|
keyLength = 2048,
|
|
197
219
|
certInfo = {},
|
|
198
|
-
|
|
220
|
+
overrideGenerator = {}
|
|
199
221
|
} = {}
|
|
200
222
|
} = options;
|
|
201
|
-
const { generateSignature, generateVersionJson } =
|
|
223
|
+
const { generateSignature, generateVersionJson } = overrideGenerator;
|
|
202
224
|
let {
|
|
203
225
|
subject = {
|
|
204
|
-
commonName:
|
|
205
|
-
organizationName: `org.${
|
|
226
|
+
commonName: pkg.name,
|
|
227
|
+
organizationName: `org.${pkg.name}`
|
|
206
228
|
},
|
|
207
|
-
days =
|
|
229
|
+
days = 3650
|
|
208
230
|
} = certInfo;
|
|
209
231
|
const buildAsarOption = {
|
|
210
|
-
version,
|
|
232
|
+
version: pkg.version,
|
|
211
233
|
asarOutputPath,
|
|
212
234
|
gzipPath,
|
|
213
235
|
electronDistPath,
|
|
214
236
|
rendererDistPath
|
|
215
237
|
};
|
|
216
238
|
const buildEntryOption = {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
239
|
+
minify,
|
|
240
|
+
sourcemap,
|
|
241
|
+
entryOutputDirPath,
|
|
242
|
+
appEntryPath,
|
|
243
|
+
nativeModuleEntryMap,
|
|
244
|
+
postBuild
|
|
220
245
|
};
|
|
221
246
|
const { privateKey, cert } = parseKeys({
|
|
222
247
|
keyLength,
|
|
223
248
|
privateKeyPath,
|
|
224
249
|
certPath,
|
|
225
|
-
|
|
250
|
+
appEntryPath,
|
|
226
251
|
subject,
|
|
227
252
|
days
|
|
228
253
|
});
|
|
229
254
|
const buildVersionOption = {
|
|
230
|
-
version,
|
|
255
|
+
version: pkg.version,
|
|
231
256
|
minimumVersion,
|
|
232
257
|
gzipPath,
|
|
233
258
|
privateKey,
|
|
@@ -236,33 +261,130 @@ function parseOptions(options) {
|
|
|
236
261
|
generateSignature,
|
|
237
262
|
generateVersionJson
|
|
238
263
|
};
|
|
239
|
-
return {
|
|
264
|
+
return { buildAsarOption, buildEntryOption, buildVersionOption };
|
|
240
265
|
}
|
|
241
266
|
|
|
242
267
|
// src/vite.ts
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
268
|
+
function debugStartup(args) {
|
|
269
|
+
process.env.VSCODE_DEBUG ? console.log("[startup] Electron App") : args.startup();
|
|
270
|
+
}
|
|
271
|
+
var id = "electron-incremental-updater";
|
|
272
|
+
var log = createLogger("info", { prefix: `[${id}]` });
|
|
273
|
+
function electronWithUpdater(options) {
|
|
274
|
+
const {
|
|
275
|
+
isBuild,
|
|
276
|
+
pkg,
|
|
277
|
+
main: _main,
|
|
278
|
+
preload: _preload,
|
|
279
|
+
updater,
|
|
280
|
+
useNotBundle = true,
|
|
281
|
+
logParsedOptions
|
|
282
|
+
} = options;
|
|
283
|
+
const _options = parseOptions(isBuild, pkg, updater);
|
|
284
|
+
try {
|
|
285
|
+
rmSync(_options.buildAsarOption.electronDistPath, { recursive: true, force: true });
|
|
286
|
+
rmSync(_options.buildEntryOption.entryOutputDirPath, { recursive: true, force: true });
|
|
287
|
+
} catch (ignore) {
|
|
288
|
+
}
|
|
289
|
+
log.info(`remove old files`, { timestamp: true });
|
|
290
|
+
const { buildAsarOption, buildEntryOption, buildVersionOption } = _options;
|
|
291
|
+
const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
|
|
292
|
+
const sourcemap = isBuild || !!process.env.VSCODE_DEBUG;
|
|
293
|
+
const _appPath = join2(entryOutputDirPath, "entry.js");
|
|
294
|
+
if (resolve(normalizePath(pkg.main)) !== resolve(normalizePath(_appPath))) {
|
|
295
|
+
throw new Error(`wrong "main" field in package.json: "${pkg.main}", it should be "${_appPath.replace(/\\/g, "/")}"`);
|
|
296
|
+
}
|
|
297
|
+
let isInit = false;
|
|
298
|
+
const _buildEntry = async () => {
|
|
299
|
+
await buildEntry(buildEntryOption);
|
|
300
|
+
log.info(`build entry to '${entryOutputDirPath}'`, { timestamp: true });
|
|
301
|
+
};
|
|
302
|
+
const electronPluginOptions = {
|
|
303
|
+
main: {
|
|
304
|
+
entry: _main.files,
|
|
305
|
+
onstart: async (args) => {
|
|
306
|
+
if (!isInit) {
|
|
307
|
+
isInit = true;
|
|
308
|
+
await _buildEntry();
|
|
309
|
+
}
|
|
310
|
+
_main.onstart?.(args) ?? args.startup();
|
|
311
|
+
},
|
|
312
|
+
vite: mergeConfig(
|
|
313
|
+
{
|
|
314
|
+
plugins: !isBuild && useNotBundle ? [notBundle()] : void 0,
|
|
315
|
+
build: {
|
|
316
|
+
sourcemap,
|
|
317
|
+
minify: isBuild,
|
|
318
|
+
outDir: `${buildAsarOption.electronDistPath}/main`,
|
|
319
|
+
rollupOptions: {
|
|
320
|
+
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
_main.vite ?? {}
|
|
325
|
+
)
|
|
326
|
+
},
|
|
327
|
+
preload: {
|
|
328
|
+
input: _preload.files,
|
|
329
|
+
onstart: _preload.onstart,
|
|
330
|
+
vite: mergeConfig(
|
|
331
|
+
{
|
|
332
|
+
plugins: [
|
|
333
|
+
{
|
|
334
|
+
name: `${id}-build`,
|
|
335
|
+
enforce: "post",
|
|
336
|
+
apply() {
|
|
337
|
+
return isBuild;
|
|
338
|
+
},
|
|
339
|
+
async closeBundle() {
|
|
340
|
+
await _buildEntry();
|
|
341
|
+
await buildAsar(buildAsarOption);
|
|
342
|
+
log.info(`build asar to '${buildAsarOption.asarOutputPath}'`, { timestamp: true });
|
|
343
|
+
await buildVersion(buildVersionOption);
|
|
344
|
+
log.info(`build version info to '${buildVersionOption.versionPath}'`, { timestamp: true });
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
build: {
|
|
349
|
+
sourcemap: sourcemap ? "inline" : void 0,
|
|
350
|
+
minify: isBuild,
|
|
351
|
+
outDir: `${buildAsarOption.electronDistPath}/preload`,
|
|
352
|
+
rollupOptions: {
|
|
353
|
+
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {})
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
_preload.vite ?? {}
|
|
358
|
+
)
|
|
263
359
|
}
|
|
264
360
|
};
|
|
361
|
+
logParsedOptions && log.info(
|
|
362
|
+
JSON.stringify(
|
|
363
|
+
{
|
|
364
|
+
...electronPluginOptions,
|
|
365
|
+
updater: { buildAsarOption, buildEntryOption, buildVersionOption }
|
|
366
|
+
},
|
|
367
|
+
(key, value) => key === "privateKey" || key === "cert" ? "***" : value,
|
|
368
|
+
2
|
|
369
|
+
),
|
|
370
|
+
{ timestamp: true }
|
|
371
|
+
);
|
|
372
|
+
let extraHmrPlugin;
|
|
373
|
+
if (nativeModuleEntryMap) {
|
|
374
|
+
const files = [...Object.values(nativeModuleEntryMap), appEntryPath].map((file) => resolve(normalizePath(file)));
|
|
375
|
+
extraHmrPlugin = {
|
|
376
|
+
name: `${id}-dev`,
|
|
377
|
+
apply() {
|
|
378
|
+
return !isBuild;
|
|
379
|
+
},
|
|
380
|
+
configureServer: (server) => {
|
|
381
|
+
server.watcher.add(files).on("change", (p) => files.includes(p) && _buildEntry().then(() => startup()));
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
|
|
265
386
|
}
|
|
266
387
|
export {
|
|
267
|
-
|
|
388
|
+
debugStartup,
|
|
389
|
+
electronWithUpdater
|
|
268
390
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"author": "subframe7536",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,22 +45,29 @@
|
|
|
45
45
|
"registry": "https://registry.npmjs.org/"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"esbuild": "*"
|
|
48
|
+
"esbuild": "*",
|
|
49
|
+
"vite-plugin-electron": "^0.15.6 || ^0.28"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"@electron/asar": "^3.2.8",
|
|
52
|
-
"
|
|
53
|
+
"@subframe7536/type-utils": "^0.1.4",
|
|
53
54
|
"selfsigned": "^2.4.1"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@subframe7536/eslint-config": "^0.5.
|
|
57
|
-
"@types/node": "^20.
|
|
58
|
-
"bumpp": "^9.
|
|
59
|
-
"electron": "
|
|
60
|
-
"eslint": "^8.
|
|
57
|
+
"@subframe7536/eslint-config": "^0.5.9",
|
|
58
|
+
"@types/node": "^20.11.5",
|
|
59
|
+
"bumpp": "^9.3.0",
|
|
60
|
+
"electron": "28.1.1",
|
|
61
|
+
"eslint": "^8.56.0",
|
|
61
62
|
"tsup": "^8.0.1",
|
|
62
|
-
"typescript": "^5.3.
|
|
63
|
-
"vite": "^5.0.
|
|
64
|
-
"
|
|
63
|
+
"typescript": "^5.3.3",
|
|
64
|
+
"vite": "^5.0.12",
|
|
65
|
+
"vite-plugin-electron": "^0.15.6",
|
|
66
|
+
"vitest": "^1.2.1"
|
|
67
|
+
},
|
|
68
|
+
"pnpm": {
|
|
69
|
+
"overrides": {
|
|
70
|
+
"has": "npm:@nolyfill/has@latest"
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
}
|
package/dist/chunk-SPZL37O5.mjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-CMBFI77K.mjs";
|
|
4
|
-
|
|
5
|
-
// src/utils/core.ts
|
|
6
|
-
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
7
|
-
import { dirname, join } from "node:path";
|
|
8
|
-
import { release } from "node:os";
|
|
9
|
-
import { app } from "electron";
|
|
10
|
-
var DEFAULT_APP_NAME = "product";
|
|
11
|
-
var is = {
|
|
12
|
-
dev: !app.isPackaged,
|
|
13
|
-
win: process.platform === "win32",
|
|
14
|
-
mac: process.platform === "darwin",
|
|
15
|
-
linux: process.platform === "linux"
|
|
16
|
-
};
|
|
17
|
-
function getLocale() {
|
|
18
|
-
return app.isReady() ? app.getLocale() : void 0;
|
|
19
|
-
}
|
|
20
|
-
function getProductAsarPath(name = DEFAULT_APP_NAME) {
|
|
21
|
-
return !app.isPackaged ? join(dirname(app.getAppPath()), `${name}.asar`) : "DEV.asar";
|
|
22
|
-
}
|
|
23
|
-
function getElectronVersion() {
|
|
24
|
-
return app.getVersion();
|
|
25
|
-
}
|
|
26
|
-
function getAppVersion(name = DEFAULT_APP_NAME) {
|
|
27
|
-
return app.isPackaged ? readFileSync(join(getProductAsarPath(name), "version"), "utf-8") : getElectronVersion();
|
|
28
|
-
}
|
|
29
|
-
var NoSuchNativeModuleError = class extends Error {
|
|
30
|
-
moduleName;
|
|
31
|
-
constructor(moduleName) {
|
|
32
|
-
super(`no such native module: ${moduleName}`);
|
|
33
|
-
this.moduleName = moduleName;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
function isNoSuchNativeModuleError(e) {
|
|
37
|
-
return e instanceof NoSuchNativeModuleError;
|
|
38
|
-
}
|
|
39
|
-
function requireNative(packageName) {
|
|
40
|
-
const path = app.isPackaged ? join(app.getAppPath(), "node_modules", packageName) : packageName;
|
|
41
|
-
try {
|
|
42
|
-
return __require(path);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return new NoSuchNativeModuleError(packageName);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function restartApp() {
|
|
48
|
-
app.relaunch();
|
|
49
|
-
app.quit();
|
|
50
|
-
}
|
|
51
|
-
function setAppUserModelId(id) {
|
|
52
|
-
is.win && app.setAppUserModelId(is.dev ? process.execPath : id);
|
|
53
|
-
}
|
|
54
|
-
function disableHWAccForWin7() {
|
|
55
|
-
if (release().startsWith("6.1")) {
|
|
56
|
-
app.disableHardwareAcceleration();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function singleInstance() {
|
|
60
|
-
if (!app.requestSingleInstanceLock()) {
|
|
61
|
-
app.quit();
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function setPortableAppDataPath(dirName = "data", create) {
|
|
66
|
-
if (!is.win) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const portablePath = join(dirname(app.getPath("exe")), dirName);
|
|
70
|
-
let exists = existsSync(portablePath);
|
|
71
|
-
if (create && !exists) {
|
|
72
|
-
mkdirSync(portablePath);
|
|
73
|
-
exists = true;
|
|
74
|
-
}
|
|
75
|
-
if (exists) {
|
|
76
|
-
app.setPath("appData", portablePath);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function waitAppReady(timeout = 1e3) {
|
|
80
|
-
return app.isReady() ? Promise.resolve() : new Promise((resolve, reject) => {
|
|
81
|
-
const _ = setTimeout(() => {
|
|
82
|
-
reject(new Error("app is not ready"));
|
|
83
|
-
}, timeout);
|
|
84
|
-
app.whenReady().then(() => {
|
|
85
|
-
clearTimeout(_);
|
|
86
|
-
resolve();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/utils/utils.ts
|
|
92
|
-
function parseGithubCdnURL(originRepoURL, cdnPrefix, relativeFilePath) {
|
|
93
|
-
if (!originRepoURL.startsWith("https://github.com/")) {
|
|
94
|
-
throw new Error("origin url must start with https://github.com/");
|
|
95
|
-
}
|
|
96
|
-
originRepoURL = originRepoURL.trim().replace(/\/?$/, "/").trim();
|
|
97
|
-
relativeFilePath = relativeFilePath.trim().replace(/^\/|\/?$/g, "").trim();
|
|
98
|
-
cdnPrefix = cdnPrefix.trim().replace(/^\/?|\/?$/g, "").trim();
|
|
99
|
-
return originRepoURL.replace("github.com", cdnPrefix) + relativeFilePath;
|
|
100
|
-
}
|
|
101
|
-
function handleUnexpectedErrors(callback) {
|
|
102
|
-
process.on("uncaughtException", callback);
|
|
103
|
-
process.on("unhandledRejection", callback);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export {
|
|
107
|
-
DEFAULT_APP_NAME,
|
|
108
|
-
is,
|
|
109
|
-
getLocale,
|
|
110
|
-
getProductAsarPath,
|
|
111
|
-
getElectronVersion,
|
|
112
|
-
getAppVersion,
|
|
113
|
-
NoSuchNativeModuleError,
|
|
114
|
-
isNoSuchNativeModuleError,
|
|
115
|
-
requireNative,
|
|
116
|
-
restartApp,
|
|
117
|
-
setAppUserModelId,
|
|
118
|
-
disableHWAccForWin7,
|
|
119
|
-
singleInstance,
|
|
120
|
-
setPortableAppDataPath,
|
|
121
|
-
waitAppReady,
|
|
122
|
-
parseGithubCdnURL,
|
|
123
|
-
handleUnexpectedErrors
|
|
124
|
-
};
|