UNPKG

@notatki/cli

Version:

A collection of tools for creating and syncing Anki notes from simple text files.

37 lines 1.47 kB
import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { exportNotes, NoteParser } from "@notatki/core"; import { generatePreview } from "@notatki/preview"; import { findNoteFiles } from "./io.js"; export async function exportCmd({ dir, out, preview }) { const parser = new NoteParser(); console.log(`Scanning directory "${dir}"...`); const { notePaths, modelPaths } = await findNoteFiles(dir); for (const path of modelPaths) { console.log(`Parsing models file "${path}"...`); const text = await readFile(path, "utf-8"); parser.parseModels(path, text); } for (const path of notePaths) { console.log(`Parsing notes file "${path}"...`); const text = await readFile(path, "utf-8"); parser.parseNotes(path, text); } parser.checkDuplicates(); parser.checkErrors(); const { notes } = parser; console.log(`Parsed ${notes.length} note(s).`); if (notes.length > 0) { await writeFile(out, exportNotes(notes)); console.log(`Exported notes to "${out}".`); if (preview) { const previewOut = path.format({ ...path.parse(out), base: undefined, ext: ".html" }); await writeFile(previewOut, generatePreview(notes)); console.log(`Generated preview to "${previewOut}".`); } } else { console.warn(`No notes found in "${dir}".`); } } //# sourceMappingURL=cmd-export.js.map