UNPKG

@notatki/cli

Version:

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

32 lines 1.31 kB
import { readFile, writeFile } from "node:fs/promises"; import { NoteParser, printModelNodes, printNoteNodes, reformatModelNodes, reformatNoteNodes } from "@notatki/core"; import { findNoteFiles } from "./io.js"; export async function reformatCmd({ dir }) { console.log(`Scanning directory "${dir}"...`); const { notePaths, modelPaths } = await findNoteFiles(dir); for (const path of modelPaths) { const parser = new NoteParser(); console.log(`Parsing models file "${path}"...`); const text = await readFile(path, "utf-8"); const nodes = parser.parseModelNodes(path, text); if (parser.errors.length > 0) { console.error(`Parse error.`); } else { await writeFile(path, printModelNodes(reformatModelNodes(nodes))); } } for (const path of notePaths) { const parser = new NoteParser(); console.log(`Parsing notes file "${path}"...`); const text = await readFile(path, "utf-8"); const nodes = parser.parseNoteNodes(path, text); if (parser.errors.length > 0) { console.error(`Parse error.`); } else { await writeFile(path, printNoteNodes(reformatNoteNodes(nodes))); } } } //# sourceMappingURL=cmd-reformat.js.map