mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 17:26:38 +01:00
feat(demo): add entrypoint for editing the demo safely
This commit is contained in:
@@ -3,81 +3,25 @@ import fsExtra from "fs-extra";
|
||||
import path from "path";
|
||||
import type NoteMeta from "./src/services/meta/note_meta.js";
|
||||
import type { NoteMetaFile } from "./src/services/meta/note_meta.js";
|
||||
import cls from "./src/services/cls.js";
|
||||
import { initializeTranslations } from "./src/services/i18n.js";
|
||||
import archiver, { type Archiver } from "archiver";
|
||||
import type { WriteStream } from "fs";
|
||||
import debounce from "./src/public/app/services/debounce.js";
|
||||
import { importData, initializeDatabase, startElectron } from "./electron-utils.js";
|
||||
|
||||
const NOTE_ID_USER_GUIDE = "pOsGYCXsbNQG";
|
||||
const markdownPath = path.join("docs", "User Guide");
|
||||
const htmlPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide");
|
||||
|
||||
async function startElectron() {
|
||||
await import("./electron-main.js");
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await initializeTranslations();
|
||||
const zipBuffer = await createImportZip();
|
||||
await initializeDatabase();
|
||||
await importData(zipBuffer);
|
||||
await importData(zipBuffer, NOTE_ID_USER_GUIDE);
|
||||
await startElectron();
|
||||
await registerHandlers();
|
||||
}
|
||||
|
||||
async function initializeDatabase() {
|
||||
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
||||
|
||||
cls.init(() => {
|
||||
if (!sqlInit.isDbInitialized()) {
|
||||
sqlInit.createInitialDatabase();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function importData(input: Buffer) {
|
||||
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(NOTE_ID_USER_GUIDE);
|
||||
if (existingNote) {
|
||||
existingNote.deleteNote(deleteId);
|
||||
}
|
||||
eraseService.eraseNotesWithDeleteId(deleteId);
|
||||
|
||||
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
|
||||
parentNoteId: "root",
|
||||
noteId: NOTE_ID_USER_GUIDE,
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async function createImportZip() {
|
||||
const inputFile = "input.zip";
|
||||
const archive = archiver("zip", {
|
||||
|
||||
Reference in New Issue
Block a user