electron-incremental-update 0.7.7 → 0.7.8

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/vite.mjs CHANGED
@@ -1,15 +1,18 @@
1
1
  import {
2
+ isUpdateJSON,
2
3
  signature
3
- } from "./chunk-Q2K52LOG.mjs";
4
+ } from "./chunk-2XHZMWRR.mjs";
4
5
  import {
6
+ parseVersion,
5
7
  zipFile
6
- } from "./chunk-67MCNA7W.mjs";
8
+ } from "./chunk-SWXNCK6H.mjs";
7
9
 
8
10
  // src/vite.ts
9
11
  import { createLogger } from "vite";
10
12
 
11
13
  // src/build-plugins/build.ts
12
14
  import { readFile, rename, writeFile } from "node:fs/promises";
15
+ import { existsSync } from "node:fs";
13
16
  import { createPackage } from "@electron/asar";
14
17
  import { build } from "esbuild";
15
18
  async function buildAsar({
@@ -30,15 +33,51 @@ async function buildVersion({
30
33
  privateKey,
31
34
  cert,
32
35
  version,
33
- generateSignature
36
+ minimumVersion,
37
+ generateSignature,
38
+ generateVersionJson
34
39
  }) {
40
+ let _json = {
41
+ beta: {
42
+ minimumVersion: version,
43
+ signature: "",
44
+ size: 0,
45
+ version
46
+ },
47
+ minimumVersion: version,
48
+ signature: "",
49
+ size: 0,
50
+ version
51
+ };
52
+ if (existsSync(versionPath)) {
53
+ try {
54
+ _json = JSON.parse(await readFile(versionPath, "utf-8"));
55
+ } catch (error) {
56
+ }
57
+ }
58
+ if (!isUpdateJSON(_json)) {
59
+ throw new Error("invalid version file");
60
+ }
35
61
  const buffer = await readFile(gzipPath);
36
- const _func = generateSignature ?? signature;
37
- await writeFile(versionPath, JSON.stringify({
38
- signature: _func(buffer, privateKey, cert, version),
39
- version,
40
- size: buffer.length
41
- }, null, 2));
62
+ const sig = await (generateSignature ?? signature)(buffer, privateKey, cert, version);
63
+ if (generateVersionJson) {
64
+ _json = await generateVersionJson(_json, buffer, sig, version, minimumVersion);
65
+ if (!isUpdateJSON(_json)) {
66
+ throw new Error("invalid version info");
67
+ }
68
+ } else {
69
+ _json.beta.version = version;
70
+ _json.beta.minimumVersion = minimumVersion;
71
+ _json.beta.signature = sig;
72
+ _json.beta.size = buffer.length;
73
+ if (!parseVersion(version).stage) {
74
+ _json.version = version;
75
+ _json.minimumVersion = minimumVersion;
76
+ _json.signature = sig;
77
+ _json.size = buffer.length;
78
+ }
79
+ }
80
+ await writeFile(versionPath, JSON.stringify(_json, null, 2));
42
81
  }
43
82
  async function buildEntry({
44
83
  entryPath,
@@ -59,15 +98,15 @@ async function buildEntry({
59
98
  import { isCI } from "ci-info";
60
99
 
61
100
  // src/build-plugins/key.ts
62
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
101
+ import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
63
102
  import { dirname } from "node:path";
64
103
  import { EOL } from "node:os";
65
104
  import { generate } from "selfsigned";
66
105
  function generateKeyPair(keyLength, subject, days, privateKeyPath, certPath) {
67
106
  const privateKeyDir = dirname(privateKeyPath);
68
- existsSync(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
107
+ existsSync2(privateKeyDir) || mkdirSync(privateKeyDir, { recursive: true });
69
108
  const certDir = dirname(certPath);
70
- existsSync(certDir) || mkdirSync(certDir, { recursive: true });
109
+ existsSync2(certDir) || mkdirSync(certDir, { recursive: true });
71
110
  const { cert, private: privateKey } = generate(subject, {
72
111
  keySize: keyLength,
73
112
  algorithm: "sha256",
@@ -110,8 +149,8 @@ function parseKeys({
110
149
  days
111
150
  }) {
112
151
  const keysDir = dirname(privateKeyPath);
113
- !existsSync(keysDir) && mkdirSync(keysDir);
114
- if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
152
+ !existsSync2(keysDir) && mkdirSync(keysDir);
153
+ if (!existsSync2(privateKeyPath) || !existsSync2(certPath)) {
115
154
  generateKeyPair(keyLength, parseSubjects(subject), days, privateKeyPath, certPath);
116
155
  }
117
156
  const privateKey = readFileSync(privateKeyPath, "utf-8");
@@ -137,6 +176,7 @@ function parseOptions(options) {
137
176
  isBuild,
138
177
  productName,
139
178
  version,
179
+ minimumVersion = version,
140
180
  minify = false,
141
181
  paths: {
142
182
  entryPath = "electron/app.ts",
@@ -155,7 +195,7 @@ function parseOptions(options) {
155
195
  overrideFunctions = {}
156
196
  } = {}
157
197
  } = options;
158
- const { generateSignature } = overrideFunctions;
198
+ const { generateSignature, generateVersionJson } = overrideFunctions;
159
199
  let {
160
200
  subject = {
161
201
  commonName: productName,
@@ -187,11 +227,13 @@ function parseOptions(options) {
187
227
  });
188
228
  buildVersionOption = {
189
229
  version,
230
+ minimumVersion,
190
231
  gzipPath,
191
232
  privateKey,
192
233
  cert,
193
234
  versionPath,
194
- generateSignature
235
+ generateSignature,
236
+ generateVersionJson
195
237
  };
196
238
  }
197
239
  return { isBuild, buildAsarOption, buildEntryOption, buildVersionOption };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "author": "subframe7536",
4
- "version": "0.7.7",
4
+ "version": "0.7.8",
5
5
  "description": "electron incremental update tools, powered by vite",
6
6
  "scripts": {
7
7
  "build": "tsup && node fix-module.js",