@textmode/docs 0.2.0 → 0.2.2
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 +20 -16
- package/package.json +1 -1
- package/src/internal/config.js +4 -1
- package/src/internal/operations.js +2 -0
- package/src/internal/typedoc-runner.js +81 -19
package/README.md
CHANGED
|
@@ -80,28 +80,32 @@ names begin with `textmode`.
|
|
|
80
80
|
|
|
81
81
|
### Defaults
|
|
82
82
|
|
|
83
|
-
| Setting | Default
|
|
84
|
-
| ------------------------------ |
|
|
85
|
-
| Package name and description | `package.json`
|
|
86
|
-
| Entrypoint and link entrypoint | `src/index.ts`
|
|
87
|
-
| Source roots | Derived from link entrypoints
|
|
88
|
-
| TypeScript config | `tsconfig.json`
|
|
89
|
-
| Output | `api/<package-name>`
|
|
90
|
-
| Hosted API URL | `https://code.textmode.art/api/<package-name>`
|
|
91
|
-
| Member pages | Methods, properties, and accessors
|
|
92
|
-
| Self-link stripping | `full`
|
|
93
|
-
| Sorting |
|
|
94
|
-
| API-link kinds | All supported reflection kinds
|
|
95
|
-
| Required docstrings | All supported reflection kinds
|
|
96
|
-
| Required examples | Functions, methods, and accessors
|
|
97
|
-
| Example checks | Gallery, manifest, and sketch checks enabled
|
|
98
|
-
| Gallery source bases | Hardcoded source bases rejected
|
|
83
|
+
| Setting | Default |
|
|
84
|
+
| ------------------------------ | ----------------------------------------------------- |
|
|
85
|
+
| Package name and description | `package.json` |
|
|
86
|
+
| Entrypoint and link entrypoint | `src/index.ts` |
|
|
87
|
+
| Source roots | Derived from link entrypoints |
|
|
88
|
+
| TypeScript config | `tsconfig.json` |
|
|
89
|
+
| Output | `api/<package-name>` |
|
|
90
|
+
| Hosted API URL | `https://code.textmode.art/api/<package-name>` |
|
|
91
|
+
| Member pages | Methods, properties, and accessors |
|
|
92
|
+
| Self-link stripping | `full` |
|
|
93
|
+
| Sorting | Kind, instance-first, alphabetical (except documents) |
|
|
94
|
+
| API-link kinds | All supported reflection kinds |
|
|
95
|
+
| Required docstrings | All supported reflection kinds |
|
|
96
|
+
| Required examples | Functions, methods, and accessors |
|
|
97
|
+
| Example checks | Gallery, manifest, and sketch checks enabled |
|
|
98
|
+
| Gallery source bases | Hardcoded source bases rejected |
|
|
99
99
|
|
|
100
100
|
Configuration precedence is shared defaults, derived package metadata,
|
|
101
101
|
`textmode.docs.config.mjs`, then command-owned overrides such as `--out`,
|
|
102
102
|
strict checking, and watch mode. Use `--show-config` to inspect the effective
|
|
103
103
|
values and the origin of every setting.
|
|
104
104
|
|
|
105
|
+
The shared sorting policy groups API reflections by kind, lists instance members
|
|
106
|
+
before static members, and alphabetizes non-document reflections. A project can
|
|
107
|
+
override it with `typedoc.sort` when its API needs a different presentation.
|
|
108
|
+
|
|
105
109
|
## Commands
|
|
106
110
|
|
|
107
111
|
```text
|
package/package.json
CHANGED
package/src/internal/config.js
CHANGED
|
@@ -57,6 +57,9 @@ export const DEFAULT_API_LINK_KINDS = [
|
|
|
57
57
|
export const DEFAULT_DOCSTRING_KINDS = [...DEFAULT_API_LINK_KINDS];
|
|
58
58
|
export const DEFAULT_EXAMPLE_KINDS = ['function', 'method', 'accessor'];
|
|
59
59
|
export const DEFAULT_MEMBER_PAGE_KINDS = ['method', 'property', 'accessor'];
|
|
60
|
+
export const DEFAULT_TYPEDOC_OPTIONS = {
|
|
61
|
+
sort: ['kind', 'instance-first', 'alphabetical-ignoring-documents'],
|
|
62
|
+
};
|
|
60
63
|
|
|
61
64
|
function isRecord(value) {
|
|
62
65
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -310,7 +313,7 @@ export async function resolveDocsConfig({ cwd = process.cwd(), configPath: reque
|
|
|
310
313
|
stripApiSelfLinks: config.stripApiSelfLinks ?? 'full',
|
|
311
314
|
checks,
|
|
312
315
|
examples,
|
|
313
|
-
typedoc: config.typedoc ?? {},
|
|
316
|
+
typedoc: { ...DEFAULT_TYPEDOC_OPTIONS, ...(config.typedoc ?? {}) },
|
|
314
317
|
origins: {
|
|
315
318
|
packageName: 'package.json#name',
|
|
316
319
|
packageDescription:
|
|
@@ -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';
|
|
@@ -8,6 +11,7 @@ import { load as loadMemberPages } from './typedoc-plugins/all-member-pages-rout
|
|
|
8
11
|
import { load as loadApiFrontmatter } from './typedoc-plugins/api-frontmatter/index.js';
|
|
9
12
|
import { load as loadCodeExamples } from './typedoc-plugins/include-code-examples/index.js';
|
|
10
13
|
import { load as loadSelfLinkStripper } from './typedoc-plugins/strip-api-self-links/index.js';
|
|
14
|
+
import { DEFAULT_TYPEDOC_OPTIONS } from './config.js';
|
|
11
15
|
|
|
12
16
|
const BASE_TYPEDOC_OPTIONS = {
|
|
13
17
|
readme: 'none',
|
|
@@ -22,7 +26,7 @@ const BASE_TYPEDOC_OPTIONS = {
|
|
|
22
26
|
exampleTag: false,
|
|
23
27
|
},
|
|
24
28
|
exclude: ['**/node_modules/**'],
|
|
25
|
-
|
|
29
|
+
...DEFAULT_TYPEDOC_OPTIONS,
|
|
26
30
|
logLevel: 'Verbose',
|
|
27
31
|
frontmatterGlobals: {
|
|
28
32
|
layout: 'doc',
|
|
@@ -65,13 +69,46 @@ function pluginInitializers(config) {
|
|
|
65
69
|
return plugins;
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
function createEntrypointTsconfig({ tsconfig, projectRoot, entryPoints }) {
|
|
73
|
+
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-docs-tsconfig-'));
|
|
74
|
+
const configPath = path.join(temporaryDirectory, 'tsconfig.json');
|
|
75
|
+
fs.writeFileSync(
|
|
76
|
+
configPath,
|
|
77
|
+
`${JSON.stringify(
|
|
78
|
+
{
|
|
79
|
+
extends: tsconfig,
|
|
80
|
+
compilerOptions: {
|
|
81
|
+
noEmit: true,
|
|
82
|
+
rootDir: projectRoot,
|
|
83
|
+
types: [],
|
|
84
|
+
},
|
|
85
|
+
files: entryPoints,
|
|
86
|
+
},
|
|
87
|
+
null,
|
|
88
|
+
2
|
|
89
|
+
)}\n`
|
|
90
|
+
);
|
|
91
|
+
return {
|
|
92
|
+
configPath,
|
|
93
|
+
cleanup() {
|
|
94
|
+
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
function applicationOptions(config, { outputDir, strict = false, watch = false } = {}) {
|
|
100
|
+
const { compilerOptions = {}, ...typedocOptions } = config.typedoc;
|
|
69
101
|
return {
|
|
70
102
|
...BASE_TYPEDOC_OPTIONS,
|
|
71
|
-
...
|
|
103
|
+
...typedocOptions,
|
|
72
104
|
entryPoints: config.entryPoints,
|
|
73
105
|
entryPointStrategy: 'resolve',
|
|
74
106
|
tsconfig: config.tsconfig,
|
|
107
|
+
compilerOptions: {
|
|
108
|
+
...compilerOptions,
|
|
109
|
+
noEmit: true,
|
|
110
|
+
rootDir: config.projectRoot,
|
|
111
|
+
},
|
|
75
112
|
out: outputDir ?? config.outputDir,
|
|
76
113
|
name: config.packageName,
|
|
77
114
|
emit: 'docs',
|
|
@@ -84,7 +121,26 @@ function applicationOptions(config, { outputDir, strict = false, watch = false }
|
|
|
84
121
|
}
|
|
85
122
|
|
|
86
123
|
export async function createDocsApplication(config, options = {}) {
|
|
87
|
-
|
|
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
|
+
}
|
|
88
144
|
}
|
|
89
145
|
|
|
90
146
|
export async function buildDocs(config, { outputDir, strict = false } = {}) {
|
|
@@ -114,22 +170,28 @@ export async function watchDocs(config, { outputDir } = {}) {
|
|
|
114
170
|
return { app, ok: started };
|
|
115
171
|
}
|
|
116
172
|
|
|
117
|
-
export async function loadEntryPointProject({ entryPoint, tsconfig, packageName }) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
}
|
|
133
195
|
const project = await app.convert();
|
|
134
196
|
if (!project || app.logger.hasErrors()) {
|
|
135
197
|
throw new Error(`TypeDoc failed to resolve ${entryPoint}.`);
|