electron-version-deployer-cli 0.1.5 → 0.1.6
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 +234 -0
- package/dist/cli.cjs +12 -3
- package/dist/main.js +3 -3
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# electron-version-deployer-cli
|
|
2
|
+
|
|
3
|
+
electron 版本版本更新命令行
|
|
4
|
+
|
|
5
|
+
# 目的
|
|
6
|
+
|
|
7
|
+
1. 减少每次版本更新包的大小,最理想的情况是每次只更新修改的代码,而不是整个软件.
|
|
8
|
+
2. 快速更新而不需要经过任何商店审核
|
|
9
|
+
|
|
10
|
+
# 实现原理
|
|
11
|
+
|
|
12
|
+
[部署流程](https://mermaid.live/edit#pako:eNqdkd1KAkEYhm9lmCMj8wI8CMJfoqM63JUYdsfV3B9ZdwtxBaMiJSHEsKigoiBPRJGQhU27md3Z9S4aG4WNPGqO5vned96Z75saFDQRwzjMy9qJUEC6Afb2eRXQtcP5n71g2AmmQ9eZ5MDW1jZI1Eir67UvXOfVfz6tM2NiIVlMmDecYNZhsgWSXMS1neDrwe9fbRJ7TJ66DMI2nlfLSCghCceOKpq6kfubSloN8thapab-kUpRpY0eKppoyrjy-5Jg6HjXvUQBqRKWNckCaS4irGjNo5gfhPMtkOEi69pI_swty3mDO3Iz85oj1_4gtxP__hzE8LEISO-STte1B0t_ivkZpMOQCUN2OZ334KU9P-v707HXmbrOmwV2uSU3R0DFhlzMV2k0OwWjUMG6gooi_fHaosZDo4AVzMM43YpIL_GQV-vUh0xDO6iqAowbuomj0CyLyMDJIpJ0pLBi_Run1P63)
|
|
13
|
+
|
|
14
|
+
[检测更新流程](https://mermaid.live/edit#pako:eNp1kstO6zAQhl9l5C2UB8iim7Bmk202VuIWQ5rkJM4CEBJCXEIJt6MedKAVFSAu4tYiIVEQFS-TccqKV8BRqSASeGXN_8381j9eIJZnM6KRkP2JmGuxSU6rAa2Zrk8DwS3uU1eADjQEvDuR8WN23SlqRq7J1hbWj_Hg0nRBHb1ULo_pGgzWr7B-KZsPcr8rT5dk--ybbii98yjvl8Gn1iytsomZ0HOHgFEqlUv5gNcGNo9-AHQF5A7YeZKdhmzdYKuLfxOYYsLhlTlIe_VCF2QbsaKywxVMnjG-fn9J0t7moN9Pe1u4m6g6zHMfMFkdzp_yBIOAV6cFeBXIjc6X5VGrODPt3eaNNvOZa6vwOFMp7exljXb6vIY7_zHZx-790AcqkeMYfJ5NKJ_fPHbPMT745B2vyi1dLSf86hjl9okUXmwo7VtkBW2U1uDiFLc3Me4C9X3ImnfY__dF5N1v6yoOteFhlYyTGgtqlNvqhyzkNZOIaVZjJtHU1abBrElMd1FxNBKeMedaRBNBxMZJ5NtUjH4T0SrUCdniB57VDHA)
|
|
15
|
+
|
|
16
|
+
# 安装
|
|
17
|
+
|
|
18
|
+
首先在你项目的根目录(与 package.json 同级)运行
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
$ npm install electron-version-deployer-cli
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
注意 ⚠️,我们需要将它安装在 `dependencies` 下,因此请不要添加额外参数。
|
|
25
|
+
|
|
26
|
+
# 使用
|
|
27
|
+
|
|
28
|
+
## 添加依赖包
|
|
29
|
+
|
|
30
|
+
添加一下包到你的 `devDependencies` 中
|
|
31
|
+
|
|
32
|
+
> 添加后,可能会有些包出现重复,手动删下就行了(编译器会有提示)
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"@inquirer/prompts": "^1.2.3",
|
|
37
|
+
"changelog-parser": "^3.0.1",
|
|
38
|
+
"commander": "^10.0.1",
|
|
39
|
+
"dompurify": "^3.0.3",
|
|
40
|
+
"download": "^8.0.0",
|
|
41
|
+
"electron": ">=10.0.0",
|
|
42
|
+
"esno": "^0.16.3",
|
|
43
|
+
"jsdom": "^22.1.0",
|
|
44
|
+
"log-symbols": "=4.1.0",
|
|
45
|
+
"marked": "^5.0.4",
|
|
46
|
+
"netlify-cli": "^15.2.0",
|
|
47
|
+
"vite": "^4.3.9",
|
|
48
|
+
"wrangler": "^3.3.0"
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> 由于我们需要在主进程里面调用 `electron-version-deployer-cli` 的检测自动更新逻辑,如果把依赖的包都放到 `dependencies`, 那么你的软件编译后也会附带这些依赖包,这是完全没有必要的。因此需要手动添加下
|
|
53
|
+
|
|
54
|
+
## 使用
|
|
55
|
+
|
|
56
|
+
### 主进程添加自动更新检测
|
|
57
|
+
|
|
58
|
+
在你的主进程中,添加以下代码, 来实现更新检测
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// main.js
|
|
62
|
+
import { EVDInit } from "electron-version-deployer-cli/dist/main";
|
|
63
|
+
|
|
64
|
+
EVDInit({
|
|
65
|
+
remoteUrl: import.meta.env.REMOTE_URL,
|
|
66
|
+
logo: `file://${join(
|
|
67
|
+
app.getAppPath(),
|
|
68
|
+
"packages",
|
|
69
|
+
"main",
|
|
70
|
+
"dist",
|
|
71
|
+
"icon.png"
|
|
72
|
+
)}`,
|
|
73
|
+
onError(error) {
|
|
74
|
+
// 记录更新检测遇到的错误
|
|
75
|
+
writeError(error, "evd");
|
|
76
|
+
},
|
|
77
|
+
onBeforeNewPkgInstall(next, version:string) {
|
|
78
|
+
// window 下如果某些程序正在使用 node_modules 会导致
|
|
79
|
+
// Error: EBUSY: resource busy or locked 错误
|
|
80
|
+
|
|
81
|
+
// 因此在安装前, 你可以手动关闭这些程序
|
|
82
|
+
DB.close();
|
|
83
|
+
|
|
84
|
+
// 执行 next 方法,继续安装
|
|
85
|
+
next();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
EVDInit 方法接受的参数如下
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
type EVDInitPropsType = {
|
|
94
|
+
// 检测远程更新的地址
|
|
95
|
+
remoteUrl: string;
|
|
96
|
+
|
|
97
|
+
// 弹窗宽度
|
|
98
|
+
windowWidth?: number;
|
|
99
|
+
// 弹窗高度
|
|
100
|
+
windowHeight?: number;
|
|
101
|
+
// logo 图标
|
|
102
|
+
logo?: string;
|
|
103
|
+
// 检测频率/s
|
|
104
|
+
detectionFrequency?: number;
|
|
105
|
+
// 是否在程序开始运行时进行检测
|
|
106
|
+
detectAtStart?: boolean;
|
|
107
|
+
// 当自动更新出现错误时的回掉
|
|
108
|
+
onError?: (err: unknown) => void;
|
|
109
|
+
onBeforeNewPkgInstall?: (next: () => any) => void;
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> 一下命令全部必须在项目根目录执行 (与 package.json 同级)
|
|
114
|
+
|
|
115
|
+
### 初始化配置
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
# 进入命令行交互模式
|
|
119
|
+
$ evd init
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
该命令主要是生成一个 evd.config.js 的配置文件。
|
|
123
|
+
|
|
124
|
+
> ⚠️ 如果你根目录下已经有了这个文件,就不需要再执行了
|
|
125
|
+
|
|
126
|
+
## 配置项
|
|
127
|
+
|
|
128
|
+
> 如果你用 typescript 是有完全的提示的
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
export type PrebuiltConfigType = Record<
|
|
132
|
+
string,
|
|
133
|
+
{ files: string[]; outputPath: string[] }
|
|
134
|
+
>;
|
|
135
|
+
|
|
136
|
+
export type EVDConfigType = {
|
|
137
|
+
// 编译命令, 如 pack-mac
|
|
138
|
+
// 在部署前,需要从编译后的软件里面,获取逻辑代码
|
|
139
|
+
compileCommand: string;
|
|
140
|
+
// CHANGELOG.md 文件位置,用于读取显示给用户此次版本更新的内容
|
|
141
|
+
changelogsPath: string;
|
|
142
|
+
// 编译后的源文件位置
|
|
143
|
+
sources: {
|
|
144
|
+
// 源文件目录, 编译后的 软件名称.app/Contents/Resources/app 文件夹
|
|
145
|
+
folder: string;
|
|
146
|
+
// node_modules 路径(相对 folder)
|
|
147
|
+
nodeModules: string;
|
|
148
|
+
// 逻辑代码路径(相对 folder)
|
|
149
|
+
codes: string;
|
|
150
|
+
// package.json 文件路径(相对 folder)
|
|
151
|
+
packageJSON: string;
|
|
152
|
+
};
|
|
153
|
+
// netlify 部署设置
|
|
154
|
+
netlify?: {
|
|
155
|
+
// 网站域名如 https://site.netlify.app
|
|
156
|
+
url: string;
|
|
157
|
+
token: string;
|
|
158
|
+
siteID: string;
|
|
159
|
+
};
|
|
160
|
+
cloudflare?: {
|
|
161
|
+
url: string;
|
|
162
|
+
token: string;
|
|
163
|
+
projectName: string;
|
|
164
|
+
};
|
|
165
|
+
prebuiltConfig: PrebuiltConfigType;
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 更新版本
|
|
170
|
+
|
|
171
|
+
如果你要更新一个版本,需要执行一下两个步骤
|
|
172
|
+
|
|
173
|
+
### 编译
|
|
174
|
+
|
|
175
|
+
```shell
|
|
176
|
+
$ evd prepare
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
这个命令首先对软件进行编译,然后将一些代码和 changelog 放到 .evd 文件夹中
|
|
180
|
+
|
|
181
|
+
### 部署
|
|
182
|
+
|
|
183
|
+
```shell
|
|
184
|
+
$ evd deploy
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
这个命令主要是把 .evd 文件夹部署到 netlity 上,并且对远程版本号,和当前版本号进行多方面的判断,尽量避免误操作问题
|
|
188
|
+
|
|
189
|
+
### 手动检查版本更新
|
|
190
|
+
|
|
191
|
+
如果你想要通过 **编程** 的方式,检测版本更新,可以使用 `EVDCheckUpdate` 这个方法
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// main.ts
|
|
195
|
+
import { EVDCheckUpdate } from "electron-version-deployer-cli/dist/main";
|
|
196
|
+
|
|
197
|
+
// 如果有新版本,isHaveNewVersion 返回的就是 false,否则是 true
|
|
198
|
+
// 如果有新版本,它会自动打开更新框
|
|
199
|
+
EVDCheckUpdate().then((isHaveNewVersion: boolean) => {
|
|
200
|
+
if (!isHaveNewVersion) {
|
|
201
|
+
IPC.send("showMessage", "success", "当前已是最新版本!");
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 安装预构建
|
|
207
|
+
|
|
208
|
+
某些依赖包需要预构建才能在不同平台上执行,比如 sqlite3,这样才能保证用户更新 node_modules 不会出现预构建找不到而导致的报错问题
|
|
209
|
+
|
|
210
|
+
比如我们要配置 sqlite3 的预构建
|
|
211
|
+
只需要添加 `configs.prebuiltConfig` 即可
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"prebuiltConfig": {
|
|
216
|
+
"sqlite3": {
|
|
217
|
+
"files": [
|
|
218
|
+
"napi-v6-darwin-unknown-arm64.tar.gz",
|
|
219
|
+
"napi-v6-darwin-unknown-x64.tar.gz",
|
|
220
|
+
"napi-v6-win32-unknown-x64.tar.gz"
|
|
221
|
+
],
|
|
222
|
+
"outputPath": ["lib", "binding"]
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
其中 files 是你需要安装的 prebuilt 版本。 outputPath 是你需要将这些与构建版本放到 sqlite3 的那个目录下,上面的配置会把这些预构建的 `.gz` 文件放到 `node_modules/sqlite3/lib/binding` 目录下面去
|
|
229
|
+
|
|
230
|
+
配置完后,只需要执行以下命令,他就会自动安装了
|
|
231
|
+
|
|
232
|
+
```shell
|
|
233
|
+
evd install-prebuilt
|
|
234
|
+
```
|
package/dist/cli.cjs
CHANGED
|
@@ -368,7 +368,8 @@ const _Netlify = class {
|
|
|
368
368
|
"--prod",
|
|
369
369
|
"--debug"
|
|
370
370
|
], {
|
|
371
|
-
stdio: ["pipe", "inherit", "inherit"]
|
|
371
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
372
|
+
shell: true
|
|
372
373
|
});
|
|
373
374
|
output.on("exit", function(code) {
|
|
374
375
|
if (code === 0) {
|
|
@@ -417,7 +418,14 @@ const _Cloudflare = class {
|
|
|
417
418
|
const fileSize = fileStats.size;
|
|
418
419
|
const fileSizeInMB = fileSize / (1024 * 1024);
|
|
419
420
|
const outputFolder = node_path.join(folderPath, "fullCodeZipSplitZips");
|
|
420
|
-
|
|
421
|
+
if (node_fs.existsSync(outputFolder)) {
|
|
422
|
+
node_fs.rmSync(outputFolder, {
|
|
423
|
+
force: true,
|
|
424
|
+
maxRetries: 3,
|
|
425
|
+
recursive: true
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
node_fs.mkdirSync(outputFolder);
|
|
421
429
|
if (fileSizeInMB < 24)
|
|
422
430
|
return;
|
|
423
431
|
const SPLIT_SIZE = 20;
|
|
@@ -458,6 +466,7 @@ const _Cloudflare = class {
|
|
|
458
466
|
"main"
|
|
459
467
|
], {
|
|
460
468
|
stdio: ["pipe", "inherit", "inherit"],
|
|
469
|
+
shell: true,
|
|
461
470
|
env: {
|
|
462
471
|
...process.env,
|
|
463
472
|
"CLOUDFLARE_API_TOKEN": cloudflareConfig.token
|
|
@@ -605,4 +614,4 @@ async function installPrebuilt(configs) {
|
|
|
605
614
|
}
|
|
606
615
|
commander.program.description(
|
|
607
616
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
608
|
-
).helpOption("-h, --help", "使用帮助").version("0.1.
|
|
617
|
+
).helpOption("-h, --help", "使用帮助").version("0.1.6", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.js
CHANGED
|
@@ -219,7 +219,7 @@ async function installPkg(zipFile) {
|
|
|
219
219
|
let fullCodeSplitIndexFile = false;
|
|
220
220
|
try {
|
|
221
221
|
const request = await fetch(
|
|
222
|
-
`${remoteUrl}/fullCodeZipSplitZips/index.json`
|
|
222
|
+
`${remoteUrl}/fullCodeZipSplitZips/index.json?hash=${Math.random()}`
|
|
223
223
|
);
|
|
224
224
|
fullCodeSplitIndexFile = await request.json();
|
|
225
225
|
} catch (e) {
|
|
@@ -230,7 +230,7 @@ async function installPkg(zipFile) {
|
|
|
230
230
|
const tmpFilePath = node_path.join(appPath, fileName);
|
|
231
231
|
const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
|
|
232
232
|
await new Promise((_res) => {
|
|
233
|
-
node_https.get(`${remoteUrl}/fullCodeZipSplitZips/${fileName}`, (response) => {
|
|
233
|
+
node_https.get(`${remoteUrl}/fullCodeZipSplitZips/${fileName}?hash=${Math.random()}`, (response) => {
|
|
234
234
|
response.pipe(tmpSplitZip).on("finish", () => {
|
|
235
235
|
tmpSplitZip.end(() => {
|
|
236
236
|
mergedStream.write(node_fs.readFileSync(tmpFilePath));
|
|
@@ -250,7 +250,7 @@ async function installPkg(zipFile) {
|
|
|
250
250
|
});
|
|
251
251
|
} else {
|
|
252
252
|
const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
|
|
253
|
-
node_https.get(`${remoteUrl}/${zipFile}`, (response) => {
|
|
253
|
+
node_https.get(`${remoteUrl}/${zipFile}?hash=${Math.random()}`, (response) => {
|
|
254
254
|
response.pipe(tmpZipFilePath).on("finish", () => {
|
|
255
255
|
tmpZipFilePath.end(() => {
|
|
256
256
|
res();
|