All files / infrastructure/scripts/src/map/domain render.ts

100% Statements 16/16
100% Branches 4/4
100% Functions 7/7
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79        1x                                                                   6x   1x 5x 5x     1x         20x 16x   5x             5x         1x 4x                   16x    
import type { Capability, Doc, Kind } from "./capabilities.ts";
import { documentedBy } from "./capabilities.ts";
 
/** Leads are hard-wrapped here, not joined from a sentence: the output has to obey `house-docs`. */
const SECTIONS: { kind: Kind; heading: string; lead: string[] }[] = [
    {
        kind: "command",
        heading: "Commands",
        lead: [
            "Root commands run against affected projects only. The per-project rows below them are the",
            "ones the root doesn't expose — `lint`, `typecheck`, `test` and `build` exist on every project",
            "and are documented once in the [root README](../README.md#getting-started).",
        ],
    },
    {
        kind: "hook",
        heading: "Git hooks",
        lead: [
            "These run themselves, but only after `pnpm quick-start` — a fresh clone has no hooks at all until",
            "that per-clone setup runs.",
        ],
    },
    {
        kind: "workflow",
        heading: "Workflows",
        lead: ["GitHub Actions, named as the Actions tab shows them rather than by filename."],
    },
    {
        kind: "skill",
        heading: "Agent skills",
        lead: [
            "Instructions an agent loads for one kind of task. Worth reading as a human too: a skill is the",
            "shortest statement of how a task is meant to go here.",
        ],
    },
];
 
/** Relative to `docs/FEATURES.md`, which sits one directory below the repo root. */
const link = (path: string): string => `[\`${path}\`](../${path})`;
 
const row = (capability: Capability, docs: Doc[]): string => {
    const explains = documentedBy(capability, docs);
    return `| \`${capability.invocation}\` | ${link(capability.source)} | ${explains ? link(explains) : "—"} |`;
};
 
const section = (
    { kind, heading, lead }: { kind: Kind; heading: string; lead: string[] },
    capabilities: Capability[],
    docs: Doc[],
): string[] => {
    const rows = capabilities.filter((capability) => capability.kind === kind);
    if (rows.length === 0) return [];
 
    return [
        `## ${heading}`,
        "",
        ...lead,
        "",
        "| Capability | Declared in | Explained in |",
        "| --- | --- | --- |",
        ...rows.map((capability) => row(capability, docs)),
        "",
    ];
};
 
export const render = (capabilities: Capability[], docs: Doc[]): string =>
    [
        "# 🗺 Features",
        "",
        "Every command, git hook, workflow and agent skill in this repo, with the doc that explains each",
        "one. Start here when you don't yet know what to go and read.",
        "",
        "**Generated by `pnpm docs:map` — do not edit.** It is an index and nothing more: the *why* lives",
        "in the doc each row points at, so there is no prose here that can drift from its source. A row",
        "with no doc is a real gap rather than a rendering artifact.",
        "",
        ...SECTIONS.flatMap((meta) => section(meta, capabilities, docs)),
    ].join("\n");