mirror of https://github.com/TriliumNext/Notes
feat(demo): add entrypoint for editing the demo safely
parent
78c8b17e33
commit
827c228cdc
@ -0,0 +1,43 @@
|
|||||||
|
import { importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
||||||
|
import { initializeTranslations } from "./src/services/i18n.js";
|
||||||
|
import fs from "fs";
|
||||||
|
import debounce from "./src/public/app/services/debounce.js";
|
||||||
|
|
||||||
|
const DEMO_NOTE_ID = "demo";
|
||||||
|
const DEMO_ZIP_PATH = "db/demo.zip";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await initializeTranslations();
|
||||||
|
await initializeDatabase();
|
||||||
|
|
||||||
|
const demoBuffer = fs.readFileSync(DEMO_ZIP_PATH);
|
||||||
|
await importData(demoBuffer, DEMO_NOTE_ID);
|
||||||
|
|
||||||
|
await startElectron();
|
||||||
|
await registerHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function registerHandlers() {
|
||||||
|
const events = (await import("./src/services/events.js")).default;
|
||||||
|
const eraseService = (await import("./src/services/erase.js")).default;
|
||||||
|
const debouncer = debounce(async () => {
|
||||||
|
console.log("Exporting data");
|
||||||
|
eraseService.eraseUnusedAttachmentsNow();
|
||||||
|
await exportData();
|
||||||
|
}, 10_000);;
|
||||||
|
events.subscribe(events.ENTITY_CHANGED, async (e) => {
|
||||||
|
if (e.entityName === "options") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Got entity changed ", e);
|
||||||
|
debouncer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportData() {
|
||||||
|
const { exportToZipFile } = (await import("./src/services/export/zip.js")).default;
|
||||||
|
await exportToZipFile(DEMO_NOTE_ID, "html", DEMO_ZIP_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
await main();
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
import cls from "./src/services/cls.js";
|
||||||
|
|
||||||
|
export async function initializeDatabase() {
|
||||||
|
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
||||||
|
|
||||||
|
cls.init(() => {
|
||||||
|
if (!sqlInit.isDbInitialized()) {
|
||||||
|
sqlInit.createInitialDatabase();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function startElectron() {
|
||||||
|
await import("./electron-main.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function importData(input: Buffer, rootId: string) {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
cls.init(async () => {
|
||||||
|
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
|
||||||
|
const notes = ((await import("./src/services/notes.js")).default);
|
||||||
|
beccaLoader.load();
|
||||||
|
const becca = ((await import("./src/becca/becca.js")).default);
|
||||||
|
const utils = ((await import("./src/services/utils.js")).default);
|
||||||
|
const eraseService = ((await import("./src/services/erase.js")).default);
|
||||||
|
const deleteId = utils.randomString(10);
|
||||||
|
|
||||||
|
const existingNote = becca.getNote(rootId);
|
||||||
|
if (existingNote) {
|
||||||
|
existingNote.deleteNote(deleteId);
|
||||||
|
}
|
||||||
|
eraseService.eraseNotesWithDeleteId(deleteId);
|
||||||
|
|
||||||
|
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
|
||||||
|
parentNoteId: "root",
|
||||||
|
noteId: rootId,
|
||||||
|
title: "User Guide",
|
||||||
|
content: "The sub-children of this note are automatically synced.",
|
||||||
|
type: "text"
|
||||||
|
});
|
||||||
|
|
||||||
|
const TaskContext = (await import("./src/services/task_context.js")).default;
|
||||||
|
const { importZip } = ((await import("./src/services/import/zip.js")).default);
|
||||||
|
const context = new TaskContext("no-report");
|
||||||
|
await importZip(context, input, note, { preserveIds: true });
|
||||||
|
|
||||||
|
const { runOnDemandChecks } = (await import("./src/services/consistency_checks.js")).default;
|
||||||
|
await runOnDemandChecks(true);
|
||||||
|
|
||||||
|
becca.reset();
|
||||||
|
beccaLoader.load();
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue