@textmode/docs 0.2.1 → 0.3.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 +5 -0
- package/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/internal/config.js +7 -0
- package/src/internal/operations.js +2 -0
- package/src/internal/typedoc-runner.js +83 -22
package/README.md
CHANGED
|
@@ -78,6 +78,10 @@ The `typedoc` object can override registered TypeDoc options except
|
|
|
78
78
|
`treatWarningsAsErrors`, `treatValidationWarningsAsErrors`, and options whose
|
|
79
79
|
names begin with `textmode`.
|
|
80
80
|
|
|
81
|
+
`editLink: true` enables the "Edit this page on GitHub" link on generated
|
|
82
|
+
API pages for the package. The default (`false`) omits the link because API
|
|
83
|
+
reference is generated and should not be edited in place via the docs site.
|
|
84
|
+
|
|
81
85
|
### Defaults
|
|
82
86
|
|
|
83
87
|
| Setting | Default |
|
|
@@ -90,6 +94,7 @@ names begin with `textmode`.
|
|
|
90
94
|
| Hosted API URL | `https://code.textmode.art/api/<package-name>` |
|
|
91
95
|
| Member pages | Methods, properties, and accessors |
|
|
92
96
|
| Self-link stripping | `full` |
|
|
97
|
+
| Edit link on API pages | Disabled (opt in per package with `editLink: true`) |
|
|
93
98
|
| Sorting | Kind, instance-first, alphabetical (except documents) |
|
|
94
99
|
| API-link kinds | All supported reflection kinds |
|
|
95
100
|
| Required docstrings | All supported reflection kinds |
|
package/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface TextmodeDocsConfig {
|
|
|
28
28
|
tsconfig?: string;
|
|
29
29
|
memberPageKinds?: MemberPageKind[];
|
|
30
30
|
stripApiSelfLinks?: 'minimal' | 'full';
|
|
31
|
+
editLink?: boolean;
|
|
31
32
|
checks?: DocsChecks;
|
|
32
33
|
examples?: false | ExamplesPolicy;
|
|
33
34
|
typedoc?: Record<string, unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textmode/docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared documentation generation and validation for the textmode.js ecosystem",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"textmode",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=24 <25"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"typescript": "^6.0.3"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
|
-
"check": "
|
|
50
|
+
"check": "pnpm run check:format && pnpm run lint && pnpm run test && pnpm run check:package && pnpm run check:pack",
|
|
51
51
|
"check:format": "prettier --check .",
|
|
52
52
|
"check:package": "node scripts/check-package.mjs",
|
|
53
53
|
"check:pack": "node scripts/pack-smoke.mjs",
|
package/src/internal/config.js
CHANGED
|
@@ -12,6 +12,7 @@ const TOP_LEVEL_KEYS = new Set([
|
|
|
12
12
|
'tsconfig',
|
|
13
13
|
'memberPageKinds',
|
|
14
14
|
'stripApiSelfLinks',
|
|
15
|
+
'editLink',
|
|
15
16
|
'checks',
|
|
16
17
|
'examples',
|
|
17
18
|
'typedoc',
|
|
@@ -203,6 +204,9 @@ export function validateDocsConfig(config) {
|
|
|
203
204
|
) {
|
|
204
205
|
throw new Error('stripApiSelfLinks must be "minimal" or "full".');
|
|
205
206
|
}
|
|
207
|
+
if (config.editLink !== undefined && typeof config.editLink !== 'boolean') {
|
|
208
|
+
throw new Error('editLink must be a boolean.');
|
|
209
|
+
}
|
|
206
210
|
if (config.checks !== undefined) {
|
|
207
211
|
validateChecks(config.checks);
|
|
208
212
|
}
|
|
@@ -311,6 +315,7 @@ export async function resolveDocsConfig({ cwd = process.cwd(), configPath: reque
|
|
|
311
315
|
tsconfig: resolveProjectPath(projectRoot, tsconfig),
|
|
312
316
|
memberPageKinds: config.memberPageKinds ?? DEFAULT_MEMBER_PAGE_KINDS,
|
|
313
317
|
stripApiSelfLinks: config.stripApiSelfLinks ?? 'full',
|
|
318
|
+
editLink: config.editLink ?? false,
|
|
314
319
|
checks,
|
|
315
320
|
examples,
|
|
316
321
|
typedoc: { ...DEFAULT_TYPEDOC_OPTIONS, ...(config.typedoc ?? {}) },
|
|
@@ -328,6 +333,7 @@ export async function resolveDocsConfig({ cwd = process.cwd(), configPath: reque
|
|
|
328
333
|
tsconfig: origin(config, 'tsconfig', 'default'),
|
|
329
334
|
memberPageKinds: origin(config, 'memberPageKinds', 'default'),
|
|
330
335
|
stripApiSelfLinks: origin(config, 'stripApiSelfLinks', 'default'),
|
|
336
|
+
editLink: origin(config, 'editLink', 'default'),
|
|
331
337
|
checks: {
|
|
332
338
|
apiLinks: config.checks?.apiLinks ? 'textmode.docs.config.mjs' : 'default',
|
|
333
339
|
docstrings: config.checks?.docstrings ? 'textmode.docs.config.mjs' : 'default',
|
|
@@ -372,6 +378,7 @@ export function formatResolvedConfig(config) {
|
|
|
372
378
|
tsconfig: displayPath(config.projectRoot, config.tsconfig),
|
|
373
379
|
memberPageKinds: config.memberPageKinds,
|
|
374
380
|
stripApiSelfLinks: config.stripApiSelfLinks,
|
|
381
|
+
editLink: config.editLink,
|
|
375
382
|
checks: config.checks,
|
|
376
383
|
examples: config.examples,
|
|
377
384
|
typedoc: config.typedoc,
|
|
@@ -62,6 +62,7 @@ async function loadPrimaryCheckProject(config) {
|
|
|
62
62
|
entryPoint: primaryEntryPoint.path,
|
|
63
63
|
tsconfig: primaryEntryPoint.tsconfig,
|
|
64
64
|
packageName: config.packageName,
|
|
65
|
+
projectRoot: config.projectRoot,
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -183,6 +184,7 @@ async function collectPendingEdits(config, routes) {
|
|
|
183
184
|
entryPoint: entryPoint.path,
|
|
184
185
|
tsconfig: entryPoint.tsconfig,
|
|
185
186
|
packageName: config.packageName,
|
|
187
|
+
projectRoot: config.projectRoot,
|
|
186
188
|
});
|
|
187
189
|
const reflections = getIncludedReflections(project, targetKinds);
|
|
188
190
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Application, TSConfigReader } from 'typedoc';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
2
5
|
import { load as loadFrontmatter } from 'typedoc-plugin-frontmatter';
|
|
3
6
|
import { load as loadMarkdown } from 'typedoc-plugin-markdown';
|
|
4
7
|
import { load as loadVitepressTheme } from 'typedoc-vitepress-theme';
|
|
@@ -25,10 +28,6 @@ const BASE_TYPEDOC_OPTIONS = {
|
|
|
25
28
|
exclude: ['**/node_modules/**'],
|
|
26
29
|
...DEFAULT_TYPEDOC_OPTIONS,
|
|
27
30
|
logLevel: 'Verbose',
|
|
28
|
-
frontmatterGlobals: {
|
|
29
|
-
layout: 'doc',
|
|
30
|
-
editLink: true,
|
|
31
|
-
},
|
|
32
31
|
frontmatterCommentTags: ['author', 'since', 'deprecated'],
|
|
33
32
|
preserveFrontmatterCommentTags: false,
|
|
34
33
|
frontmatterNamingConvention: 'camelCase',
|
|
@@ -66,13 +65,50 @@ function pluginInitializers(config) {
|
|
|
66
65
|
return plugins;
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
function createEntrypointTsconfig({ tsconfig, projectRoot, entryPoints }) {
|
|
69
|
+
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-docs-tsconfig-'));
|
|
70
|
+
const configPath = path.join(temporaryDirectory, 'tsconfig.json');
|
|
71
|
+
fs.writeFileSync(
|
|
72
|
+
configPath,
|
|
73
|
+
`${JSON.stringify(
|
|
74
|
+
{
|
|
75
|
+
extends: tsconfig,
|
|
76
|
+
compilerOptions: {
|
|
77
|
+
noEmit: true,
|
|
78
|
+
rootDir: projectRoot,
|
|
79
|
+
types: [],
|
|
80
|
+
},
|
|
81
|
+
files: entryPoints,
|
|
82
|
+
},
|
|
83
|
+
null,
|
|
84
|
+
2
|
|
85
|
+
)}\n`
|
|
86
|
+
);
|
|
87
|
+
return {
|
|
88
|
+
configPath,
|
|
89
|
+
cleanup() {
|
|
90
|
+
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
69
95
|
function applicationOptions(config, { outputDir, strict = false, watch = false } = {}) {
|
|
96
|
+
const { compilerOptions = {}, ...typedocOptions } = config.typedoc;
|
|
70
97
|
return {
|
|
71
98
|
...BASE_TYPEDOC_OPTIONS,
|
|
72
|
-
|
|
99
|
+
frontmatterGlobals: {
|
|
100
|
+
layout: 'doc',
|
|
101
|
+
editLink: config.editLink ?? false,
|
|
102
|
+
},
|
|
103
|
+
...typedocOptions,
|
|
73
104
|
entryPoints: config.entryPoints,
|
|
74
105
|
entryPointStrategy: 'resolve',
|
|
75
106
|
tsconfig: config.tsconfig,
|
|
107
|
+
compilerOptions: {
|
|
108
|
+
...compilerOptions,
|
|
109
|
+
noEmit: true,
|
|
110
|
+
rootDir: config.projectRoot,
|
|
111
|
+
},
|
|
76
112
|
out: outputDir ?? config.outputDir,
|
|
77
113
|
name: config.packageName,
|
|
78
114
|
emit: 'docs',
|
|
@@ -85,7 +121,26 @@ function applicationOptions(config, { outputDir, strict = false, watch = false }
|
|
|
85
121
|
}
|
|
86
122
|
|
|
87
123
|
export async function createDocsApplication(config, options = {}) {
|
|
88
|
-
|
|
124
|
+
const temporaryConfig = createEntrypointTsconfig({
|
|
125
|
+
tsconfig: config.tsconfig,
|
|
126
|
+
projectRoot: config.projectRoot,
|
|
127
|
+
entryPoints: config.entryPoints,
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
const app = await Application.bootstrapWithPlugins(
|
|
131
|
+
applicationOptions({ ...config, tsconfig: temporaryConfig.configPath }, options),
|
|
132
|
+
[new TSConfigReader()]
|
|
133
|
+
);
|
|
134
|
+
if (options.watch) {
|
|
135
|
+
process.once('exit', temporaryConfig.cleanup);
|
|
136
|
+
} else {
|
|
137
|
+
temporaryConfig.cleanup();
|
|
138
|
+
}
|
|
139
|
+
return app;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
temporaryConfig.cleanup();
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
89
144
|
}
|
|
90
145
|
|
|
91
146
|
export async function buildDocs(config, { outputDir, strict = false } = {}) {
|
|
@@ -115,22 +170,28 @@ export async function watchDocs(config, { outputDir } = {}) {
|
|
|
115
170
|
return { app, ok: started };
|
|
116
171
|
}
|
|
117
172
|
|
|
118
|
-
export async function loadEntryPointProject({ entryPoint, tsconfig, packageName }) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
173
|
+
export async function loadEntryPointProject({ entryPoint, tsconfig, packageName, projectRoot }) {
|
|
174
|
+
const temporaryConfig = createEntrypointTsconfig({ tsconfig, projectRoot, entryPoints: [entryPoint] });
|
|
175
|
+
let app;
|
|
176
|
+
try {
|
|
177
|
+
app = await Application.bootstrap(
|
|
178
|
+
{
|
|
179
|
+
entryPoints: [entryPoint],
|
|
180
|
+
entryPointStrategy: 'resolve',
|
|
181
|
+
tsconfig: temporaryConfig.configPath,
|
|
182
|
+
name: packageName,
|
|
183
|
+
excludeInternal: true,
|
|
184
|
+
excludePrivate: true,
|
|
185
|
+
excludeProtected: true,
|
|
186
|
+
readme: 'none',
|
|
187
|
+
emit: 'none',
|
|
188
|
+
logLevel: 'Error',
|
|
189
|
+
},
|
|
190
|
+
[new TSConfigReader()]
|
|
191
|
+
);
|
|
192
|
+
} finally {
|
|
193
|
+
temporaryConfig.cleanup();
|
|
194
|
+
}
|
|
134
195
|
const project = await app.convert();
|
|
135
196
|
if (!project || app.logger.hasErrors()) {
|
|
136
197
|
throw new Error(`TypeDoc failed to resolve ${entryPoint}.`);
|