markdownscribe 0.0.1 → 0.1.0
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 +46 -4
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +90 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/format.d.ts +9 -0
- package/dist/commands/format.d.ts.map +1 -0
- package/dist/commands/format.js +50 -0
- package/dist/commands/format.js.map +1 -0
- package/dist/commands/frontmatter.d.ts +4 -0
- package/dist/commands/frontmatter.d.ts.map +1 -0
- package/dist/commands/frontmatter.js +31 -0
- package/dist/commands/frontmatter.js.map +1 -0
- package/dist/commands/lint.d.ts +4 -0
- package/dist/commands/lint.d.ts.map +1 -0
- package/dist/commands/lint.js +34 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/mermaid.d.ts +4 -0
- package/dist/commands/mermaid.d.ts.map +1 -0
- package/dist/commands/mermaid.js +48 -0
- package/dist/commands/mermaid.js.map +1 -0
- package/dist/commands/toc.d.ts +8 -0
- package/dist/commands/toc.d.ts.map +1 -0
- package/dist/commands/toc.js +36 -0
- package/dist/commands/toc.js.map +1 -0
- package/dist/commands/types.d.ts +6 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/url.d.ts +8 -0
- package/dist/commands/url.d.ts.map +1 -0
- package/dist/commands/url.js +27 -0
- package/dist/commands/url.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +20 -0
- package/dist/config.js.map +1 -0
- package/dist/fs-utils.d.ts +2 -0
- package/dist/fs-utils.d.ts.map +1 -0
- package/dist/fs-utils.js +17 -0
- package/dist/fs-utils.js.map +1 -0
- package/dist/output.d.ts +8 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +41 -0
- package/dist/output.js.map +1 -0
- package/package.json +52 -9
- package/index.js +0 -5
package/README.md
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
# markdownscribe (CLI)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command-line interface for [MarkdownScribe](https://api-production-d0eb.up.railway.app) — frontmatter, table of contents, lint, format, Mermaid-to-SVG, and URL-to-Markdown, from your terminal or from a shell script/agent runner. Built on top of [`@markdownscribe/sdk`](../sdk/README.md).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g markdownscribe
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Installs two equivalent binaries: `markdownscribe` and the shorter `mdscribe`.
|
|
12
|
+
|
|
13
|
+
## Authentication
|
|
14
|
+
|
|
15
|
+
Resolved in this order: `MDSCRIBE_API_KEY` env var → `API_KEY_MAT` env var → a `.env` file (`MDSCRIBE_API_KEY=...`) in the current directory.
|
|
16
|
+
|
|
17
|
+
API base URL: `MDSCRIBE_URL` env var → `--base-url <url>` flag → production default.
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
mdscribe frontmatter <path> # file or directory (non-recursive)
|
|
23
|
+
mdscribe toc <path> [--min-depth N] [--max-depth N]
|
|
24
|
+
mdscribe format <path> [--prose-wrap preserve|always|never] [--write] [--check]
|
|
25
|
+
mdscribe lint <path>
|
|
26
|
+
mdscribe mermaid <path> # single .mmd or .md/.mdx file, writes <name>-diagram-N.svg
|
|
27
|
+
mdscribe url <url> [--mode clean|raw] [--save <path>]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`frontmatter`/`toc`/`format`/`lint` accept a single file or a directory (non-recursive: only `.md`/`.mdx` files directly in it). `mermaid` and `url` take a single file / a single URL. Every successful run prints the credits charged for that call. Files written to disk (`format --write`, `mermaid`'s SVGs, `url --save`) are UTF-8 without a BOM.
|
|
31
|
+
|
|
32
|
+
## Exit codes
|
|
33
|
+
|
|
34
|
+
| Code | Meaning |
|
|
35
|
+
|---|---|
|
|
36
|
+
| 0 | Success |
|
|
37
|
+
| 1 | Generic/config error |
|
|
38
|
+
| 2 | Authentication failed (401) |
|
|
39
|
+
| 3 | Insufficient credits (402) |
|
|
40
|
+
| 4 | Rate limited (429) |
|
|
41
|
+
| 5 | Invalid request (400/413/422) |
|
|
42
|
+
| 6 | Upstream service unavailable (503/504/424) |
|
|
43
|
+
| 7 | Not found (404) |
|
|
44
|
+
|
|
45
|
+
Scriptable by design — every failure mode maps to a distinct, documented exit code, which the previous ad-hoc PowerShell scripts didn't guarantee.
|
|
46
|
+
|
|
47
|
+
## Scope
|
|
48
|
+
|
|
49
|
+
Covers the 6 REST markdown operations. A first-class MCP server — so this same functionality is directly callable from Claude and other agent runtimes without shelling out — is planned for a follow-up sprint (the "Claude channel": Extensions/Skills/Plugins). Until then, this CLI is the fastest way for both a human and an LLM-driven shell/agent to call MarkdownScribe correctly.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { MarkdownScribeClient } from "@markdownscribe/sdk";
|
|
4
|
+
import { ConfigError, resolveConfig } from "./config.js";
|
|
5
|
+
import { runFrontmatter } from "./commands/frontmatter.js";
|
|
6
|
+
import { runToc } from "./commands/toc.js";
|
|
7
|
+
import { runFormat } from "./commands/format.js";
|
|
8
|
+
import { runLint } from "./commands/lint.js";
|
|
9
|
+
import { runMermaid } from "./commands/mermaid.js";
|
|
10
|
+
import { runUrl } from "./commands/url.js";
|
|
11
|
+
function getClient(opts) {
|
|
12
|
+
const configOptions = { cwd: process.cwd() };
|
|
13
|
+
if (opts.baseUrl !== undefined)
|
|
14
|
+
configOptions.baseUrlFlag = opts.baseUrl;
|
|
15
|
+
const config = resolveConfig(configOptions);
|
|
16
|
+
return new MarkdownScribeClient(config);
|
|
17
|
+
}
|
|
18
|
+
// Nunca usar process.exit() aqui: no Node 24+ no Windows, forçar saída logo
|
|
19
|
+
// depois de um fetch() cria uma corrida real com o fechamento de handles do
|
|
20
|
+
// libuv e derruba o processo com "Assertion failed:
|
|
21
|
+
// !(handle->flags & UV_HANDLE_CLOSING)" DEPOIS do resultado já ter sido
|
|
22
|
+
// impresso corretamente — bug upstream do Node, sem fix lançado ainda
|
|
23
|
+
// (nodejs/node#56645, nodejs/node#58091). Setar process.exitCode e deixar o
|
|
24
|
+
// processo encerrar sozinho evita a corrida sem mudar o exit code observado
|
|
25
|
+
// externamente.
|
|
26
|
+
function emit(result) {
|
|
27
|
+
if (result.stdout)
|
|
28
|
+
process.stdout.write(result.stdout);
|
|
29
|
+
if (result.stderr)
|
|
30
|
+
process.stderr.write(result.stderr);
|
|
31
|
+
process.exitCode = result.exitCode;
|
|
32
|
+
}
|
|
33
|
+
async function execute(fn) {
|
|
34
|
+
try {
|
|
35
|
+
emit(await fn());
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err instanceof ConfigError) {
|
|
39
|
+
process.stderr.write(`${err.message}\n`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const program = new Command();
|
|
47
|
+
program
|
|
48
|
+
.name("markdownscribe")
|
|
49
|
+
.description("MarkdownScribe CLI — frontmatter, TOC, lint, format, mermaid and url-to-markdown from the terminal.")
|
|
50
|
+
.version("0.1.0")
|
|
51
|
+
.option("--base-url <url>", "override the MarkdownScribe API base URL");
|
|
52
|
+
program
|
|
53
|
+
.command("frontmatter")
|
|
54
|
+
.description("Extract frontmatter from a Markdown file or directory")
|
|
55
|
+
.argument("<path>", "file or directory (non-recursive)")
|
|
56
|
+
.action((path) => execute(() => runFrontmatter(path, getClient(program.opts()))));
|
|
57
|
+
program
|
|
58
|
+
.command("toc")
|
|
59
|
+
.description("Generate a table of contents for a Markdown file or directory")
|
|
60
|
+
.argument("<path>", "file or directory (non-recursive)")
|
|
61
|
+
.option("--min-depth <n>", "minimum heading depth", (v) => Number.parseInt(v, 10))
|
|
62
|
+
.option("--max-depth <n>", "maximum heading depth", (v) => Number.parseInt(v, 10))
|
|
63
|
+
.action((path, opts) => execute(() => runToc(path, opts, getClient(program.opts()))));
|
|
64
|
+
program
|
|
65
|
+
.command("format")
|
|
66
|
+
.description("Normalize a Markdown file or directory")
|
|
67
|
+
.argument("<path>", "file or directory (non-recursive)")
|
|
68
|
+
.option("--prose-wrap <mode>", "preserve|always|never", "preserve")
|
|
69
|
+
.option("--write", "overwrite the file with the formatted content")
|
|
70
|
+
.option("--check", "report changed status without writing or printing")
|
|
71
|
+
.action((path, opts) => execute(() => runFormat(path, opts, getClient(program.opts()))));
|
|
72
|
+
program
|
|
73
|
+
.command("lint")
|
|
74
|
+
.description("Lint a Markdown file or directory")
|
|
75
|
+
.argument("<path>", "file or directory (non-recursive)")
|
|
76
|
+
.action((path) => execute(() => runLint(path, getClient(program.opts()))));
|
|
77
|
+
program
|
|
78
|
+
.command("mermaid")
|
|
79
|
+
.description("Render Mermaid diagrams from a .mmd or .md file to SVG")
|
|
80
|
+
.argument("<path>", "single .mmd or .md/.mdx file")
|
|
81
|
+
.action((path) => execute(() => runMermaid(path, getClient(program.opts()))));
|
|
82
|
+
program
|
|
83
|
+
.command("url")
|
|
84
|
+
.description("Convert a web page to Markdown")
|
|
85
|
+
.argument("<url>", "http(s) URL")
|
|
86
|
+
.option("--mode <mode>", "clean|raw", "clean")
|
|
87
|
+
.option("--save <path>", "write the result to a file instead of stdout")
|
|
88
|
+
.action((url, opts) => execute(() => runUrl(url, opts, getClient(program.opts()))));
|
|
89
|
+
await program.parseAsync(process.argv);
|
|
90
|
+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AC;KAClD,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CACvB,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,EAAiB,CAAC,CAAC,CAAC,CAC1E,CAAC;AAEJ,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,gCAAgC,CAAC;KAC7C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;KAChC,MAAM,CAAC,eAAe,EAAE,WAAW,EAAE,OAAO,CAAC;KAC7C,MAAM,CAAC,eAAe,EAAE,8CAA8C,CAAC;KACvE,MAAM,CAAC,CAAC,GAAW,EAAE,IAA8C,EAAE,EAAE,CACtE,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,EAAiB,CAAC,CAAC,CAAC,CAC3E,CAAC;AAEJ,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MarkdownScribeClient } from "@markdownscribe/sdk";
|
|
2
|
+
import type { CommandResult } from "./types.js";
|
|
3
|
+
export interface FormatOptions {
|
|
4
|
+
proseWrap?: "preserve" | "always" | "never";
|
|
5
|
+
write?: boolean;
|
|
6
|
+
check?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function runFormat(pathArg: string, options: FormatOptions, client: MarkdownScribeClient): Promise<CommandResult>;
|
|
9
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/commands/format.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAKhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,aAAa,CAAC,CA2CxB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
3
|
+
import { collectMarkdownFiles } from "../fs-utils.js";
|
|
4
|
+
import { formatError } from "../output.js";
|
|
5
|
+
export async function runFormat(pathArg, options, client) {
|
|
6
|
+
const files = collectMarkdownFiles(pathArg);
|
|
7
|
+
let stdout = "";
|
|
8
|
+
let stderr = "";
|
|
9
|
+
let exitCode = 0;
|
|
10
|
+
let totalCredits = 0;
|
|
11
|
+
for (const file of files) {
|
|
12
|
+
const markdown = readFileSync(file, "utf8");
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.format({
|
|
15
|
+
markdown,
|
|
16
|
+
options: { prose_wrap: options.proseWrap ?? "preserve" },
|
|
17
|
+
});
|
|
18
|
+
totalCredits += result.meta.credits;
|
|
19
|
+
if (options.check) {
|
|
20
|
+
stdout += `${result.changed ? "changed" : "ok"}: ${file}\n`;
|
|
21
|
+
}
|
|
22
|
+
else if (options.write) {
|
|
23
|
+
if (result.changed) {
|
|
24
|
+
// UTF-8 sem BOM (diferente de PowerShell Out-File -Encoding utf8,
|
|
25
|
+
// que grava BOM — bug do script atual que este CLI corrige).
|
|
26
|
+
writeFileSync(file, result.formatted, "utf8");
|
|
27
|
+
stdout += `formatted: ${file}\n`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
stdout += `already formatted: ${file}\n`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
stdout += result.formatted;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
39
|
+
throw err;
|
|
40
|
+
const formatted = formatError(err);
|
|
41
|
+
stderr += `${file}: ${formatted.message}\n`;
|
|
42
|
+
exitCode = formatted.exitCode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (exitCode === 0) {
|
|
46
|
+
stdout += `\ncredits charged: ${totalCredits}\n`;
|
|
47
|
+
}
|
|
48
|
+
return { exitCode, stdout, stderr };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/commands/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAS3C,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,OAAe,EACf,OAAsB,EACtB,MAA4B;IAE5B,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;gBACjC,QAAQ;gBACR,OAAO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frontmatter.d.ts","sourceRoot":"","sources":["../../src/commands/frontmatter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAKhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CA0B1G"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
3
|
+
import { collectMarkdownFiles } from "../fs-utils.js";
|
|
4
|
+
import { formatError } from "../output.js";
|
|
5
|
+
export async function runFrontmatter(pathArg, client) {
|
|
6
|
+
const files = collectMarkdownFiles(pathArg);
|
|
7
|
+
let stdout = "";
|
|
8
|
+
let stderr = "";
|
|
9
|
+
let exitCode = 0;
|
|
10
|
+
let totalCredits = 0;
|
|
11
|
+
for (const file of files) {
|
|
12
|
+
const markdown = readFileSync(file, "utf8");
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.frontmatter({ markdown });
|
|
15
|
+
totalCredits += result.meta.credits;
|
|
16
|
+
stdout += `=== ${file} ===\n${JSON.stringify(result.frontmatter, null, 2)}\n`;
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
20
|
+
throw err;
|
|
21
|
+
const formatted = formatError(err);
|
|
22
|
+
stderr += `${file}: ${formatted.message}\n`;
|
|
23
|
+
exitCode = formatted.exitCode;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (exitCode === 0) {
|
|
27
|
+
stdout += `\ncredits charged: ${totalCredits}\n`;
|
|
28
|
+
}
|
|
29
|
+
return { exitCode, stdout, stderr };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @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C;QAChC,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,sBAAsB,YAAY,IAAI,CAAC;IACnD,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/commands/lint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAKhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAsB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6BnG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
3
|
+
import { collectMarkdownFiles } from "../fs-utils.js";
|
|
4
|
+
import { formatError } from "../output.js";
|
|
5
|
+
export async function runLint(pathArg, client) {
|
|
6
|
+
const files = collectMarkdownFiles(pathArg);
|
|
7
|
+
let stdout = "";
|
|
8
|
+
let stderr = "";
|
|
9
|
+
let exitCode = 0;
|
|
10
|
+
let totalCredits = 0;
|
|
11
|
+
for (const file of files) {
|
|
12
|
+
const markdown = readFileSync(file, "utf8");
|
|
13
|
+
try {
|
|
14
|
+
const result = await client.lint({ markdown });
|
|
15
|
+
totalCredits += result.meta.credits;
|
|
16
|
+
stdout += `=== ${file} (${result.summary.total} finding(s)) ===\n`;
|
|
17
|
+
for (const finding of result.findings) {
|
|
18
|
+
stdout += `${finding.rule} line ${finding.line}: ${finding.message}\n`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
23
|
+
throw err;
|
|
24
|
+
const formatted = formatError(err);
|
|
25
|
+
stderr += `${file}: ${formatted.message}\n`;
|
|
26
|
+
exitCode = formatted.exitCode;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (exitCode === 0) {
|
|
30
|
+
stdout += `\ncredits charged: ${totalCredits}\n`;
|
|
31
|
+
}
|
|
32
|
+
return { exitCode, stdout, stderr };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=lint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/commands/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,MAA4B;IACzE,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC/C,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;YACpC,MAAM,IAAI,OAAO,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,KAAK,oBAAoB,CAAC;YACnE,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACtC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,SAAS,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,IAAI,CAAC;YACzE,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,CAAC,GAAG,YAAY,sBAAsB,CAAC;gBAAE,MAAM,GAAG,CAAC;YACxD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,OAAO,IAAI,CAAC;YAC5C,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAChC,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,sBAAsB,YAAY,IAAI,CAAC;IACnD,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../src/commands/mermaid.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAgDtG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
3
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
4
|
+
import { formatError } from "../output.js";
|
|
5
|
+
export async function runMermaid(pathArg, client) {
|
|
6
|
+
const stat = statSync(pathArg);
|
|
7
|
+
if (stat.isDirectory()) {
|
|
8
|
+
return { exitCode: 5, stdout: "", stderr: "mermaid: pass a single file, not a directory\n" };
|
|
9
|
+
}
|
|
10
|
+
const content = readFileSync(pathArg, "utf8");
|
|
11
|
+
const isDiagram = extname(pathArg).toLowerCase() === ".mmd";
|
|
12
|
+
try {
|
|
13
|
+
const result = isDiagram
|
|
14
|
+
? await client.mermaid({ diagram: content })
|
|
15
|
+
: await client.mermaid({ markdown: content });
|
|
16
|
+
if (result.summary.total === 0) {
|
|
17
|
+
return {
|
|
18
|
+
exitCode: 0,
|
|
19
|
+
stdout: `no mermaid blocks found (charged ${result.meta.credits} credit)\n`,
|
|
20
|
+
stderr: "",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const dir = dirname(pathArg);
|
|
24
|
+
const base = basename(pathArg, extname(pathArg));
|
|
25
|
+
let stdout = "";
|
|
26
|
+
let stderr = "";
|
|
27
|
+
for (const diagram of result.diagrams) {
|
|
28
|
+
const n = diagram.index + 1;
|
|
29
|
+
const svgPath = join(dir, `${base}-diagram-${n}.svg`);
|
|
30
|
+
// SVG em UTF-8 sem BOM (BOM quebra alguns viewers) — mesma escrita
|
|
31
|
+
// que o script mdscribe-mermaid.ps1 atual já faz.
|
|
32
|
+
writeFileSync(svgPath, diagram.svg, "utf8");
|
|
33
|
+
stdout += `ok: ${base}-diagram-${n}.svg\n`;
|
|
34
|
+
}
|
|
35
|
+
for (const diagramError of result.errors) {
|
|
36
|
+
stderr += `failed (diagram ${diagramError.index + 1}): ${diagramError.message}\n`;
|
|
37
|
+
}
|
|
38
|
+
stdout += `\n${result.summary.rendered}/${result.summary.total} rendered — ${result.meta.credits} credits\n`;
|
|
39
|
+
return { exitCode: 0, stdout, stderr };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
43
|
+
throw err;
|
|
44
|
+
const formatted = formatError(err);
|
|
45
|
+
return { exitCode: formatted.exitCode, stdout: "", st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AAC;QACnC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;IACxF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MarkdownScribeClient } from "@markdownscribe/sdk";
|
|
2
|
+
import type { CommandResult } from "./types.js";
|
|
3
|
+
export interface TocOptions {
|
|
4
|
+
minDepth?: number;
|
|
5
|
+
maxDepth?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function runToc(pathArg: string, options: TocOptions, client: MarkdownScribeClient): Promise<CommandResult>;
|
|
8
|
+
//# sourceMappingURL=toc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/commands/toc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAKhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,aAAa,CAAC,CA8BxB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
3
|
+
import { collectMarkdownFiles } from "../fs-utils.js";
|
|
4
|
+
import { formatError } from "../output.js";
|
|
5
|
+
export async function runToc(pathArg, options, client) {
|
|
6
|
+
const files = collectMarkdownFiles(pathArg);
|
|
7
|
+
let stdout = "";
|
|
8
|
+
let stderr = "";
|
|
9
|
+
let exitCode = 0;
|
|
10
|
+
let totalCredits = 0;
|
|
11
|
+
const tocOptions = {};
|
|
12
|
+
if (options.minDepth !== undefined)
|
|
13
|
+
tocOptions.min_depth = options.minDepth;
|
|
14
|
+
if (options.maxDepth !== undefined)
|
|
15
|
+
tocOptions.max_depth = options.maxDepth;
|
|
16
|
+
for (const file of files) {
|
|
17
|
+
const markdown = readFileSync(file, "utf8");
|
|
18
|
+
try {
|
|
19
|
+
const result = await client.toc({ markdown, options: tocOptions });
|
|
20
|
+
totalCredits += result.meta.credits;
|
|
21
|
+
stdout += `=== ${file} ===\n${result.toc}\n`;
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
25
|
+
throw err;
|
|
26
|
+
const formatted = formatError(err);
|
|
27
|
+
stderr += `${file}: ${formatted.message}\n`;
|
|
28
|
+
exitCode = formatted.exitCode;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (exitCode === 0) {
|
|
32
|
+
stdout += `\ncredits charged: ${totalCredits}\n`;
|
|
33
|
+
}
|
|
34
|
+
return { exitCode, stdout, stderr };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=toc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.js","sourceRoot":"","sources":["../../src/commands/toc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQ3C,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAe,EACf,OAAmB,EACnB,MAA4B;IAE5B,MAAM,KAAK,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,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types.d.ts","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/commands/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MarkdownScribeClient } from "@markdownscribe/sdk";
|
|
2
|
+
import type { CommandResult } from "./types.js";
|
|
3
|
+
export interface UrlOptions {
|
|
4
|
+
mode?: "clean" | "raw";
|
|
5
|
+
save?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function runUrl(url: string, options: UrlOptions, client: MarkdownScribeClient): Promise<CommandResult>;
|
|
8
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/commands/url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,MAAM,CAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAsBxB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
3
|
+
import { formatError } from "../output.js";
|
|
4
|
+
export async function runUrl(url, options, client) {
|
|
5
|
+
try {
|
|
6
|
+
const result = await client.urlToMd({ url, mode: options.mode ?? "clean" });
|
|
7
|
+
let stdout = "";
|
|
8
|
+
if (options.save) {
|
|
9
|
+
// UTF-8 sem BOM — corrige o bug de BOM do script mdscribe-url.ps1
|
|
10
|
+
// atual (Out-File -Encoding utf8 grava BOM).
|
|
11
|
+
writeFileSync(options.save, result.markdown, "utf8");
|
|
12
|
+
stdout += `saved to: ${options.save}\n`;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
stdout += result.markdown;
|
|
16
|
+
}
|
|
17
|
+
stdout += `\ncredits charged: ${result.meta.credits}\n`;
|
|
18
|
+
return { exitCode: 0, stdout, stderr: "" };
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (!(err instanceof MarkdownScribeApiError))
|
|
22
|
+
throw err;
|
|
23
|
+
const formatted = formatError(err);
|
|
24
|
+
return { exitCode: formatted.exitCode, stdout: "", stderr: `${formatted.message}\n` };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/commands/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQ3C,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,GAAW,EACX,OAAmB,EACnB,MAA4B;IAE5B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;QAC5E,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,kEAAkE;YAClE,6CAA6C;YAC7C,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACrD,MAAM,IAAI,aAAa,OAAO,CAAC,IAAI,IAAI,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC;QAC5B,CAAC;QAED,MAAM,IAAI,sBAAsB,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC;QAExD,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,CAAC,GAAG,YAAY,sBAAsB,CAAC;YAAE,MAAM,GAAG,CAAC;QACxD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;IACxF,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ConfigError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export interface ResolveConfigOptions {
|
|
4
|
+
cwd: string;
|
|
5
|
+
baseUrlFlag?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CliConfig {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveConfig(options: ResolveConfigOptions): CliConfig;
|
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAY,SAAQ,KAAK;CAAG;AAEzC,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAgBtE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { config as loadDotenv } from "dotenv";
|
|
4
|
+
const DEFAULT_BASE_URL = "https://api-production-d0eb.up.railway.app";
|
|
5
|
+
export class ConfigError extends Error {
|
|
6
|
+
}
|
|
7
|
+
// Resolução de chave: MDSCRIBE_API_KEY -> API_KEY_MAT (compat `railway run`)
|
|
8
|
+
// -> .env no cwd, nessa ordem (SPEC-010 §CLI). Resolução de URL: MDSCRIBE_URL
|
|
9
|
+
// -> --base-url -> default de produção.
|
|
10
|
+
export function resolveConfig(options) {
|
|
11
|
+
const dotenvPath = join(options.cwd, ".env");
|
|
12
|
+
const dotenvResult = existsSync(dotenvPath) ? loadDotenv({ path: dotenvPath }).parsed : undefined;
|
|
13
|
+
const apiKey = process.env["MDSCRIBE_API_KEY"] ?? process.env["API_KEY_MAT"] ?? dotenvResult?.["MDSCRIBE_API_KEY"];
|
|
14
|
+
if (!apiKey) {
|
|
15
|
+
throw new ConfigError("No API key found. Set MDSCRIBE_API_KEY (or API_KEY_MAT), or add MDSCRIBE_API_KEY to a .env file in the current directory.");
|
|
16
|
+
}
|
|
17
|
+
const baseUrl = options.baseUrlFlag ?? process.env["MDSCRIBE_URL"] ?? DEFAULT_BASE_URL;
|
|
18
|
+
return { apiKey, baseUrl };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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statSync } from "node:fs";
|
|
2
|
+
import { extname, join } from "node:path";
|
|
3
|
+
const MARKDOWN_EXTENSIONS = new Set([".md", ".mdx"]);
|
|
4
|
+
// Não-recursiva por design (SPEC-010 §CLI) — pasta lista só os arquivos no
|
|
5
|
+
// próprio nível, mesma regra que os scripts PowerShell atuais já seguem
|
|
6
|
+
// (exceto mdscribe-fm.ps1 -Recurse, que fica fora de escopo do CLI).
|
|
7
|
+
export function collectMarkdownFiles(path) {
|
|
8
|
+
const stat = statSync(path);
|
|
9
|
+
if (!stat.isDirectory()) {
|
|
10
|
+
return [path];
|
|
11
|
+
}
|
|
12
|
+
return readdirSync(path)
|
|
13
|
+
.filter((name) => MARKDOWN_EXTENSIONS.has(extname(name).toLowerCase()))
|
|
14
|
+
.map((name) => join(path, name))
|
|
15
|
+
.sort();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fs-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-utils.js","sourceRoot":"","sources":["../src/fs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAErD,2EAA2E;AAC3E,wEAAwE;AACxE,qEAAqE;AACrE,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,WAAW,CAAC,IAAI,CAAC;SACrB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;SACtE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SAC/B,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
2
|
+
export declare function isTty(stream: NodeJS.WriteStream, jsonFlag: boolean): boolean;
|
|
3
|
+
export interface FormattedError {
|
|
4
|
+
exitCode: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function formatError(err: MarkdownScribeApiError): FormattedError;
|
|
8
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAG5E;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,wBAAgB,WAAW,CAAC,GAAG,EAAE,sBAAsB,GAAG,cAAc,CA0BvE"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MarkdownScribeApiError } from "@markdownscribe/sdk";
|
|
2
|
+
export function isTty(stream, jsonFlag) {
|
|
3
|
+
if (jsonFlag)
|
|
4
|
+
return false;
|
|
5
|
+
return Boolean(stream.isTTY);
|
|
6
|
+
}
|
|
7
|
+
// Mapeia as 3 famílias de erro reais da API (toHttpError-shaped,
|
|
8
|
+
// app.onError 500, e o grupo ad-hoc do serviço de extração — pesquisa do
|
|
9
|
+
// D-037) pro contrato de exit code do CLI (SPEC-010 §CLI, 0-7). balance e
|
|
10
|
+
// retry_after_seconds precisam sobreviver na mensagem — são o dado que
|
|
11
|
+
// ancora a verificação de cobrança (blueprint §2.5.2).
|
|
12
|
+
export function formatError(err) {
|
|
13
|
+
const detail = errorDetail(err);
|
|
14
|
+
switch (err.status) {
|
|
15
|
+
case 401:
|
|
16
|
+
return { exitCode: 2, message: `Authentication failed: ${detail}` };
|
|
17
|
+
case 402:
|
|
18
|
+
return { exitCode: 3, message: `Insufficient credits (balance: ${err.body["balance"]}): ${detail}` };
|
|
19
|
+
case 429:
|
|
20
|
+
return {
|
|
21
|
+
exitCode: 4,
|
|
22
|
+
message: `Rate limited (retry after ${err.body["retry_after_seconds"]}s): ${detail}`,
|
|
23
|
+
};
|
|
24
|
+
case 400:
|
|
25
|
+
case 413:
|
|
26
|
+
case 422:
|
|
27
|
+
return { exitCode: 5, message: `Invalid request: ${detail}` };
|
|
28
|
+
case 503:
|
|
29
|
+
case 504:
|
|
30
|
+
case 424:
|
|
31
|
+
return { exitCode: 6, message: `Upstream service unavailable: ${detail}` };
|
|
32
|
+
case 404:
|
|
33
|
+
return { exitCode: 7, message: `Not found: ${detail}` };
|
|
34
|
+
default:
|
|
35
|
+
return { exitCode: 1, message: `MarkdownScribe error: ${detail}` };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function errorDetail(err) {
|
|
39
|
+
return err.body.hint ? `${err.body.error} — ${err.body.hint}` : err.body.error;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,MAAM,UAAU,KAAK,CAAC,MAA0B,EAAE,QAAiB;IACjE,IAAI,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,OAAO,C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C,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;AACjF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "markdownscribe",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "MarkdownScribe — the
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MarkdownScribe CLI — frontmatter, TOC, lint, format, mermaid and url-to-markdown from the terminal, built for humans and LLM/agent tooling.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown",
|
|
7
|
+
"cli",
|
|
8
|
+
"frontmatter",
|
|
9
|
+
"toc",
|
|
10
|
+
"table-of-contents",
|
|
11
|
+
"lint",
|
|
12
|
+
"markdown-lint",
|
|
13
|
+
"format",
|
|
14
|
+
"mermaid",
|
|
15
|
+
"url-to-markdown",
|
|
16
|
+
"command-line",
|
|
17
|
+
"llm-tools",
|
|
18
|
+
"agent-tools",
|
|
19
|
+
"mdscribe"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"markdownscribe": "./dist/bin.js",
|
|
24
|
+
"mdscribe": "./dist/bin.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^13.0.0",
|
|
35
|
+
"dotenv": "^16.4.0",
|
|
36
|
+
"@markdownscribe/sdk": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"postgres": "^3.4.5",
|
|
41
|
+
"rimraf": "^6.0.0",
|
|
42
|
+
"typescript": "^5.6.0",
|
|
43
|
+
"vitest": "^4.1.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.json",
|
|
47
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"lint": "echo 'lint TBD (eslint em fase futura)'",
|
|
51
|
+
"clean": "rimraf dist coverage .turbo *.tsbuildinfo"
|
|
52
|
+
}
|
|
53
|
+
}
|