mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-17 15:42:34 +08:00
feat(edit-demo): unzip demo for easy diffing
This commit is contained in:
parent
827c228cdc
commit
293314b8ef
@ -7,7 +7,7 @@ import { initializeTranslations } from "./src/services/i18n.js";
|
|||||||
import archiver, { type Archiver } from "archiver";
|
import archiver, { type Archiver } from "archiver";
|
||||||
import type { WriteStream } from "fs";
|
import type { WriteStream } from "fs";
|
||||||
import debounce from "./src/public/app/services/debounce.js";
|
import debounce from "./src/public/app/services/debounce.js";
|
||||||
import { importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
import { extractZip, importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
||||||
|
|
||||||
const NOTE_ID_USER_GUIDE = "pOsGYCXsbNQG";
|
const NOTE_ID_USER_GUIDE = "pOsGYCXsbNQG";
|
||||||
const markdownPath = path.join("docs", "User Guide");
|
const markdownPath = path.join("docs", "User Guide");
|
||||||
@ -52,8 +52,6 @@ function waitForEnd(archive: Archiver, stream: WriteStream) {
|
|||||||
async function exportData(format: "html" | "markdown", outputPath: string) {
|
async function exportData(format: "html" | "markdown", outputPath: string) {
|
||||||
const zipFilePath = "output.zip";
|
const zipFilePath = "output.zip";
|
||||||
|
|
||||||
const deferred = (await import("./src/services/utils.js")).deferred;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fsExtra.remove(outputPath);
|
await fsExtra.remove(outputPath);
|
||||||
await fsExtra.mkdir(outputPath);
|
await fsExtra.mkdir(outputPath);
|
||||||
@ -61,26 +59,7 @@ async function exportData(format: "html" | "markdown", outputPath: string) {
|
|||||||
// First export as zip.
|
// First export as zip.
|
||||||
const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;
|
const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;
|
||||||
await exportToZipFile(NOTE_ID_USER_GUIDE, format, zipFilePath);
|
await exportToZipFile(NOTE_ID_USER_GUIDE, format, zipFilePath);
|
||||||
|
await extractZip(zipFilePath, outputPath);
|
||||||
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(outputPath, 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 {
|
} finally {
|
||||||
if (await fsExtra.exists(zipFilePath)) {
|
if (await fsExtra.exists(zipFilePath)) {
|
||||||
await fsExtra.rm(zipFilePath);
|
await fsExtra.rm(zipFilePath);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
import { extractZip, importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
||||||
import { initializeTranslations } from "./src/services/i18n.js";
|
import { initializeTranslations } from "./src/services/i18n.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import debounce from "./src/public/app/services/debounce.js";
|
import debounce from "./src/public/app/services/debounce.js";
|
||||||
@ -24,7 +24,8 @@ async function registerHandlers() {
|
|||||||
console.log("Exporting data");
|
console.log("Exporting data");
|
||||||
eraseService.eraseUnusedAttachmentsNow();
|
eraseService.eraseUnusedAttachmentsNow();
|
||||||
await exportData();
|
await exportData();
|
||||||
}, 10_000);;
|
await extractZip(DEMO_ZIP_PATH, "demo");
|
||||||
|
}, 10_000);
|
||||||
events.subscribe(events.ENTITY_CHANGED, async (e) => {
|
events.subscribe(events.ENTITY_CHANGED, async (e) => {
|
||||||
if (e.entityName === "options") {
|
if (e.entityName === "options") {
|
||||||
return;
|
return;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import cls from "./src/services/cls.js";
|
import cls from "./src/services/cls.js";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import fsExtra from "fs-extra";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
export async function initializeDatabase() {
|
export async function initializeDatabase() {
|
||||||
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
||||||
@ -55,3 +58,27 @@ export function importData(input: Buffer, rootId: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function extractZip(zipFilePath: string, outputPath: string) {
|
||||||
|
const deferred = (await import("./src/services/utils.js")).deferred;
|
||||||
|
|
||||||
|
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(outputPath, 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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user