@textmode/docs 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.
Files changed (41) hide show
  1. package/README.md +132 -0
  2. package/index.d.ts +37 -0
  3. package/package.json +60 -0
  4. package/src/cli/textmode-docs.mjs +198 -0
  5. package/src/index.js +23 -0
  6. package/src/internal/config.js +380 -0
  7. package/src/internal/lib/api-doc-checks.mjs +147 -0
  8. package/src/internal/lib/api-doc-routes.mjs +93 -0
  9. package/src/internal/lib/example-checks.mjs +405 -0
  10. package/src/internal/lib/jsdoc-comments.mjs +78 -0
  11. package/src/internal/lib/reflection-policy.mjs +113 -0
  12. package/src/internal/lib/reporting.mjs +23 -0
  13. package/src/internal/operations.js +271 -0
  14. package/src/internal/reflection-kinds.js +21 -0
  15. package/src/internal/typedoc-plugins/accessor-docs-normalizer/README.md +45 -0
  16. package/src/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.js +53 -0
  17. package/src/internal/typedoc-plugins/accessor-docs-normalizer/index.js +32 -0
  18. package/src/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.js +144 -0
  19. package/src/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.js +28 -0
  20. package/src/internal/typedoc-plugins/all-member-pages-router/README.md +57 -0
  21. package/src/internal/typedoc-plugins/all-member-pages-router/child-pages.js +65 -0
  22. package/src/internal/typedoc-plugins/all-member-pages-router/constants.js +58 -0
  23. package/src/internal/typedoc-plugins/all-member-pages-router/index.js +18 -0
  24. package/src/internal/typedoc-plugins/all-member-pages-router/member-paths.js +48 -0
  25. package/src/internal/typedoc-plugins/all-member-pages-router/member-reflections.js +164 -0
  26. package/src/internal/typedoc-plugins/all-member-pages-router/namespace-paths.js +44 -0
  27. package/src/internal/typedoc-plugins/all-member-pages-router/router.js +58 -0
  28. package/src/internal/typedoc-plugins/api-frontmatter/README.md +66 -0
  29. package/src/internal/typedoc-plugins/api-frontmatter/constants.js +52 -0
  30. package/src/internal/typedoc-plugins/api-frontmatter/descriptions.js +87 -0
  31. package/src/internal/typedoc-plugins/api-frontmatter/frontmatter.js +56 -0
  32. package/src/internal/typedoc-plugins/api-frontmatter/index.js +39 -0
  33. package/src/internal/typedoc-plugins/api-frontmatter/library-context.js +38 -0
  34. package/src/internal/typedoc-plugins/api-frontmatter/reflection-metadata.js +95 -0
  35. package/src/internal/typedoc-plugins/include-code-examples/README.md +40 -0
  36. package/src/internal/typedoc-plugins/include-code-examples/code-fences.js +55 -0
  37. package/src/internal/typedoc-plugins/include-code-examples/example-metadata.js +41 -0
  38. package/src/internal/typedoc-plugins/include-code-examples/index.js +23 -0
  39. package/src/internal/typedoc-plugins/include-code-examples/transform-markdown.js +33 -0
  40. package/src/internal/typedoc-plugins/strip-api-self-links/index.js +117 -0
  41. package/src/internal/typedoc-runner.js +138 -0
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # @textmode/docs
2
+
3
+ Shared documentation generation and validation for public textmode.js
4
+ libraries. The package owns the TypeDoc stack, Markdown plugins, public API
5
+ checks, example validation, and API-link maintenance behind one command.
6
+
7
+ ## Ownership
8
+
9
+ - `package.json` owns the package name, description, and TypeScript dependency.
10
+ - `textmode.docs.config.mjs` owns project-specific documentation policy.
11
+ - `@textmode/docs` owns TypeDoc and its plugins, shared defaults, rendering,
12
+ validation, link editing, and command behavior.
13
+
14
+ Consumers should not define `package.json#typedocOptions`, maintain another
15
+ tooling config, invoke TypeDoc directly, or import package internals.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install --save-dev @textmode/docs typescript
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ Conventional projects need no configuration file. Create
26
+ `textmode.docs.config.mjs` at the project root only for policy that differs
27
+ from the shared defaults:
28
+
29
+ ```js
30
+ import { defineDocs } from '@textmode/docs';
31
+
32
+ export default defineDocs({
33
+ entryPoints: ['src/index.ts'],
34
+ linkEntryPoints: [
35
+ {
36
+ path: 'src/index.ts',
37
+ tsconfig: 'tsconfig.json',
38
+ namespaceExportsOnly: false,
39
+ },
40
+ ],
41
+ sourceRoots: ['src'],
42
+ outputDir: 'api/example-package',
43
+ apiBaseUrl: 'https://code.textmode.art/api/example-package',
44
+ tsconfig: 'tsconfig.json',
45
+ memberPageKinds: ['method', 'property', 'accessor'],
46
+ stripApiSelfLinks: 'full',
47
+ checks: {
48
+ apiLinks: ['class', 'interface', 'typeAlias', 'enum', 'variable', 'function', 'method', 'accessor', 'property'],
49
+ docstrings: [
50
+ 'class',
51
+ 'interface',
52
+ 'typeAlias',
53
+ 'enum',
54
+ 'variable',
55
+ 'function',
56
+ 'method',
57
+ 'accessor',
58
+ 'property',
59
+ ],
60
+ examples: ['function', 'method', 'accessor'],
61
+ },
62
+ examples: {
63
+ checkSketches: true,
64
+ forbidGallerySourceBase: true,
65
+ },
66
+ typedoc: {},
67
+ });
68
+ ```
69
+
70
+ Paths resolve relative to the project root containing `package.json`.
71
+
72
+ Supported reflection names are `class`, `interface`, `typeAlias`, `enum`,
73
+ `variable`, `function`, `method`, `accessor`, and `property`. Set
74
+ `examples: false` to disable gallery, manifest, and sketch checks for a package
75
+ without examples.
76
+
77
+ The `typedoc` object can override registered TypeDoc options except
78
+ `entryPoints`, `out`, `tsconfig`, `plugin`, `router`, `emit`, `watch`,
79
+ `treatWarningsAsErrors`, `treatValidationWarningsAsErrors`, and options whose
80
+ names begin with `textmode`.
81
+
82
+ ### Defaults
83
+
84
+ | Setting | Default |
85
+ | ------------------------------ | ---------------------------------------------- |
86
+ | Package name and description | `package.json` |
87
+ | Entrypoint and link entrypoint | `src/index.ts` |
88
+ | Source roots | Derived from link entrypoints |
89
+ | TypeScript config | `tsconfig.json` |
90
+ | Output | `api/<package-name>` |
91
+ | Hosted API URL | `https://code.textmode.art/api/<package-name>` |
92
+ | Member pages | Methods, properties, and accessors |
93
+ | Self-link stripping | `full` |
94
+ | Sorting | Source order |
95
+ | API-link kinds | All supported reflection kinds |
96
+ | Required docstrings | All supported reflection kinds |
97
+ | Required examples | Functions, methods, and accessors |
98
+ | Example checks | Gallery, manifest, and sketch checks enabled |
99
+ | Gallery source bases | Hardcoded source bases rejected |
100
+
101
+ Configuration precedence is shared defaults, derived package metadata,
102
+ `textmode.docs.config.mjs`, then command-owned overrides such as `--out`,
103
+ strict checking, and watch mode. Use `--show-config` to inspect the effective
104
+ values and the origin of every setting.
105
+
106
+ ## Commands
107
+
108
+ ```text
109
+ textmode-docs check
110
+ textmode-docs build [--out <directory>]
111
+ textmode-docs watch [--out <directory>]
112
+ textmode-docs links add
113
+ textmode-docs api-check [--include-accessors]
114
+ ```
115
+
116
+ - `check` renders to fresh temporary storage, treats TypeDoc and validation
117
+ warnings as errors, validates routes, public API documentation, links, and
118
+ enabled example policies, then removes the temporary output.
119
+ - `build` cleans and renders the configured output directory.
120
+ - `watch` performs an initial render and rebuilds through TypeDoc's watcher.
121
+ - `links add` derives current routes in temporary storage and idempotently
122
+ inserts or updates JSDoc API links inside `sourceRoots`.
123
+ - `api-check` runs only public API documentation policy.
124
+ `--include-accessors` adds accessors to policies that normally omit them.
125
+
126
+ Every command accepts `--cwd`, `--config`, `--show-config`, `--help`, and
127
+ `--version`. `build` and `watch` also accept `--out`. Unknown commands, flags,
128
+ missing values, and extra positional arguments are rejected.
129
+
130
+ Normal results are written to stdout and diagnostics to stderr. Exit status `0`
131
+ means success, `1` means documentation or content validation failed, and `2`
132
+ means invocation, configuration, dependency, input, or internal-tool failure.
package/index.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ export type ReflectionKindName =
2
+ 'class' | 'interface' | 'typeAlias' | 'enum' | 'variable' | 'function' | 'method' | 'accessor' | 'property';
3
+
4
+ export type MemberPageKind = 'method' | 'property' | 'accessor';
5
+
6
+ export interface LinkEntryPoint {
7
+ path: string;
8
+ tsconfig?: string;
9
+ namespaceExportsOnly?: boolean;
10
+ }
11
+
12
+ export interface DocsChecks {
13
+ apiLinks?: ReflectionKindName[];
14
+ docstrings?: ReflectionKindName[];
15
+ examples?: ReflectionKindName[];
16
+ }
17
+
18
+ export interface ExamplesPolicy {
19
+ checkSketches?: boolean;
20
+ forbidGallerySourceBase?: boolean;
21
+ }
22
+
23
+ export interface TextmodeDocsConfig {
24
+ entryPoints?: string[];
25
+ linkEntryPoints?: LinkEntryPoint[];
26
+ sourceRoots?: string[];
27
+ outputDir?: string;
28
+ apiBaseUrl?: string;
29
+ tsconfig?: string;
30
+ memberPageKinds?: MemberPageKind[];
31
+ stripApiSelfLinks?: 'minimal' | 'full';
32
+ checks?: DocsChecks;
33
+ examples?: false | ExamplesPolicy;
34
+ typedoc?: Record<string, unknown>;
35
+ }
36
+
37
+ export declare function defineDocs<const T extends TextmodeDocsConfig>(config: T): T;
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@textmode/docs",
3
+ "version": "0.1.0",
4
+ "description": "Shared documentation generation and validation for the textmode.js ecosystem",
5
+ "keywords": [
6
+ "textmode",
7
+ "typedoc",
8
+ "documentation",
9
+ "validation"
10
+ ],
11
+ "author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
12
+ "license": "MIT",
13
+ "homepage": "https://code.textmode.art",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/humanbydefinition/textmode-tooling.git",
17
+ "directory": "packages/docs"
18
+ },
19
+ "type": "module",
20
+ "engines": {
21
+ "node": ">=20.8.1"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./index.d.ts",
26
+ "import": "./src/index.js"
27
+ }
28
+ },
29
+ "bin": {
30
+ "textmode-docs": "./src/cli/textmode-docs.mjs"
31
+ },
32
+ "files": [
33
+ "src",
34
+ "index.d.ts",
35
+ "README.md"
36
+ ],
37
+ "dependencies": {
38
+ "typedoc": "^0.28.20",
39
+ "typedoc-plugin-frontmatter": "^1.3.1",
40
+ "typedoc-plugin-markdown": "^4.12.0",
41
+ "typedoc-vitepress-theme": "^1.1.3"
42
+ },
43
+ "peerDependencies": {
44
+ "typescript": ">=5.9 <7"
45
+ },
46
+ "devDependencies": {
47
+ "typescript": "^6.0.3"
48
+ },
49
+ "scripts": {
50
+ "check": "npm run check:format && npm run lint && npm run test && npm run check:package && npm run check:pack",
51
+ "check:format": "prettier --check .",
52
+ "check:package": "node scripts/check-package.mjs",
53
+ "check:pack": "node scripts/pack-smoke.mjs",
54
+ "lint": "node --check src/index.js && node --check src/cli/textmode-docs.mjs && node --check src/internal/*.js && node --check src/internal/lib/*.mjs",
55
+ "test": "vitest run"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import process from 'node:process';
5
+ import { parseArgs } from 'node:util';
6
+
7
+ import { formatResolvedConfig, resolveDocsConfig } from '../internal/config.js';
8
+ import {
9
+ addApiLinks,
10
+ checkApiDocumentation,
11
+ checkDocumentation,
12
+ generateDocumentation,
13
+ watchDocumentation,
14
+ } from '../internal/operations.js';
15
+
16
+ const PACKAGE_JSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
17
+ const COMMANDS = new Set(['check', 'build', 'watch', 'api-check']);
18
+
19
+ function printGeneralHelp() {
20
+ console.log(`@textmode/docs ${PACKAGE_JSON.version}`);
21
+ console.log('');
22
+ console.log('Usage: textmode-docs <command> [options]');
23
+ console.log('');
24
+ console.log('Commands:');
25
+ console.log(' check Validate generated docs, public API docs, and examples');
26
+ console.log(' build [--out <directory>] Generate documentation');
27
+ console.log(' watch [--out <directory>] Generate documentation and watch for changes');
28
+ console.log(' links add Insert or update public API links in source JSDoc');
29
+ console.log(' api-check [--include-accessors]');
30
+ console.log(' Run the focused public API documentation check');
31
+ console.log('');
32
+ console.log('Common options:');
33
+ console.log(' --cwd <directory> Project root containing package.json');
34
+ console.log(' --config <file> Config path relative to the project root');
35
+ console.log(' --show-config Print resolved configuration and exit');
36
+ console.log(' --help, -h Show help');
37
+ console.log(' --version Show version');
38
+ }
39
+
40
+ function printCommandHelp(command) {
41
+ const usage = {
42
+ check: 'textmode-docs check [--cwd <directory>] [--config <file>] [--show-config]',
43
+ build: 'textmode-docs build [--out <directory>] [--cwd <directory>] [--config <file>] [--show-config]',
44
+ watch: 'textmode-docs watch [--out <directory>] [--cwd <directory>] [--config <file>] [--show-config]',
45
+ 'api-check':
46
+ 'textmode-docs api-check [--include-accessors] [--cwd <directory>] [--config <file>] [--show-config]',
47
+ 'links add': 'textmode-docs links add [--cwd <directory>] [--config <file>] [--show-config]',
48
+ };
49
+ console.log(`Usage: ${usage[command]}`);
50
+ }
51
+
52
+ function parseCli(argv) {
53
+ const parsed = parseArgs({
54
+ args: argv,
55
+ allowPositionals: true,
56
+ strict: true,
57
+ options: {
58
+ cwd: { type: 'string' },
59
+ config: { type: 'string' },
60
+ out: { type: 'string' },
61
+ 'show-config': { type: 'boolean' },
62
+ 'include-accessors': { type: 'boolean' },
63
+ help: { type: 'boolean', short: 'h' },
64
+ version: { type: 'boolean' },
65
+ },
66
+ });
67
+
68
+ if (parsed.values.version) {
69
+ if (parsed.positionals.length > 0) {
70
+ throw new Error('--version does not accept a command.');
71
+ }
72
+ return { action: 'version' };
73
+ }
74
+
75
+ if (parsed.positionals.length === 0) {
76
+ if (parsed.values.help) {
77
+ return { action: 'help' };
78
+ }
79
+ throw new Error('Missing command. Run textmode-docs --help for usage.');
80
+ }
81
+
82
+ let command = parsed.positionals[0];
83
+ let expectedPositionals = 1;
84
+ if (command === 'links') {
85
+ if (parsed.positionals[1] !== 'add') {
86
+ throw new Error('The links command requires the "add" subcommand.');
87
+ }
88
+ command = 'links add';
89
+ expectedPositionals = 2;
90
+ } else if (!COMMANDS.has(command)) {
91
+ throw new Error(`Unknown command "${command}".`);
92
+ }
93
+ if (parsed.positionals.length !== expectedPositionals) {
94
+ throw new Error(`Unexpected positional argument "${parsed.positionals[expectedPositionals]}".`);
95
+ }
96
+
97
+ if (parsed.values.out !== undefined && command !== 'build' && command !== 'watch') {
98
+ throw new Error('--out is supported only by build and watch.');
99
+ }
100
+ if (parsed.values['include-accessors'] && command !== 'api-check') {
101
+ throw new Error('--include-accessors is supported only by api-check.');
102
+ }
103
+
104
+ return {
105
+ action: parsed.values.help ? 'command-help' : 'run',
106
+ command,
107
+ values: parsed.values,
108
+ };
109
+ }
110
+
111
+ function commandDetails(command) {
112
+ return {
113
+ name: command,
114
+ emit: command === 'api-check' || command === 'links add' || command === 'check' ? 'temporary' : 'docs',
115
+ strict: command === 'check',
116
+ watch: command === 'watch',
117
+ origins: {
118
+ emit: `command:${command}`,
119
+ strict: `command:${command}`,
120
+ watch: `command:${command}`,
121
+ },
122
+ };
123
+ }
124
+
125
+ async function run(argv) {
126
+ let cli;
127
+ try {
128
+ cli = parseCli(argv);
129
+ } catch (error) {
130
+ console.error(error instanceof Error ? error.message : String(error));
131
+ process.exitCode = 2;
132
+ return;
133
+ }
134
+
135
+ if (cli.action === 'help') {
136
+ printGeneralHelp();
137
+ return;
138
+ }
139
+ if (cli.action === 'version') {
140
+ console.log(PACKAGE_JSON.version);
141
+ return;
142
+ }
143
+ if (cli.action === 'command-help') {
144
+ printCommandHelp(cli.command);
145
+ return;
146
+ }
147
+
148
+ try {
149
+ const config = await resolveDocsConfig({
150
+ cwd: cli.values.cwd,
151
+ configPath: cli.values.config,
152
+ out: cli.values.out,
153
+ });
154
+ if (cli.values['show-config']) {
155
+ console.log(
156
+ JSON.stringify(
157
+ {
158
+ ...formatResolvedConfig(config),
159
+ command: commandDetails(cli.command),
160
+ },
161
+ null,
162
+ 2
163
+ )
164
+ );
165
+ return;
166
+ }
167
+
168
+ let result;
169
+ switch (cli.command) {
170
+ case 'check':
171
+ result = await checkDocumentation(config);
172
+ break;
173
+ case 'build':
174
+ result = await generateDocumentation(config);
175
+ break;
176
+ case 'watch':
177
+ result = await watchDocumentation(config);
178
+ break;
179
+ case 'api-check':
180
+ result = await checkApiDocumentation(config, {
181
+ includeAccessors: cli.values['include-accessors'],
182
+ });
183
+ break;
184
+ case 'links add':
185
+ result = await addApiLinks(config);
186
+ break;
187
+ }
188
+
189
+ if (!result?.ok) {
190
+ process.exitCode = 1;
191
+ }
192
+ } catch (error) {
193
+ console.error(error instanceof Error ? (error.stack ?? error.message) : String(error));
194
+ process.exitCode = 2;
195
+ }
196
+ }
197
+
198
+ await run(process.argv.slice(2));
package/src/index.js ADDED
@@ -0,0 +1,23 @@
1
+ const CONFIG_MARKER = Symbol.for('@textmode/docs/config');
2
+
3
+ /**
4
+ * Define project-specific documentation policy.
5
+ *
6
+ * @template {import('../index.d.ts').TextmodeDocsConfig} T
7
+ * @param {T} config
8
+ * @returns {T}
9
+ */
10
+ export function defineDocs(config) {
11
+ if (config === null || typeof config !== 'object' || Array.isArray(config)) {
12
+ throw new TypeError('defineDocs expects a configuration object.');
13
+ }
14
+
15
+ Object.defineProperty(config, CONFIG_MARKER, {
16
+ configurable: false,
17
+ enumerable: false,
18
+ value: true,
19
+ writable: false,
20
+ });
21
+
22
+ return config;
23
+ }