electron-version-deployer-cli 0.1.0 → 0.1.2
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 +36 -1
- package/dist/main.js +44 -8
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -391,6 +391,7 @@ const _Netlify = class {
|
|
|
391
391
|
if (!configs.netlify.siteID) {
|
|
392
392
|
return `configs.netlify.siteID 未配置`;
|
|
393
393
|
}
|
|
394
|
+
return;
|
|
394
395
|
}
|
|
395
396
|
return `configs.netlify 配置不存在`;
|
|
396
397
|
}
|
|
@@ -408,7 +409,40 @@ const _Cloudflare = class {
|
|
|
408
409
|
var _a;
|
|
409
410
|
return (_a = configs.cloudflare) == null ? void 0 : _a.url;
|
|
410
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
|
+
}
|
|
411
444
|
deploy(props) {
|
|
445
|
+
this.splitFileIfNeed(props.folder);
|
|
412
446
|
const cloudflareConfig = props.configs.cloudflare;
|
|
413
447
|
if (!cloudflareConfig)
|
|
414
448
|
throw new Error("cloudflare 配置为空");
|
|
@@ -448,6 +482,7 @@ const _Cloudflare = class {
|
|
|
448
482
|
if (!configs.cloudflare.projectName) {
|
|
449
483
|
return `configs.cloudflare.projectName 未配置`;
|
|
450
484
|
}
|
|
485
|
+
return;
|
|
451
486
|
}
|
|
452
487
|
return `configs.cloudflare 配置不存在`;
|
|
453
488
|
}
|
|
@@ -568,4 +603,4 @@ async function installPrebuilt(configs) {
|
|
|
568
603
|
}
|
|
569
604
|
commander.program.description(
|
|
570
605
|
"Electron 版本部署 CLI,简化你的 Electron 软件更新,让一切变得简单。"
|
|
571
|
-
).helpOption("-h, --help", "使用帮助").version("0.1.
|
|
606
|
+
).helpOption("-h, --help", "使用帮助").version("0.1.2", "-V, --version", "显示版本号").parse(process.argv);
|
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(
|