Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(edit-docs): clean up ZIP file
Elian Doranbffb0963dff0
diff --git a/electron-docs-main.ts b/electron-docs-main.tsindex 3c9ab8033e..4b3bc07261 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);-- // First export as zip.- const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;- await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath);-- 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);-- await fsExtra.mkdirs(path.dirname(destPath));- await fs.writeFile(destPath, fileContent);- }-- zip.readEntry();- });- }, 1000);+ const deferred = (await import("./src/services/utils.js")).deferred;++ try {+ await fsExtra.remove(destRootPath);+ await fsExtra.mkdir(destRootPath);++ // First export as zip.+ const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;+ await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath);++ const promise = deferred<void>()+ 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);++ 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();