From bffb0963dff0243fc81b70278a77c63fdf5e6f83 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 10 Mar 2025 16:31:44 +0200 Subject: [PATCH] feat(edit-docs): clean up ZIP file --- electron-docs-main.ts | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/electron-docs-main.ts b/electron-docs-main.ts index 3c9ab8033..4b3bc0726 100644 --- a/electron-docs-main.ts +++ b/electron-docs-main.ts @@ -17,29 +17,40 @@ async function exportData() { const zipFilePath = "output.zip"; const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide"); - await fsExtra.remove(destRootPath); - await fsExtra.mkdir(destRootPath); + const deferred = (await import("./src/services/utils.js")).deferred; - // First export as zip. - const { exportToZipFile } = (await import("./src/services/export/zip.js")).default; - await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath); + try { + await fsExtra.remove(destRootPath); + await fsExtra.mkdir(destRootPath); - setTimeout(async () => { - // Then extract the zip. - const { readZipFile, readContent } = (await import("./src/services/import/zip.js")); - await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => { - // We ignore directories since they can appear out of order anyway. - if (!entry.fileName.endsWith("/")) { - const destPath = path.join(destRootPath, entry.fileName); - const fileContent = await readContent(zip, entry); + // First export as zip. + const { exportToZipFile } = (await import("./src/services/export/zip.js")).default; + await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath); - await fsExtra.mkdirs(path.dirname(destPath)); - await fs.writeFile(destPath, fileContent); - } + const promise = deferred() + setTimeout(async () => { + // Then extract the zip. + const { readZipFile, readContent } = (await import("./src/services/import/zip.js")); + await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => { + // We ignore directories since they can appear out of order anyway. + if (!entry.fileName.endsWith("/")) { + const destPath = path.join(destRootPath, entry.fileName); + const fileContent = await readContent(zip, entry); - zip.readEntry(); - }); - }, 1000); + await fsExtra.mkdirs(path.dirname(destPath)); + await fs.writeFile(destPath, fileContent); + } + + zip.readEntry(); + }); + promise.resolve(); + }, 1000); + await promise; + } finally { + if (await fsExtra.exists(zipFilePath)) { + await fsExtra.rm(zipFilePath); + } + } } await main();