@notatki/cli
Version:
A collection of tools for creating and syncing Anki notes from simple text files.
22 lines (20 loc) • 765 B
text/typescript
import { readFile, writeFile } from "node:fs/promises";
import { insertNoteId, NoteParser, printNoteNodes } from "@notatki/core";
import { findNoteFiles } from "./io.js";
export async function insertIdCmd({ dir }: { dir: string }): Promise<void> {
console.log(`Scanning directory "${dir}"...`);
const { notePaths } = await findNoteFiles(dir);
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 {
if (insertNoteId(nodes)) {
await writeFile(path, printNoteNodes(nodes));
}
}
}
}