@cosyte/script-utils 0.1.8 → 0.1.10

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.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Types for `@cosyte/script-utils/docs-content`: the structure check for a library's
3
+ * `docs-content/` folder, the pages docs.cosyte.com renders. The standard it checks is decision
4
+ * record 0006 in cosyte/config.
5
+ */
6
+
7
+ /** The folder this check reads, at the repository root. */
8
+ export declare const DOCS_DIR: "docs-content";
9
+
10
+ /** The sidebar file inside it. */
11
+ export declare const SIDEBARS_FILE: "sidebars.json";
12
+
13
+ /** The folder the reference generator owns. Its pages are read only for their headings. */
14
+ export declare const GENERATED_DIR: "api";
15
+
16
+ /** How a link into the generated reference starts. */
17
+ export declare const REFERENCE_LINK_PREFIX: "./api/";
18
+
19
+ /** The pages every library has, by id. */
20
+ export declare const REQUIRED_PAGES: readonly string[];
21
+
22
+ /** One top-level category of the sidebar. */
23
+ export interface DocsCategory {
24
+ /** The label, exactly as the sidebar writes it. */
25
+ readonly label: string;
26
+ /** Whether every library has this category. */
27
+ readonly required: boolean;
28
+ /** The page the category must open with, or null when any page may. */
29
+ readonly first: string | null;
30
+ }
31
+
32
+ /** The top-level categories, in the only order they may appear. */
33
+ export declare const CATEGORIES: readonly DocsCategory[];
34
+
35
+ /** The two fixed pages, listed last at the top level of the sidebar, in this order. */
36
+ export declare const QUALITY_PAGES: readonly ["testing-and-quality", "performance"];
37
+
38
+ /** The heading of the section each quality page's generated numbers go in. */
39
+ export declare const NUMBERS_HEADING: "## Current numbers";
40
+
41
+ /**
42
+ * What the "Current numbers" section holds in the repository: this text and nothing else, however
43
+ * its lines wrap. The release replaces the section with the numbers it measured.
44
+ */
45
+ export declare const NUMBERS_PLACEHOLDER: string;
46
+
47
+ /** The label the docs site gives the generated reference. A sidebar never writes it. */
48
+ export declare const RESERVED_LABEL: "API Reference";
49
+
50
+ /** The front matter keys every page carries. */
51
+ export declare const FRONT_MATTER_KEYS: readonly string[];
52
+
53
+ /** The front matter keys a page must not carry. */
54
+ export declare const FORBIDDEN_KEYS: readonly string[];
55
+
56
+ /** The longest description, in characters. */
57
+ export declare const DESCRIPTION_LIMIT: 160;
58
+
59
+ /** A page's file name, without `.md`: lower-case words joined by single hyphens. */
60
+ export declare const PAGE_NAME: RegExp;
61
+
62
+ /** A rule a finding can carry. */
63
+ export type DocsContentRule =
64
+ | "sidebar"
65
+ | "listing"
66
+ | "required-page"
67
+ | "front-matter"
68
+ | "file-name"
69
+ | "numbers"
70
+ | "reference-link";
71
+
72
+ /** Every rule, with what it requires. */
73
+ export declare const DOCS_CONTENT_RULES: Readonly<Record<DocsContentRule, string>>;
74
+
75
+ /** Raised when the check cannot read its input; the command line turns it into exit 2. */
76
+ export declare class DocsContentRefusal extends Error {}
77
+
78
+ /** One front matter value and the line it is on. */
79
+ export interface FrontMatterField {
80
+ /** The value, unquoted. */
81
+ value: string;
82
+ /** Its 1-based line in the page. */
83
+ line: number;
84
+ }
85
+
86
+ /** What {@link parseFrontMatter} read. */
87
+ export interface FrontMatter {
88
+ /** Every key read, with its value. */
89
+ fields: Map<string, FrontMatterField>;
90
+ /** Each line it could not read, with why. */
91
+ errors: { line: number; message: string }[];
92
+ /** Whether the page opens with front matter at all. */
93
+ present: boolean;
94
+ }
95
+
96
+ /**
97
+ * Read a page's front matter: one `key: value` per line between a first line `---` and the next.
98
+ *
99
+ * @param text - The page.
100
+ * @returns The fields, the errors and whether a block was there.
101
+ */
102
+ export declare function parseFrontMatter(text: string): FrontMatter;
103
+
104
+ /**
105
+ * Every anchor the headings of a page get on the docs site: each heading's text lower-cased, with
106
+ * what the site's slugger drops dropped and each space turned into a hyphen; a repeated slug is
107
+ * numbered `-1`, `-2` and so on in page order. Headings in fenced code are not read.
108
+ *
109
+ * @param text - A page.
110
+ * @returns Its anchors.
111
+ */
112
+ export declare function headingAnchors(text: string): Set<string>;
113
+
114
+ /** A docs-content tree, read. */
115
+ export interface DocsContentInput {
116
+ /** The `.md` files at the top of docs-content/, by file name without `.md`. */
117
+ pages: { name: string; text: string }[];
118
+ /** The text of sidebars.json, or null when there is none. */
119
+ sidebars: string | null;
120
+ /** Markdown that is not a top-level `.md` page and is not under api/, relative to docs-content/. */
121
+ misplaced?: string[];
122
+ /**
123
+ * The generated `.md` pages, by their path under api/, read for the headings a link into the
124
+ * reference names. Without it, every such link names a page that is not there.
125
+ */
126
+ reference?: Map<string, string>;
127
+ }
128
+
129
+ /** One finding. */
130
+ export interface DocsContentFinding {
131
+ /** The file, relative to docs-content/. */
132
+ file: string;
133
+ /** The 1-based line, or 0 when the finding is about the whole file. */
134
+ line: number;
135
+ /** The rule it breaks. */
136
+ rule: DocsContentRule;
137
+ /** What is wrong, in plain words. */
138
+ message: string;
139
+ }
140
+
141
+ /**
142
+ * Check a docs-content tree that has already been read.
143
+ *
144
+ * @param input - The pages, the sidebar text and any misplaced markdown.
145
+ * @returns Every finding; empty when the tree keeps the standard.
146
+ */
147
+ export declare function checkDocsContent(input: DocsContentInput): DocsContentFinding[];
148
+
149
+ /**
150
+ * Read docs-content/ under a repository root: the pages, the sidebar, and the generated pages under
151
+ * api/ for their headings.
152
+ *
153
+ * @param root - The repository root.
154
+ * @returns The tree, read.
155
+ * @throws {@link DocsContentRefusal} When the folder is missing or a file in it cannot be read.
156
+ */
157
+ export declare function readDocsContent(root: string): Required<DocsContentInput>;
158
+
159
+ /** A stream the command line writes to. */
160
+ export interface DocsContentStream {
161
+ write(text: string): unknown;
162
+ }
163
+
164
+ /** What {@link runDocsContentCheck} takes. */
165
+ export interface DocsContentCheckOptions {
166
+ /** CLI arguments; only `--dir <path>` is accepted. */
167
+ argv?: string[];
168
+ /** The repository root. Default: the working directory. */
169
+ dir?: string;
170
+ /** Where the clean report goes. Default: the process's stdout. */
171
+ stdout?: DocsContentStream;
172
+ /** Where findings and refusals go. Default: the process's stderr. */
173
+ stderr?: DocsContentStream;
174
+ }
175
+
176
+ /**
177
+ * Check docs-content/ in a repository and report.
178
+ *
179
+ * @param options - Arguments, the root and the streams.
180
+ * @returns 0 clean, 1 a finding, 2 the check could not run.
181
+ */
182
+ export declare function runDocsContentCheck(options?: DocsContentCheckOptions): 0 | 1 | 2;