electron-incremental-update 0.5.1 → 0.6.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 +7 -7
- package/dist/{chunk-OBERMV66.mjs → chunk-VADH6AZA.mjs} +12 -21
- package/dist/index.cjs +128 -102
- package/dist/index.d.ts +26 -15
- package/dist/index.mjs +118 -94
- package/dist/vite.cjs +71 -48
- package/dist/vite.d.ts +24 -2
- package/dist/vite.mjs +63 -32
- package/package.json +3 -2
package/dist/vite.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
generateRSA,
|
|
3
2
|
signature
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VADH6AZA.mjs";
|
|
5
4
|
|
|
6
5
|
// src/vite.ts
|
|
7
6
|
import { createLogger } from "vite";
|
|
8
7
|
|
|
9
|
-
// src/build-plugins/
|
|
8
|
+
// src/build-plugins/build.ts
|
|
10
9
|
import { createReadStream, createWriteStream } from "node:fs";
|
|
11
10
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
12
11
|
import zlib from "node:zlib";
|
|
12
|
+
import { build } from "esbuild";
|
|
13
13
|
function gzipFile(filePath) {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
15
|
const gzip = zlib.createGzip();
|
|
@@ -46,23 +46,20 @@ async function buildAsar({
|
|
|
46
46
|
await pack(electronDistPath, asarOutputPath);
|
|
47
47
|
await gzipFile(asarOutputPath);
|
|
48
48
|
}
|
|
49
|
-
async function
|
|
49
|
+
async function buildVersion({
|
|
50
50
|
asarOutputPath,
|
|
51
51
|
versionPath,
|
|
52
52
|
privateKey,
|
|
53
|
-
|
|
53
|
+
cert,
|
|
54
54
|
version
|
|
55
55
|
}) {
|
|
56
56
|
const buffer = await readFile(`${asarOutputPath}.gz`);
|
|
57
57
|
await writeFile(versionPath, JSON.stringify({
|
|
58
|
-
signature: signature(buffer, privateKey,
|
|
58
|
+
signature: signature(buffer, privateKey, cert, version),
|
|
59
59
|
version,
|
|
60
60
|
size: buffer.length
|
|
61
61
|
}, null, 2));
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
// src/build-plugins/entry.ts
|
|
65
|
-
import { build } from "esbuild";
|
|
66
63
|
async function buildEntry({
|
|
67
64
|
entryPath,
|
|
68
65
|
entryOutputPath: outfile,
|
|
@@ -82,16 +79,35 @@ async function buildEntry({
|
|
|
82
79
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
83
80
|
import { dirname } from "node:path";
|
|
84
81
|
import { EOL } from "node:os";
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
83
|
+
import { CertificateSigningRequest } from "@cyyynthia/jscert";
|
|
84
|
+
function generateCert(privateKey) {
|
|
85
|
+
const dn = {
|
|
86
|
+
country: "zh-CN",
|
|
87
|
+
state: "zj",
|
|
88
|
+
locality: "hz",
|
|
89
|
+
organization: "test",
|
|
90
|
+
organizationalUnit: "test unit",
|
|
91
|
+
commonName: "test.test",
|
|
92
|
+
emailAddress: "test@example.com"
|
|
93
|
+
};
|
|
94
|
+
const csr = new CertificateSigningRequest(dn, privateKey, { digest: "sha256" });
|
|
95
|
+
const expiry = new Date(Date.now() + 365 * 864e5);
|
|
96
|
+
return csr.createSelfSignedCertificate(expiry).toPem();
|
|
90
97
|
}
|
|
91
|
-
function
|
|
98
|
+
function generateKeys(length = 2048) {
|
|
99
|
+
const { privateKey: _key } = generateKeyPairSync("rsa", { modulusLength: length });
|
|
100
|
+
const cert = generateCert(_key);
|
|
101
|
+
const privateKey = _key.export({ type: "pkcs1", format: "pem" });
|
|
102
|
+
return {
|
|
103
|
+
privateKey,
|
|
104
|
+
cert
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function writeCertToMain(entryPath, cert) {
|
|
92
108
|
const file = readFileSync(entryPath, "utf-8");
|
|
93
|
-
const regex = /const
|
|
94
|
-
const replacement = `const
|
|
109
|
+
const regex = /const SIGNATURE_CERT = ['`][\s\S]*?['`]/;
|
|
110
|
+
const replacement = `const SIGNATURE_CERT = \`${cert}\``;
|
|
95
111
|
let replaced = file;
|
|
96
112
|
const signaturePubExists = regex.test(file);
|
|
97
113
|
if (signaturePubExists) {
|
|
@@ -116,24 +132,26 @@ function writePublicKeyToMain(entryPath, publicKey) {
|
|
|
116
132
|
function getKeys({
|
|
117
133
|
keyLength,
|
|
118
134
|
privateKeyPath,
|
|
119
|
-
|
|
135
|
+
certPath,
|
|
120
136
|
entryPath
|
|
121
137
|
}) {
|
|
122
138
|
const keysDir = dirname(privateKeyPath);
|
|
123
139
|
!existsSync(keysDir) && mkdirSync(keysDir);
|
|
124
|
-
let privateKey,
|
|
125
|
-
if (!existsSync(privateKeyPath)) {
|
|
126
|
-
const keys =
|
|
140
|
+
let privateKey, cert;
|
|
141
|
+
if (!existsSync(privateKeyPath) || !existsSync(certPath)) {
|
|
142
|
+
const keys = generateKeys(keyLength);
|
|
127
143
|
privateKey = keys.privateKey;
|
|
128
|
-
|
|
144
|
+
cert = keys.cert;
|
|
145
|
+
writeFileSync(privateKeyPath, privateKey);
|
|
146
|
+
writeFileSync(certPath, cert);
|
|
129
147
|
} else {
|
|
130
148
|
privateKey = readFileSync(privateKeyPath, "utf-8");
|
|
131
|
-
|
|
149
|
+
cert = readFileSync(certPath, "utf-8");
|
|
132
150
|
}
|
|
133
|
-
|
|
151
|
+
writeCertToMain(entryPath, cert);
|
|
134
152
|
return {
|
|
135
153
|
privateKey,
|
|
136
|
-
|
|
154
|
+
cert
|
|
137
155
|
};
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -151,9 +169,17 @@ function parseOptions(options) {
|
|
|
151
169
|
} = paths;
|
|
152
170
|
const {
|
|
153
171
|
privateKeyPath = "keys/private.pem",
|
|
154
|
-
|
|
155
|
-
keyLength = 2048
|
|
172
|
+
certPath = "keys/cert.pem",
|
|
173
|
+
keyLength = 2048,
|
|
174
|
+
certInfo
|
|
156
175
|
} = keys;
|
|
176
|
+
let {
|
|
177
|
+
subject = {
|
|
178
|
+
commonName: productName,
|
|
179
|
+
organization: `org.${productName}`
|
|
180
|
+
},
|
|
181
|
+
expires = Date.now() + 365 * 864e5
|
|
182
|
+
} = certInfo || {};
|
|
157
183
|
const buildAsarOption = {
|
|
158
184
|
version,
|
|
159
185
|
asarOutputPath,
|
|
@@ -167,17 +193,22 @@ function parseOptions(options) {
|
|
|
167
193
|
};
|
|
168
194
|
let buildVersionOption;
|
|
169
195
|
if (!isCI) {
|
|
170
|
-
|
|
196
|
+
if (typeof expires === "number") {
|
|
197
|
+
expires = new Date(Date.now() + expires);
|
|
198
|
+
}
|
|
199
|
+
const { privateKey, cert } = getKeys({
|
|
171
200
|
keyLength,
|
|
172
201
|
privateKeyPath,
|
|
173
|
-
|
|
174
|
-
entryPath
|
|
202
|
+
certPath,
|
|
203
|
+
entryPath,
|
|
204
|
+
subject,
|
|
205
|
+
expires
|
|
175
206
|
});
|
|
176
207
|
buildVersionOption = {
|
|
177
208
|
version,
|
|
178
209
|
asarOutputPath,
|
|
179
210
|
privateKey,
|
|
180
|
-
|
|
211
|
+
cert,
|
|
181
212
|
versionPath
|
|
182
213
|
};
|
|
183
214
|
}
|
|
@@ -203,7 +234,7 @@ function vite_default(options) {
|
|
|
203
234
|
}
|
|
204
235
|
log.info("build asar start");
|
|
205
236
|
await buildAsar(buildAsarOption);
|
|
206
|
-
buildVersionOption && await
|
|
237
|
+
buildVersionOption && await buildVersion(buildVersionOption);
|
|
207
238
|
log.info(`build asar end, output to ${asarOutputPath}`);
|
|
208
239
|
}
|
|
209
240
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-incremental-update",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "electron incremental update tools, powered by vite",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"vitest": "^0.32.2"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
+
"@cyyynthia/jscert": "^0.1.2",
|
|
64
65
|
"ci-info": "^3.8.0"
|
|
65
66
|
}
|
|
66
|
-
}
|
|
67
|
+
}
|