mdq-cli 0.1.0 → 0.1.1
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/README.md +1 -1
- package/bin/mdq.js +38 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/mdq.js
CHANGED
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
// src/utils/mdq/cli.ts
|
|
4
4
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { Command } from "commander";
|
|
6
|
+
// src/utils/mdq/package.json
|
|
7
|
+
var package_default = {
|
|
8
|
+
name: "mdq-cli",
|
|
9
|
+
version: "0.1.1",
|
|
10
|
+
description: "Query and edit markdown with a selector language - jq, for markdown",
|
|
11
|
+
license: "MIT",
|
|
12
|
+
type: "module",
|
|
13
|
+
main: "./index.js",
|
|
14
|
+
types: "./types/query.d.ts",
|
|
15
|
+
exports: {
|
|
16
|
+
".": {
|
|
17
|
+
types: "./types/query.d.ts",
|
|
18
|
+
import: "./index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
bin: {
|
|
22
|
+
mdq: "./bin/mdq.js"
|
|
23
|
+
},
|
|
24
|
+
files: ["index.js", "types/", "bin/", "README.md"],
|
|
25
|
+
engines: {
|
|
26
|
+
node: ">=18"
|
|
27
|
+
},
|
|
28
|
+
keywords: ["markdown", "query", "selector", "cli", "jq", "frontmatter", "marked", "edit"],
|
|
29
|
+
repository: {
|
|
30
|
+
type: "git",
|
|
31
|
+
url: "https://github.com/testomatio/explorbot",
|
|
32
|
+
directory: "src/utils/mdq"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
6
35
|
|
|
7
36
|
// src/utils/mdq/query.ts
|
|
8
37
|
import { marked } from "marked";
|
|
@@ -633,11 +662,19 @@ var SEGMENT = /(\s*\.?)([A-Za-z]\w*)(?:\((!?)(~?)(?:"((?:[^"\\]|\\.)*)"|\/((?:[^
|
|
|
633
662
|
// src/utils/mdq/cli.ts
|
|
634
663
|
var EDIT_FLAGS = ["remove", "replace", "insertBefore", "insertAfter", "prepend", "append", "addRow", "addItem", "set"];
|
|
635
664
|
async function runMdq(argv, readStdin) {
|
|
665
|
+
let printed = "";
|
|
636
666
|
const program = new Command;
|
|
637
|
-
program.name("mdq").description("query and edit markdown").argument("[selector]", "markdown selector").argument("[file]", "file to read; stdin when omitted").option("-j, --json", "output rows as JSON").option("-c, --count", "print the number of matches").option("-t, --text", "print unwrapped text").option("--frontmatter", "print frontmatter as JSON").option("-i, --in-place", "write the result back to the file").option("--remove", "delete matched blocks").option("--replace <markdown>", "replace matched blocks").option("--insert-before <markdown>", "insert before each match").option("--insert-after <markdown>", "insert after each match").option("--prepend <markdown>", "insert at the start of each match").option("--append <markdown>", "insert at the end of each match").option("--add-row <json>", "append a table row").option("--add-item <text>", "append a list item").option("--set <key=value>", "set an entry; omit the value to delete it").exitOverride().configureOutput({
|
|
667
|
+
program.name("mdq").description("query and edit markdown").version(package_default.version, "-v, --version").argument("[selector]", "markdown selector").argument("[file]", "file to read; stdin when omitted").option("-j, --json", "output rows as JSON").option("-c, --count", "print the number of matches").option("-t, --text", "print unwrapped text").option("--frontmatter", "print frontmatter as JSON").option("-i, --in-place", "write the result back to the file").option("--remove", "delete matched blocks").option("--replace <markdown>", "replace matched blocks").option("--insert-before <markdown>", "insert before each match").option("--insert-after <markdown>", "insert after each match").option("--prepend <markdown>", "insert at the start of each match").option("--append <markdown>", "insert at the end of each match").option("--add-row <json>", "append a table row").option("--add-item <text>", "append a list item").option("--set <key=value>", "set an entry; omit the value to delete it").exitOverride().configureOutput({
|
|
668
|
+
writeOut: (text) => {
|
|
669
|
+
printed += text;
|
|
670
|
+
},
|
|
671
|
+
writeErr: () => {}
|
|
672
|
+
});
|
|
638
673
|
try {
|
|
639
674
|
program.parse(argv, { from: "user" });
|
|
640
675
|
} catch (error) {
|
|
676
|
+
if (printed)
|
|
677
|
+
return { output: printed, code: 0 };
|
|
641
678
|
return { output: String(error.message), code: 2 };
|
|
642
679
|
}
|
|
643
680
|
const options = program.opts();
|