feat: add kitchen view command and parser skeleton (task 0003)

Cut the first complete thread through both layers with the smallest set
of node types.

@kitchen-md/core gains a pure, total `parse` returning a
`DocumentAST` of `{ frontmatter, blocks, diagnostics }`, built from a
minimal remark pipeline (remark-parse + remark-frontmatter) with an
internal translation layer to core's own types. This slice models
frontmatter passthrough, HeadingBlock, ParagraphBlock, and TextNode;
remark's mdast does not surface in the public API.

@kitchen-md/bin gains the `view` subcommand (commander) that reads a
file, calls `parse`, and passes the AST to a pure `render` that returns
an ANSI-styled string via chalk (auto-suppressed off a TTY). Frontmatter
prints as raw YAML followed by a separator, headings styled distinctly
by level, paragraphs as prose. A missing argument prints usage and a
missing/unreadable file a human-readable error, both exiting 1.

Richer blocks/inline plus raw fallbacks are task 0004; malformed
frontmatter diagnostics and the basic.md smoke test are task 0007.
This commit is contained in:
2026-07-26 07:24:32 -04:00
parent fdede89e0c
commit d1c1f330c5
15 changed files with 836 additions and 14 deletions

View File

@@ -1,6 +1,25 @@
import { describe, test } from "bun:test";
import { describe, expect, test } from "bun:test";
import { runCli } from "./test-support.ts";
const CLI = `${import.meta.dir}/index.ts`;
describe("cli", () => {
test.todo("exits with non-zero code when no file argument is given");
test.todo("exits with non-zero code when file does not exist");
test("exits with non-zero code when no file argument is given", async () => {
const { exitCode, stderr } = await runCli(["view"], CLI);
expect(exitCode).not.toBe(0);
expect(stderr).toMatch(/missing required argument|usage/i);
});
test("exits with non-zero code when file does not exist", async () => {
const { exitCode, stderr } = await runCli(
["view", "/no/such/kitchen-recipe-does-not-exist.md"],
CLI,
);
expect(exitCode).toBe(1);
expect(stderr.trim().length).toBeGreaterThan(0);
expect(stderr).toMatch(/cannot read|no such file|ENOENT/i);
expect(stderr).toContain("/no/such/kitchen-recipe-does-not-exist.md");
});
});