electron-version-deployer-cli 0.1.1 → 0.1.3
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/cli.cjs +34 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.js +44 -8
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -409,7 +409,40 @@ const _Cloudflare = class {
|
|
|
409
409
|
var _a;
|
|
410
410
|
return (_a = configs.cloudflare) == null ? void 0 : _a.url;
|
|
411
411
|
}
|
|
412
|
+
// 由于 cloudflare 限制了文件最大只能为 25m
|
|
413
|
+
// 判断文件夹下面的 fullCode.zip 是否超过 25m 如果超过就进行分割
|
|
414
|
+
splitFileIfNeed(folderPath) {
|
|
415
|
+
const fullCodeZipPath = node_path.join(folderPath, "fullCode.zip");
|
|
416
|
+
const fileStats = node_fs.statSync(fullCodeZipPath);
|
|
417
|
+
const fileSize = fileStats.size;
|
|
418
|
+
const fileSizeInMB = fileSize / (1024 * 1024);
|
|
419
|
+
const outputFolder = node_path.join(folderPath, "fullCodeZipSplitZips");
|
|
420
|
+
!node_fs.existsSync(outputFolder) && node_fs.mkdirSync(outputFolder);
|
|
421
|
+
if (fileSizeInMB < 24)
|
|
422
|
+
return;
|
|
423
|
+
const SPLIT_SIZE = 20;
|
|
424
|
+
const chunkCount = Math.ceil(fileSizeInMB / SPLIT_SIZE);
|
|
425
|
+
const splitZipsFileName = [];
|
|
426
|
+
const fileBuffer = node_fs.readFileSync(fullCodeZipPath);
|
|
427
|
+
const fileName = fullCodeZipPath.split("/").pop().split(".");
|
|
428
|
+
const fileExtension = fileName.pop();
|
|
429
|
+
const baseFileName = fileName.join(".");
|
|
430
|
+
for (let i = 0; i < chunkCount; i++) {
|
|
431
|
+
const start = i * SPLIT_SIZE * 1024 * 1024;
|
|
432
|
+
const end = Math.min((i + 1) * SPLIT_SIZE * 1024 * 1024, fileSize);
|
|
433
|
+
const chunkBuffer = fileBuffer.slice(start, end);
|
|
434
|
+
const chunkFileName = `${baseFileName}.part${i + 1}.${fileExtension}`;
|
|
435
|
+
splitZipsFileName.push(chunkFileName);
|
|
436
|
+
node_fs.writeFileSync(node_path.join(outputFolder, chunkFileName), chunkBuffer);
|
|
437
|
+
}
|
|
438
|
+
node_fs.writeFileSync(
|
|
439
|
+
node_path.join(outputFolder, "index.json"),
|
|
440
|
+
JSON.stringify(splitZipsFileName)
|
|
441
|
+
);
|
|
442
|
+
node_fs.unlinkSync(node_path.join(folderPath, "fullCode.zip"));
|
|
443
|
+
}
|
|
412
444
|
deploy(props) {
|
|
445
|
+
this.splitFileIfNeed(props.folder);
|
|
413
446
|
const cloudflareConfig = props.configs.cloudflare;
|
|
414
447
|
if (!cloudflareConfig)
|
|
415
448
|
throw new Error("cloudflare 配置为空");
|
|
@@ -570,4 +603,4 @@ async function installPrebuilt(configs) {
|
|
|
570
603
|
}
|
|
571
604
|
commander.program.description(
|
|
572
605
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
573
|
-
).helpOption("-h, --help", "使用帮助").version("0.1.
|
|
606
|
+
).helpOption("-h, --help", "使用帮助").version("0.1.3", "-V, --version", "显示版本号").parse(process.argv);
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -215,18 +215,54 @@ async function installPkg(zipFile) {
|
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
node_fs.mkdirSync(unzipPath);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
await new Promise(async (res, rej) => {
|
|
219
|
+
let fullCodeSplitIndexFile = false;
|
|
220
|
+
try {
|
|
221
|
+
const request = await fetch(
|
|
222
|
+
`${remoteUrl}/fullCodeZipSplitZips/index.json`
|
|
223
|
+
);
|
|
224
|
+
fullCodeSplitIndexFile = await request.json();
|
|
225
|
+
} catch (e) {
|
|
226
|
+
}
|
|
227
|
+
if (zipFile === "fullCode.zip" && fullCodeSplitIndexFile) {
|
|
228
|
+
const mergedStream = node_fs.createWriteStream(unzipPath + ".zip");
|
|
229
|
+
for (let fileName of fullCodeSplitIndexFile) {
|
|
230
|
+
const tmpFilePath = node_path.join(appPath, fileName);
|
|
231
|
+
const tmpSplitZip = node_fs.createWriteStream(tmpFilePath);
|
|
232
|
+
await new Promise((_res) => {
|
|
233
|
+
node_https.get(`${remoteUrl}/fullCodeZipSplitZips/${fileName}`, (response) => {
|
|
234
|
+
response.pipe(tmpSplitZip).on("finish", () => {
|
|
235
|
+
tmpSplitZip.end(() => {
|
|
236
|
+
mergedStream.write(node_fs.readFileSync(tmpFilePath));
|
|
237
|
+
_res();
|
|
238
|
+
});
|
|
239
|
+
}).on("error", (err) => {
|
|
240
|
+
rej(err);
|
|
241
|
+
});
|
|
242
|
+
}).on("error", (err) => {
|
|
243
|
+
rej(err);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
node_fs.unlinkSync(tmpFilePath);
|
|
247
|
+
}
|
|
248
|
+
mergedStream.end(() => {
|
|
222
249
|
res();
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
const tmpZipFilePath = node_fs.createWriteStream(unzipPath + ".zip");
|
|
253
|
+
node_https.get(`${remoteUrl}/${zipFile}`, (response) => {
|
|
254
|
+
response.pipe(tmpZipFilePath).on("finish", () => {
|
|
255
|
+
tmpZipFilePath.end(() => {
|
|
256
|
+
res();
|
|
257
|
+
});
|
|
258
|
+
}).on("error", (err) => {
|
|
259
|
+
rej(err);
|
|
260
|
+
});
|
|
223
261
|
}).on("error", (err) => {
|
|
224
262
|
rej(err);
|
|
225
263
|
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
})
|
|
229
|
-
);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
230
266
|
await extract(unzipPath + ".zip", { dir: unzipPath });
|
|
231
267
|
await new Promise((res) => setTimeout(res, 1e3));
|
|
232
268
|
node_fs.writeFileSync(
|