@notatki/cli 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd-export.d.ts +3 -1
- package/dist/cmd-export.d.ts.map +1 -1
- package/dist/cmd-export.js +21 -9
- package/dist/cmd-export.js.map +1 -1
- package/dist/cmd-insert-id.js.map +1 -1
- package/dist/cmd-reformat.js.map +1 -1
- package/dist/cmd-sync.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/io.d.ts +2 -1
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +6 -3
- package/dist/io.js.map +1 -1
- package/dist/program.js +4 -2
- package/dist/program.js.map +1 -1
- package/package.json +6 -5
- package/src/cmd-export.ts +0 -36
- package/src/cmd-insert-id.ts +0 -21
- package/src/cmd-reformat.ts +0 -30
- package/src/cmd-sync.ts +0 -29
- package/src/index.ts +0 -3
- package/src/io.ts +0 -31
- package/src/program.ts +0 -63
package/dist/cmd-export.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export declare function exportCmd({ dir, out, preview }: {
|
|
1
|
+
export declare function exportCmd({ dir, out, preview, csv, json, }: {
|
|
2
2
|
dir: string;
|
|
3
3
|
out: string;
|
|
4
4
|
preview: boolean;
|
|
5
|
+
csv: boolean;
|
|
6
|
+
json: boolean;
|
|
5
7
|
}): Promise<void>;
|
|
6
8
|
//# sourceMappingURL=cmd-export.d.ts.map
|
package/dist/cmd-export.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd-export.d.ts","sourceRoot":"","sources":["../src/cmd-export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cmd-export.d.ts","sourceRoot":"","sources":["../src/cmd-export.ts"],"names":[],"mappings":"AAKA,wBAAsB,SAAS,CAAC,EAC9B,GAAG,EACH,GAAG,EACH,OAAO,EACP,GAAG,EACH,IAAI,GACL,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,OAAO,CAAC,IAAI,CAAC,CA0ChB"}
|
package/dist/cmd-export.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import
|
|
3
|
-
import { exportNotes, NoteParser } from "@notatki/core";
|
|
2
|
+
import { exportAnki, exportCsv, exportJson, NoteParser } from "@notatki/core";
|
|
4
3
|
import { generatePreview } from "@notatki/preview";
|
|
5
|
-
import { findNoteFiles } from "./io.js";
|
|
6
|
-
export async function exportCmd({ dir, out, preview }) {
|
|
4
|
+
import { findNoteFiles, withExt } from "./io.js";
|
|
5
|
+
export async function exportCmd({ dir, out, preview, csv, json, }) {
|
|
7
6
|
const parser = new NoteParser();
|
|
8
7
|
console.log(`Scanning directory "${dir}"...`);
|
|
9
8
|
const { notePaths, modelPaths } = await findNoteFiles(dir);
|
|
@@ -22,12 +21,25 @@ export async function exportCmd({ dir, out, preview }) {
|
|
|
22
21
|
const { notes } = parser;
|
|
23
22
|
console.log(`Parsed ${notes.length} note(s).`);
|
|
24
23
|
if (notes.length > 0) {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (!(csv || json)) {
|
|
25
|
+
const path = withExt(out, ".apkg");
|
|
26
|
+
await writeFile(path, await exportAnki(notes));
|
|
27
|
+
console.log(`Exported notes to "${path}".`);
|
|
28
|
+
}
|
|
29
|
+
if (csv) {
|
|
30
|
+
const path = withExt(out, ".csv");
|
|
31
|
+
await writeFile(path, await exportCsv(notes));
|
|
32
|
+
console.log(`Exported notes to "${path}" in CSV format.`);
|
|
33
|
+
}
|
|
34
|
+
if (json) {
|
|
35
|
+
const path = withExt(out, ".json");
|
|
36
|
+
await writeFile(path, await exportJson(notes));
|
|
37
|
+
console.log(`Exported notes to "${path}" in JSON format.`);
|
|
38
|
+
}
|
|
27
39
|
if (preview) {
|
|
28
|
-
const
|
|
29
|
-
await writeFile(
|
|
30
|
-
console.log(`Generated preview to "${
|
|
40
|
+
const path = withExt(out, ".html");
|
|
41
|
+
await writeFile(path, generatePreview(notes));
|
|
42
|
+
console.log(`Generated HTML preview to "${path}".`);
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
else {
|
package/dist/cmd-export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd-export.js","sourceRoot":"","sources":["../src/cmd-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"cmd-export.js","sourceRoot":"","sources":["../src/cmd-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,GAAG,EACH,GAAG,EACH,OAAO,EACP,GAAG,EACH,IAAI,GAOL;IACC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC,CAAC;IAC9C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,MAAM,CAAC,CAAC;QAChD,MAAM,IAAI,G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AG,EAAE,OAAO,CAAC,CAAC;YACnC,MAAM,SAAS,CAAC,IAAI,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,mBAAmB,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACnC,MAAM,SAAS,CAAC,IAAI,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,IAAI,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { exportAnki, exportCsv, exportJson, NoteParser } from \"@notatki/core\";\nimport { generatePreview } from \"@notatki/preview\";\nimport { findNoteFiles, withExt } from \"./io.js\";\n\nexport async function exportCmd({\n dir,\n out,\n preview,\n csv,\n json,\n}: {\n dir: string;\n out: string;\n preview: boolean;\n csv: boolean;\n json: boolean;\n}): Promise<void> {\n const parser = new NoteParser();\n console.log(`Scanning directory \"${dir}\"...`);\n const { notePaths, modelPaths } = await findNoteFiles(dir);\n for (const path of modelPaths) {\n console.log(`Parsing models file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n parser.parseModels(path, text);\n }\n for (const path of notePaths) {\n console.log(`Parsing notes file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n parser.parseNotes(path, text);\n }\n parser.checkDuplicates();\n parser.checkErrors();\n const { notes } = parser;\n console.log(`Parsed ${notes.length} note(s).`);\n if (notes.length > 0) {\n if (!(csv || json)) {\n const path = withExt(out, \".apkg\");\n await writeFile(path, await exportAnki(notes));\n console.log(`Exported notes to \"${path}\".`);\n }\n if (csv) {\n const path = withExt(out, \".csv\");\n await writeFile(path, await exportCsv(notes));\n console.log(`Exported notes to \"${path}\" in CSV format.`);\n }\n if (json) {\n const path = withExt(out, \".json\");\n await writeFile(path, await exportJson(notes));\n console.log(`Exported notes to \"${path}\" in JSON format.`);\n }\n if (preview) {\n const path = withExt(out, \".html\");\n await writeFile(path, generatePreview(notes));\n console.log(`Generated HTML preview to \"${path}\".`);\n }\n } else {\n console.warn(`No notes found in \"${dir}\".`);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd-insert-id.js","sourceRoot":"","sources":["../src/cmd-insert-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAE,GAAG,EAAmB;IACxD,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC,CAAC;IAC9C,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/C,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,MAAM,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAChC,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/C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { insertNoteId, NoteParser, printNoteNodes } from \"@notatki/core\";\nimport { findNoteFiles } from \"./io.js\";\n\nexport async function insertIdCmd({ dir }: { dir: string }): Promise<void> {\n console.log(`Scanning directory \"${dir}\"...`);\n const { notePaths } = await findNoteFiles(dir);\n for (const path of notePaths) {\n const parser = new NoteParser();\n console.log(`Parsing notes file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n const nodes = parser.parseNoteNodes(path, text);\n if (parser.errors.length > 0) {\n console.error(`Parse error.`);\n } else {\n if (insertNoteId(nodes)) {\n await writeFile(path, printNoteNodes(nodes));\n }\n }\n }\n}\n"]}
|
package/dist/cmd-reformat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd-reformat.js","sourceRoot":"","sources":["../src/cmd-reformat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAAE,GAAG,EAAmB;IACxD,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC,CAAC;IAC9C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,MAAM,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IA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C;YACN,MAAM,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { NoteParser, printModelNodes, printNoteNodes, reformatModelNodes, reformatNoteNodes } from \"@notatki/core\";\nimport { findNoteFiles } from \"./io.js\";\n\nexport async function reformatCmd({ dir }: { dir: string }): Promise<void> {\n console.log(`Scanning directory \"${dir}\"...`);\n const { notePaths, modelPaths } = await findNoteFiles(dir);\n for (const path of modelPaths) {\n const parser = new NoteParser();\n console.log(`Parsing models file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n const nodes = parser.parseModelNodes(path, text);\n if (parser.errors.length > 0) {\n console.error(`Parse error.`);\n } else {\n await writeFile(path, printModelNodes(reformatModelNodes(nodes)));\n }\n }\n for (const path of notePaths) {\n const parser = new NoteParser();\n console.log(`Parsing notes file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n const nodes = parser.parseNoteNodes(path, text);\n if (parser.errors.length > 0) {\n console.error(`Parse error.`);\n } else {\n await writeFile(path, printNoteNodes(reformatNoteNodes(nodes)));\n }\n }\n}\n"]}
|
package/dist/cmd-sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd-sync.js","sourceRoot":"","sources":["../src/cmd-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,EAAE,GAAG,EAAmB;IACpD,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAChC,OAAO,CAAC,GAA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AI,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { NoteParser } from \"@notatki/core\";\nimport { synchronizeNotes } from \"@notatki/sync\";\nimport { findNoteFiles } from \"./io.js\";\n\nexport async function syncCmd({ dir }: { dir: string }): Promise<void> {\n const parser = new NoteParser();\n console.log(`Scanning directory \"${dir}\"...`);\n const { notePaths, modelPaths } = await findNoteFiles(dir);\n for (const path of modelPaths) {\n console.log(`Parsing models file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n parser.parseModels(path, text);\n }\n for (const path of notePaths) {\n console.log(`Parsing notes file \"${path}\"...`);\n const text = await readFile(path, \"utf-8\");\n parser.parseNotes(path, text);\n }\n parser.checkDuplicates();\n parser.checkErrors();\n const { notes } = parser;\n console.log(`Parsed ${notes.length} note(s).`);\n if (notes.length > 0) {\n await synchronizeNotes(notes, {});\n } else {\n console.warn(`No notes found in \"${dir}\".`);\n }\n}\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC","sourcesContent":["export * from \"./cmd-export.js\";\nexport * from \"./cmd-insert-id.js\";\nexport * from \"./io.js\";\n"]}
|
package/dist/io.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function pathTo(...
|
|
1
|
+
export declare function pathTo(...parts: string[]): string;
|
|
2
|
+
export declare function withExt(path: string, ext: string): string;
|
|
2
3
|
export declare function findNoteFiles(dir: string, exclude?: readonly string[]): Promise<{
|
|
3
4
|
notePaths: string[];
|
|
4
5
|
modelPaths: string[];
|
package/dist/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAKA,wBAAgB,MAAM,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAKA,wBAAgB,MAAM,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAEjD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,SAAS,MAAM,EAAwD;;;GAmBjF"}
|
package/dist/io.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { glob } from "node:fs/promises";
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
2
|
+
import { format, join, parse, resolve } from "node:path";
|
|
3
3
|
const cwd = process.cwd();
|
|
4
|
-
export function pathTo(...
|
|
5
|
-
return resolve(cwd, ...
|
|
4
|
+
export function pathTo(...parts) {
|
|
5
|
+
return resolve(cwd, ...parts);
|
|
6
|
+
}
|
|
7
|
+
export function withExt(path, ext) {
|
|
8
|
+
return format({ ...parse(path), base: undefined, ext });
|
|
6
9
|
}
|
|
7
10
|
export async function findNoteFiles(dir, exclude = ["**/.git", "**/.hg", "**/.svn", "**/node_modules"]) {
|
|
8
11
|
const notePaths = [];
|
package/dist/io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE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AC,IAAI,CAAC,CAAC;gBACtB,MAAM;QACV,CAAC;IACH,CAAC;IACD,SAAS,CAAC,IAAI,EAAE,CAAC;IACjB,UAAU,CAAC,IAAI,EAAE,CAAC;IAClB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { glob } from \"node:fs/promises\";\nimport { format, join, parse, resolve } from \"node:path\";\n\nconst cwd = process.cwd();\n\nexport function pathTo(...parts: string[]): string {\n return resolve(cwd, ...parts);\n}\n\nexport function withExt(path: string, ext: string): string {\n return format({ ...parse(path), base: undefined, ext });\n}\n\nexport async function findNoteFiles(\n dir: string,\n exclude: readonly string[] = [\"**/.git\", \"**/.hg\", \"**/.svn\", \"**/node_modules\"],\n) {\n const notePaths: string[] = [];\n const modelPaths: string[] = [];\n const cwd = pathTo(dir);\n for await (const item of glob(\"**/*.{note,model}\", { cwd, exclude })) {\n const path = join(cwd, item);\n switch (true) {\n case item.endsWith(\".note\"):\n notePaths.push(path);\n break;\n case item.endsWith(\".model\"):\n modelPaths.push(path);\n break;\n }\n }\n notePaths.sort();\n modelPaths.sort();\n return { notePaths, modelPaths };\n}\n"]}
|
package/dist/program.js
CHANGED
|
@@ -21,10 +21,12 @@ program
|
|
|
21
21
|
.action(syncCmd);
|
|
22
22
|
program
|
|
23
23
|
.command("export")
|
|
24
|
-
.description("build and export notes to a file in the
|
|
24
|
+
.description("build and export notes to a file in the format that can be imported to Anki")
|
|
25
25
|
.option("--dir <dir>", "name of the directory with note source files", parsePath, parsePath("."))
|
|
26
|
-
.option("--out <file>", "output file name", parsePath, parsePath("notes
|
|
26
|
+
.option("--out <file>", "output file name", parsePath, parsePath("notes"))
|
|
27
27
|
.option("--preview", "whether to generate a preview HTML file", false)
|
|
28
|
+
.option("--csv", "output a CSV file")
|
|
29
|
+
.option("--json", "output a JSON file")
|
|
28
30
|
.action(exportCmd);
|
|
29
31
|
program
|
|
30
32
|
.command("insert-id")
|
package/dist/program.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,eAAe,CAAC;IACtB,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;CAC1D,CAAC,CAAC;AAEH,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,sEAAsE,CAAC;KACnF,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,iGAAiG,CAAC;KAC9G,MAAM,CAAC,aAAa,EAAE,8CAA8C,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;KAChG,MAAM,CAAC,OAAO,CAAC,CAAC;AAEnB,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;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AAC,SAAS,CAAC,CAAC;AAErB,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,oCAAoC,CAAC;KACjD,MAAM,CAAC,aAAa,EAAE,8CAA8C,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;KAChG,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,aAAa,EAAE,8CAA8C,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;KAChG,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,IAAI,CAAC;IACH,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YAC/C,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;QACvG,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { styleText } from \"node:util\";\nimport { ParseError } from \"@notatki/core\";\nimport { Command } from \"commander\";\nimport { exportCmd } from \"./cmd-export.js\";\nimport { insertIdCmd } from \"./cmd-insert-id.js\";\nimport { reformatCmd } from \"./cmd-reformat.js\";\nimport { syncCmd } from \"./cmd-sync.js\";\nimport { pathTo } from \"./io.js\";\n\nconst program = new Command();\n\nprogram.configureOutput({\n outputError: (str, write) => write(styleText(\"red\", str)),\n});\n\nprogram\n .name(\"notatki\")\n .description(\"Build Anki notes from text files written in a human readable format.\")\n .version(\"0.0.0\");\n\nprogram\n .command(\"sync\")\n .description(\"build and synchronize notes with the desktop Anki application through the Anki Connect protocol\")\n .option(\"--dir <dir>\", \"name of the directory with note source files\", parsePath, parsePath(\".\"))\n .action(syncCmd);\n\nprogram\n .command(\"export\")\n .description(\"build and export notes to a file in the format that can be imported to Anki\")\n .option(\"--dir <dir>\", \"name of the directory with note source files\", parsePath, parsePath(\".\"))\n .option(\"--out <file>\", \"output file name\", parsePath, parsePath(\"notes\"))\n .option(\"--preview\", \"whether to generate a preview HTML file\", false)\n .option(\"--csv\", \"output a CSV file\")\n .option(\"--json\", \"output a JSON file\")\n .action(exportCmd);\n\nprogram\n .command(\"insert-id\")\n .description(\"insert unique note id to each note\")\n .option(\"--dir <dir>\", \"name of the directory with note source files\", parsePath, parsePath(\".\"))\n .action(insertIdCmd);\n\nprogram\n .command(\"reformat\")\n .description(\"reformat note files\")\n .option(\"--dir <dir>\", \"name of the directory with note source files\", parsePath, parsePath(\".\"))\n .action(reformatCmd);\n\ntry {\n program.parse();\n} catch (err) {\n if (err instanceof ParseError) {\n const lines = [];\n for (const { message, location } of err.errors) {\n lines.push(`${String(location.source)}:${location.start.line}:${location.start.column}: ${message}`);\n }\n program.error(lines.join(\"\\n\"));\n } else {\n throw err;\n }\n}\n\nfunction parsePath(value: string): string {\n return pathTo(value);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notatki/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A collection of tools for creating and syncing Anki notes from simple text files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anki",
|
|
@@ -15,14 +15,15 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "git+https://github.com/aradzie/notatki.git"
|
|
17
17
|
},
|
|
18
|
+
"license": "MIT",
|
|
18
19
|
"type": "module",
|
|
19
20
|
"bin": {
|
|
20
21
|
"notatki": "notatki.js"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@notatki/core": "^0.0.
|
|
24
|
-
"@notatki/preview": "^0.0.
|
|
25
|
-
"@notatki/sync": "^0.0.
|
|
24
|
+
"@notatki/core": "^0.0.4",
|
|
25
|
+
"@notatki/preview": "^0.0.4",
|
|
26
|
+
"@notatki/sync": "^0.0.4",
|
|
26
27
|
"commander": "^14.0.0"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
@@ -33,5 +34,5 @@
|
|
|
33
34
|
"publishConfig": {
|
|
34
35
|
"access": "public"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b2237839f8310ecbb0b05de29dcfe5571b1d786c"
|
|
37
38
|
}
|
package/src/cmd-export.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { exportNotes, NoteParser } from "@notatki/core";
|
|
4
|
-
import { generatePreview } from "@notatki/preview";
|
|
5
|
-
import { findNoteFiles } from "./io.js";
|
|
6
|
-
|
|
7
|
-
export async function exportCmd({ dir, out, preview }: { dir: string; out: string; preview: boolean }): Promise<void> {
|
|
8
|
-
const parser = new NoteParser();
|
|
9
|
-
console.log(`Scanning directory "${dir}"...`);
|
|
10
|
-
const { notePaths, modelPaths } = await findNoteFiles(dir);
|
|
11
|
-
for (const path of modelPaths) {
|
|
12
|
-
console.log(`Parsing models file "${path}"...`);
|
|
13
|
-
const text = await readFile(path, "utf-8");
|
|
14
|
-
parser.parseModels(path, text);
|
|
15
|
-
}
|
|
16
|
-
for (const path of notePaths) {
|
|
17
|
-
console.log(`Parsing notes file "${path}"...`);
|
|
18
|
-
const text = await readFile(path, "utf-8");
|
|
19
|
-
parser.parseNotes(path, text);
|
|
20
|
-
}
|
|
21
|
-
parser.checkDuplicates();
|
|
22
|
-
parser.checkErrors();
|
|
23
|
-
const { notes } = parser;
|
|
24
|
-
console.log(`Parsed ${notes.length} note(s).`);
|
|
25
|
-
if (notes.length > 0) {
|
|
26
|
-
await writeFile(out, exportNotes(notes));
|
|
27
|
-
console.log(`Exported notes to "${out}".`);
|
|
28
|
-
if (preview) {
|
|
29
|
-
const previewOut = path.format({ ...path.parse(out), base: undefined, ext: ".html" });
|
|
30
|
-
await writeFile(previewOut, generatePreview(notes));
|
|
31
|
-
console.log(`Generated preview to "${previewOut}".`);
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
console.warn(`No notes found in "${dir}".`);
|
|
35
|
-
}
|
|
36
|
-
}
|
package/src/cmd-insert-id.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { insertNoteId, NoteParser, printNoteNodes } from "@notatki/core";
|
|
3
|
-
import { findNoteFiles } from "./io.js";
|
|
4
|
-
|
|
5
|
-
export async function insertIdCmd({ dir }: { dir: string }): Promise<void> {
|
|
6
|
-
console.log(`Scanning directory "${dir}"...`);
|
|
7
|
-
const { notePaths } = await findNoteFiles(dir);
|
|
8
|
-
for (const path of notePaths) {
|
|
9
|
-
const parser = new NoteParser();
|
|
10
|
-
console.log(`Parsing notes file "${path}"...`);
|
|
11
|
-
const text = await readFile(path, "utf-8");
|
|
12
|
-
const nodes = parser.parseNoteNodes(path, text);
|
|
13
|
-
if (parser.errors.length > 0) {
|
|
14
|
-
console.error(`Parse error.`);
|
|
15
|
-
} else {
|
|
16
|
-
if (insertNoteId(nodes)) {
|
|
17
|
-
await writeFile(path, printNoteNodes(nodes));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/src/cmd-reformat.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { NoteParser, printModelNodes, printNoteNodes, reformatModelNodes, reformatNoteNodes } from "@notatki/core";
|
|
3
|
-
import { findNoteFiles } from "./io.js";
|
|
4
|
-
|
|
5
|
-
export async function reformatCmd({ dir }: { dir: string }): Promise<void> {
|
|
6
|
-
console.log(`Scanning directory "${dir}"...`);
|
|
7
|
-
const { notePaths, modelPaths } = await findNoteFiles(dir);
|
|
8
|
-
for (const path of modelPaths) {
|
|
9
|
-
const parser = new NoteParser();
|
|
10
|
-
console.log(`Parsing models file "${path}"...`);
|
|
11
|
-
const text = await readFile(path, "utf-8");
|
|
12
|
-
const nodes = parser.parseModelNodes(path, text);
|
|
13
|
-
if (parser.errors.length > 0) {
|
|
14
|
-
console.error(`Parse error.`);
|
|
15
|
-
} else {
|
|
16
|
-
await writeFile(path, printModelNodes(reformatModelNodes(nodes)));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
for (const path of notePaths) {
|
|
20
|
-
const parser = new NoteParser();
|
|
21
|
-
console.log(`Parsing notes file "${path}"...`);
|
|
22
|
-
const text = await readFile(path, "utf-8");
|
|
23
|
-
const nodes = parser.parseNoteNodes(path, text);
|
|
24
|
-
if (parser.errors.length > 0) {
|
|
25
|
-
console.error(`Parse error.`);
|
|
26
|
-
} else {
|
|
27
|
-
await writeFile(path, printNoteNodes(reformatNoteNodes(nodes)));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/cmd-sync.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { NoteParser } from "@notatki/core";
|
|
3
|
-
import { synchronizeNotes } from "@notatki/sync";
|
|
4
|
-
import { findNoteFiles } from "./io.js";
|
|
5
|
-
|
|
6
|
-
export async function syncCmd({ dir }: { dir: string }): Promise<void> {
|
|
7
|
-
const parser = new NoteParser();
|
|
8
|
-
console.log(`Scanning directory "${dir}"...`);
|
|
9
|
-
const { notePaths, modelPaths } = await findNoteFiles(dir);
|
|
10
|
-
for (const path of modelPaths) {
|
|
11
|
-
console.log(`Parsing models file "${path}"...`);
|
|
12
|
-
const text = await readFile(path, "utf-8");
|
|
13
|
-
parser.parseModels(path, text);
|
|
14
|
-
}
|
|
15
|
-
for (const path of notePaths) {
|
|
16
|
-
console.log(`Parsing notes file "${path}"...`);
|
|
17
|
-
const text = await readFile(path, "utf-8");
|
|
18
|
-
parser.parseNotes(path, text);
|
|
19
|
-
}
|
|
20
|
-
parser.checkDuplicates();
|
|
21
|
-
parser.checkErrors();
|
|
22
|
-
const { notes } = parser;
|
|
23
|
-
console.log(`Parsed ${notes.length} note(s).`);
|
|
24
|
-
if (notes.length > 0) {
|
|
25
|
-
await synchronizeNotes(notes, {});
|
|
26
|
-
} else {
|
|
27
|
-
console.warn(`No notes found in "${dir}".`);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/index.ts
DELETED
package/src/io.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { glob } from "node:fs/promises";
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
3
|
-
|
|
4
|
-
const cwd = process.cwd();
|
|
5
|
-
|
|
6
|
-
export function pathTo(...file: string[]): string {
|
|
7
|
-
return resolve(cwd, ...file);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function findNoteFiles(
|
|
11
|
-
dir: string,
|
|
12
|
-
exclude: readonly string[] = ["**/.git", "**/.hg", "**/.svn", "**/node_modules"],
|
|
13
|
-
) {
|
|
14
|
-
const notePaths: string[] = [];
|
|
15
|
-
const modelPaths: string[] = [];
|
|
16
|
-
const cwd = pathTo(dir);
|
|
17
|
-
for await (const item of glob("**/*.{note,model}", { cwd, exclude })) {
|
|
18
|
-
const path = join(cwd, item);
|
|
19
|
-
switch (true) {
|
|
20
|
-
case item.endsWith(".note"):
|
|
21
|
-
notePaths.push(path);
|
|
22
|
-
break;
|
|
23
|
-
case item.endsWith(".model"):
|
|
24
|
-
modelPaths.push(path);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
notePaths.sort();
|
|
29
|
-
modelPaths.sort();
|
|
30
|
-
return { notePaths, modelPaths };
|
|
31
|
-
}
|
package/src/program.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { styleText } from "node:util";
|
|
2
|
-
import { ParseError } from "@notatki/core";
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import { exportCmd } from "./cmd-export.js";
|
|
5
|
-
import { insertIdCmd } from "./cmd-insert-id.js";
|
|
6
|
-
import { reformatCmd } from "./cmd-reformat.js";
|
|
7
|
-
import { syncCmd } from "./cmd-sync.js";
|
|
8
|
-
import { pathTo } from "./io.js";
|
|
9
|
-
|
|
10
|
-
const program = new Command();
|
|
11
|
-
|
|
12
|
-
program.configureOutput({
|
|
13
|
-
outputError: (str, write) => write(styleText("red", str)),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
program
|
|
17
|
-
.name("notatki")
|
|
18
|
-
.description("Build Anki notes from text files written in a human readable format.")
|
|
19
|
-
.version("0.0.0");
|
|
20
|
-
|
|
21
|
-
program
|
|
22
|
-
.command("sync")
|
|
23
|
-
.description("build and synchronize notes with the desktop Anki application through the Anki Connect protocol")
|
|
24
|
-
.option("--dir <dir>", "name of the directory with note source files", parsePath, parsePath("."))
|
|
25
|
-
.action(syncCmd);
|
|
26
|
-
|
|
27
|
-
program
|
|
28
|
-
.command("export")
|
|
29
|
-
.description("build and export notes to a file in the Anki notes file format")
|
|
30
|
-
.option("--dir <dir>", "name of the directory with note source files", parsePath, parsePath("."))
|
|
31
|
-
.option("--out <file>", "output file name", parsePath, parsePath("notes.txt"))
|
|
32
|
-
.option("--preview", "whether to generate a preview HTML file", false)
|
|
33
|
-
.action(exportCmd);
|
|
34
|
-
|
|
35
|
-
program
|
|
36
|
-
.command("insert-id")
|
|
37
|
-
.description("insert unique note id to each note")
|
|
38
|
-
.option("--dir <dir>", "name of the directory with note source files", parsePath, parsePath("."))
|
|
39
|
-
.action(insertIdCmd);
|
|
40
|
-
|
|
41
|
-
program
|
|
42
|
-
.command("reformat")
|
|
43
|
-
.description("reformat note files")
|
|
44
|
-
.option("--dir <dir>", "name of the directory with note source files", parsePath, parsePath("."))
|
|
45
|
-
.action(reformatCmd);
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
program.parse();
|
|
49
|
-
} catch (err) {
|
|
50
|
-
if (err instanceof ParseError) {
|
|
51
|
-
const lines = [];
|
|
52
|
-
for (const { message, location } of err.errors) {
|
|
53
|
-
lines.push(`${String(location.source)}:${location.start.line}:${location.start.column}: ${message}`);
|
|
54
|
-
}
|
|
55
|
-
program.error(lines.join("\n"));
|
|
56
|
-
} else {
|
|
57
|
-
throw err;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function parsePath(value: string): string {
|
|
62
|
-
return pathTo(value);
|
|
63
|
-
}
|