feat(edit-docs): clean up ZIP file

pull/1389/head
Elian Doran 2025-03-10 16:31:44 +07:00
parent df2a9aed44
commit bffb0963df
No known key found for this signature in database
1 changed files with 34 additions and 23 deletions

@ -17,29 +17,40 @@ async function exportData() {
const zipFilePath = "output.zip"; const zipFilePath = "output.zip";
const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide"); const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide");
await fsExtra.remove(destRootPath); const deferred = (await import("./src/services/utils.js")).deferred;
await fsExtra.mkdir(destRootPath);
try {
// First export as zip. await fsExtra.remove(destRootPath);
const { exportToZipFile } = (await import("./src/services/export/zip.js")).default; await fsExtra.mkdir(destRootPath);
await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath);
// First export as zip.
setTimeout(async () => { const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;
// Then extract the zip. await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath);
const { readZipFile, readContent } = (await import("./src/services/import/zip.js"));
await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => { const promise = deferred<void>()
// We ignore directories since they can appear out of order anyway. setTimeout(async () => {
if (!entry.fileName.endsWith("/")) { // Then extract the zip.
const destPath = path.join(destRootPath, entry.fileName); const { readZipFile, readContent } = (await import("./src/services/import/zip.js"));
const fileContent = await readContent(zip, entry); await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => {
// We ignore directories since they can appear out of order anyway.
await fsExtra.mkdirs(path.dirname(destPath)); if (!entry.fileName.endsWith("/")) {
await fs.writeFile(destPath, fileContent); const destPath = path.join(destRootPath, entry.fileName);
} const fileContent = await readContent(zip, entry);
zip.readEntry(); await fsExtra.mkdirs(path.dirname(destPath));
}); await fs.writeFile(destPath, fileContent);
}, 1000); }
zip.readEntry();
});
promise.resolve();
}, 1000);
await promise;
} finally {
if (await fsExtra.exists(zipFilePath)) {
await fsExtra.rm(zipFilePath);
}
}
} }
await main(); await main();