@travetto/doc 8.0.0-alpha.14 → 8.0.0-alpha.16
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 +13 -5
- package/package.json +5 -3
- package/src/jsx.ts +8 -2
- package/src/mapping/module.ts +5 -5
- package/src/render/context.ts +12 -1
- package/src/render/html.ts +29 -2
- package/src/render/markdown.ts +26 -2
- package/src/render/renderer.ts +4 -4
- package/support/cli.doc.ts +4 -1
package/README.md
CHANGED
|
@@ -57,6 +57,9 @@ As you can see, you need to export a field named `text` as the body of the help
|
|
|
57
57
|
|
|
58
58
|
* `Anchor` - In page anchor reference
|
|
59
59
|
* `Class` - Class reference
|
|
60
|
+
* `CliHelpDescription` - Standardized CLI command help description
|
|
61
|
+
* `CliHelpExecution` - Standardized CLI command help execution
|
|
62
|
+
* `CliHelpSection` - Standardized CLI command help section
|
|
60
63
|
* `Code` - Code sample
|
|
61
64
|
* `CodeLink` - Code link with regexp for detecting line
|
|
62
65
|
* `Command` - Command invocation
|
|
@@ -87,17 +90,22 @@ Some of the more common libraries are provided as the `d.library` method. The p
|
|
|
87
90
|
You can also link to other [Travetto](https://travetto.dev) based modules as needed. The `d.module` object relies on what is already imported into your project, and reference the package.json of the related module. If the module is not installed, doc generation will fail.
|
|
88
91
|
|
|
89
92
|
## CLI - doc
|
|
90
|
-
|
|
93
|
+
Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
91
94
|
|
|
92
|
-
**Terminal:
|
|
95
|
+
**Terminal: Help for doc**
|
|
93
96
|
```bash
|
|
94
97
|
$ trv doc --help
|
|
95
98
|
|
|
96
99
|
Usage: doc [options]
|
|
97
100
|
|
|
101
|
+
Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
102
|
+
|
|
103
|
+
Supports multiple output formats/targets and optional watch mode for
|
|
104
|
+
iterative documentation authoring.
|
|
105
|
+
|
|
98
106
|
Options:
|
|
99
107
|
-i, --input <string> Input File (default: "DOC.tsx")
|
|
100
|
-
-o, --outputs <string> Outputs (default: ["README.md"])
|
|
108
|
+
-o, --outputs <string> Outputs (default: ["README.md","DOC.html"])
|
|
101
109
|
-w, --watch Watch? (default: false)
|
|
102
110
|
--help display help for command
|
|
103
111
|
```
|
|
@@ -152,7 +160,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
|
|
|
152
160
|
Usage: <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token punctuation">[</span>command<span class="token punctuation">]</span>
|
|
153
161
|
|
|
154
162
|
Commands:
|
|
155
|
-
doc
|
|
156
|
-
<span class="token function">service</span>
|
|
163
|
+
doc Generate documentation outputs from a module <span class="token variable"><span class="token variable">`</span>DOC.tsx<span class="token variable">`</span></span> entry file.
|
|
164
|
+
<span class="token function">service</span> Manage development services <span class="token punctuation">(</span>start/stop/restart/status<span class="token punctuation">)</span> across the workspace.</code></pre>
|
|
157
165
|
</figure>
|
|
158
166
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/doc",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.16",
|
|
4
4
|
"description": "Documentation support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
"directory": "module/doc"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/runtime": "^8.0.0-alpha.
|
|
27
|
+
"@travetto/runtime": "^8.0.0-alpha.16",
|
|
28
|
+
"@types/markdown-it": "^14.1.2",
|
|
28
29
|
"@types/prismjs": "^1.26.6",
|
|
30
|
+
"markdown-it": "^14.2.0",
|
|
29
31
|
"prismjs": "^1.30.0"
|
|
30
32
|
},
|
|
31
33
|
"peerDependencies": {
|
|
32
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
34
|
+
"@travetto/cli": "^8.0.0-alpha.22"
|
|
33
35
|
},
|
|
34
36
|
"peerDependenciesMeta": {
|
|
35
37
|
"@travetto/cli": {
|
package/src/jsx.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { castTo, TypedObject } from '@travetto/runtime';
|
|
1
|
+
import { castTo, type Class as ClassType, TypedObject } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import type { LIBRARIES } from './mapping/library.ts';
|
|
4
4
|
import type { MODULES } from './mapping/module.ts';
|
|
@@ -9,6 +9,8 @@ import { PackageDocUtil } from './util/package.ts';
|
|
|
9
9
|
|
|
10
10
|
type InstallProps = { title: string, pkg: string };
|
|
11
11
|
type ExecProps = { title: string, cmd: string, args?: string[], config?: RunConfig & { formatCommand?(cmd: string, args: string[]): string } };
|
|
12
|
+
type CliHelpProps = { commandClass: ClassType };
|
|
13
|
+
type CliHelpExecutionProps = CliHelpProps & { config?: RunConfig };
|
|
12
14
|
type StdHeaderProps = { module?: string, install?: boolean };
|
|
13
15
|
type HeaderProps = { title: string, description?: string };
|
|
14
16
|
type ModuleProps = { name: keyof typeof MODULES };
|
|
@@ -46,6 +48,9 @@ const Config: CompFn<CodeProps> = () => EMPTY; // Configuration block
|
|
|
46
48
|
const StdHeader: CompFn<StdHeaderProps> = () => EMPTY; // Standard module header
|
|
47
49
|
const Header: CompFn<HeaderProps> = () => EMPTY; // Basic module header
|
|
48
50
|
const Execution: CompFn<ExecProps> = () => EMPTY; // Run a command, and include the output as part of the document
|
|
51
|
+
const CliHelpSection: CompFn<CliHelpProps> = () => EMPTY; // Standardized CLI command help section
|
|
52
|
+
const CliHelpDescription: CompFn<CliHelpProps & { short?: boolean }> = () => EMPTY; // Standardized CLI command help description
|
|
53
|
+
const CliHelpExecution: CompFn<CliHelpExecutionProps> = () => EMPTY; // Standardized CLI command help execution
|
|
49
54
|
|
|
50
55
|
const Module: CompFn<ModuleProps> = () => EMPTY; // Node Module Reference
|
|
51
56
|
const Library: CompFn<LibraryProps> = () => EMPTY; // Library reference
|
|
@@ -55,7 +60,8 @@ export const c = {
|
|
|
55
60
|
Anchor, Library, Ref, File, Image, CodeLink,
|
|
56
61
|
Module, Note, Header, StdHeader,
|
|
57
62
|
Section, SubSection, SubSubSection,
|
|
58
|
-
Code, Execution, Terminal, Install, Config
|
|
63
|
+
Code, Execution, Terminal, Install, Config,
|
|
64
|
+
CliHelpSection, CliHelpDescription, CliHelpExecution,
|
|
59
65
|
} as const;
|
|
60
66
|
|
|
61
67
|
type C = typeof c;
|
package/src/mapping/module.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const MODULES = {
|
|
2
2
|
Auth: {
|
|
3
3
|
name: '@travetto/auth', folder: '@travetto/auth', displayName: 'Authentication',
|
|
4
|
-
description: 'Authentication
|
|
4
|
+
description: 'Authentication support for the Travetto framework'
|
|
5
5
|
},
|
|
6
6
|
AuthModel: {
|
|
7
7
|
name: '@travetto/auth-model', folder: '@travetto/auth-model', displayName: 'Authentication Model',
|
|
@@ -75,6 +75,10 @@ export const MODULES = {
|
|
|
75
75
|
name: '@travetto/image', folder: '@travetto/image', displayName: 'Image',
|
|
76
76
|
description: 'Image support, resizing, and optimization'
|
|
77
77
|
},
|
|
78
|
+
LlmSupport: {
|
|
79
|
+
name: '@travetto/llm-support', folder: '@travetto/llm-support', displayName: 'LLM Support',
|
|
80
|
+
description: 'Task-oriented synthesized LLM guidance for Travetto modules.'
|
|
81
|
+
},
|
|
78
82
|
Log: {
|
|
79
83
|
name: '@travetto/log', folder: '@travetto/log', displayName: 'Logging',
|
|
80
84
|
description: 'Logging framework that integrates at the console.log level.'
|
|
@@ -167,10 +171,6 @@ export const MODULES = {
|
|
|
167
171
|
name: '@travetto/runtime', folder: '@travetto/runtime', displayName: 'Runtime',
|
|
168
172
|
description: 'Runtime for travetto applications.'
|
|
169
173
|
},
|
|
170
|
-
Scaffold: {
|
|
171
|
-
name: '@travetto/scaffold', folder: '@travetto/scaffold', displayName: 'App Scaffold',
|
|
172
|
-
description: 'App Scaffold for the Travetto framework'
|
|
173
|
-
},
|
|
174
174
|
Schema: {
|
|
175
175
|
name: '@travetto/schema', folder: '@travetto/schema', displayName: 'Schema',
|
|
176
176
|
description: 'Data type registry for runtime validation, reflection and binding.'
|
package/src/render/context.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
import { PackageUtil } from '@travetto/manifest';
|
|
4
|
-
import { castTo, RuntimeIndex } from '@travetto/runtime';
|
|
4
|
+
import { castTo, RuntimeIndex, type Class } from '@travetto/runtime';
|
|
5
|
+
import { CliCommandRegistryIndex } from '@travetto/cli';
|
|
6
|
+
import { SchemaRegistryIndex } from '@travetto/schema';
|
|
5
7
|
|
|
6
8
|
import { type JSXElementByFn, c, d } from '../jsx.ts';
|
|
7
9
|
import { DocResolveUtil, type ResolvedCode, type ResolvedRef, type ResolvedSnippetLink } from '../util/resolve.ts';
|
|
@@ -96,6 +98,15 @@ export class RenderContext {
|
|
|
96
98
|
return this.#executeCache[key] = result;
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Resolve CLI command metadata for a class from cli:schema output.
|
|
103
|
+
*/
|
|
104
|
+
resolveCliCommandFromClass(commandClass: Class): { name: string, description?: string } {
|
|
105
|
+
const { name } = CliCommandRegistryIndex.get(commandClass);
|
|
106
|
+
const { description } = SchemaRegistryIndex.getConfig(commandClass);
|
|
107
|
+
return { name, description };
|
|
108
|
+
}
|
|
109
|
+
|
|
99
110
|
/**
|
|
100
111
|
* Resolve a reference to a given node
|
|
101
112
|
*/
|
package/src/render/html.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
+
import markdown from 'markdown-it';
|
|
2
3
|
|
|
3
|
-
import { Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
4
|
+
import { CodecUtil, Runtime, RuntimeError, RuntimeIndex } from '@travetto/runtime';
|
|
4
5
|
import { PackageUtil } from '@travetto/manifest';
|
|
6
|
+
import { HELP_FLAG } from '@travetto/cli';
|
|
5
7
|
|
|
6
8
|
import { highlight } from './code-highlight.ts';
|
|
7
9
|
import type { RenderProvider, RenderState } from '../types.ts';
|
|
@@ -15,6 +17,7 @@ import { PackageDocUtil } from '../util/package.ts';
|
|
|
15
17
|
|
|
16
18
|
const ESCAPE_ENTITIES: Record<string, string> = { '<': '<', '>': '>', '&': '&', '{': "{{'{'}}", '}': "{{'}'}}" };
|
|
17
19
|
const ENTITY_REGEX = new RegExp(`[${Object.keys(ESCAPE_ENTITIES).join('')}]`, 'gm');
|
|
20
|
+
const md = new markdown({ html: false });
|
|
18
21
|
|
|
19
22
|
const stdInline = async ({ recurse, node }: RenderState<JSXElement, RenderContext>): Promise<string> =>
|
|
20
23
|
`<${node.type}>${await recurse()}</${node.type}>`;
|
|
@@ -51,6 +54,30 @@ export const Html: RenderProvider<RenderContext> = {
|
|
|
51
54
|
});
|
|
52
55
|
return Html.Terminal(sub);
|
|
53
56
|
},
|
|
57
|
+
CliHelpExecution: async ({ context, props, createState }) => {
|
|
58
|
+
const config = context.resolveCliCommandFromClass(props.commandClass);
|
|
59
|
+
const { name: command } = config;
|
|
60
|
+
return Html.Execution(createState('Execution', {
|
|
61
|
+
title: `Showing help for ${command}`,
|
|
62
|
+
cmd: 'trv',
|
|
63
|
+
args: [command, HELP_FLAG],
|
|
64
|
+
config: { ...props.config }
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
CliHelpDescription: async ({ context, props }) => {
|
|
68
|
+
const config = context.resolveCliCommandFromClass(props.commandClass);
|
|
69
|
+
let text = config.description ?? '';
|
|
70
|
+
if (props.short) {
|
|
71
|
+
text = CodecUtil.readFirstLine(text);
|
|
72
|
+
}
|
|
73
|
+
return md.render(text);
|
|
74
|
+
},
|
|
75
|
+
CliHelpSection: async ({ context, props, recurse }) => {
|
|
76
|
+
const config = context.resolveCliCommandFromClass(props.commandClass);
|
|
77
|
+
const { name: command } = config;
|
|
78
|
+
const title = `CLI - ${command}`;
|
|
79
|
+
return `\n<h2 id="${context.getAnchorId(title)}">${title}</h2>\n\n${await recurse()}`;
|
|
80
|
+
},
|
|
54
81
|
Install: async ({ context, node }) => {
|
|
55
82
|
const highlighted = highlight(`
|
|
56
83
|
${PackageDocUtil.getInstallInstructions(node.props.pkg, true)}
|
|
@@ -125,7 +152,7 @@ ${PackageDocUtil.getInstallInstructions(node.props.pkg, true)}
|
|
|
125
152
|
`<a target="_blank" class="source-link" href="${context.link(props.href, props)}">${props.title}</a>`,
|
|
126
153
|
Image: async ({ context, props }) => {
|
|
127
154
|
if (!/^https?:/.test(props.href) && !(await fs.stat(props.href, { throwIfNoEntry: false }))) {
|
|
128
|
-
throw new
|
|
155
|
+
throw new RuntimeError(`${props.href} is not a valid location`);
|
|
129
156
|
}
|
|
130
157
|
return `<img src="${context.link(props.href, props)}" alt="${props.title}">`;
|
|
131
158
|
},
|
package/src/render/markdown.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
3
|
+
import { CodecUtil, Runtime, RuntimeError, RuntimeIndex } from '@travetto/runtime';
|
|
4
4
|
import { PackageUtil } from '@travetto/manifest';
|
|
5
|
+
import { HELP_FLAG } from '@travetto/cli';
|
|
5
6
|
|
|
6
7
|
import type { RenderProvider } from '../types.ts';
|
|
7
8
|
import { c, getComponentName } from '../jsx.ts';
|
|
@@ -53,6 +54,29 @@ export const Markdown: RenderProvider<RenderContext> = {
|
|
|
53
54
|
});
|
|
54
55
|
return Markdown.Terminal(state);
|
|
55
56
|
},
|
|
57
|
+
CliHelpExecution: async ({ context, props, createState }) => {
|
|
58
|
+
const { name: command } = context.resolveCliCommandFromClass(props.commandClass);
|
|
59
|
+
return await Markdown.Execution(createState('Execution', {
|
|
60
|
+
title: `Help for ${command}`,
|
|
61
|
+
cmd: 'trv',
|
|
62
|
+
args: [command, HELP_FLAG],
|
|
63
|
+
config: { ...props.config }
|
|
64
|
+
}));
|
|
65
|
+
},
|
|
66
|
+
CliHelpDescription: async ({ context, props }) => {
|
|
67
|
+
const { description = '' } = context.resolveCliCommandFromClass(props.commandClass);
|
|
68
|
+
let text = description;
|
|
69
|
+
if (props.short) {
|
|
70
|
+
text = CodecUtil.readFirstLine(text);
|
|
71
|
+
}
|
|
72
|
+
return text;
|
|
73
|
+
},
|
|
74
|
+
CliHelpSection: async ({ context, props, recurse }) => {
|
|
75
|
+
const { name: command } = context.resolveCliCommandFromClass(props.commandClass);
|
|
76
|
+
const title = `CLI - ${command}`;
|
|
77
|
+
const body = await recurse();
|
|
78
|
+
return `\n## ${title}\n${body}`;
|
|
79
|
+
},
|
|
56
80
|
Install: async ({ context, node }) =>
|
|
57
81
|
`\n\n**Install: ${node.props.title}**
|
|
58
82
|
\`\`\`bash
|
|
@@ -102,7 +126,7 @@ ${context.cleanText(content.text)}
|
|
|
102
126
|
|
|
103
127
|
Image: async ({ props, context }) => {
|
|
104
128
|
if (!/^https?:/.test(props.href) && !(await fs.stat(props.href, { throwIfNoEntry: false }))) {
|
|
105
|
-
throw new
|
|
129
|
+
throw new RuntimeError(`${props.href} is not a valid location`);
|
|
106
130
|
}
|
|
107
131
|
return `})`;
|
|
108
132
|
},
|
package/src/render/renderer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
3
|
import { type ManifestContext, PackageUtil } from '@travetto/manifest';
|
|
4
|
-
import { castTo, type Class, Runtime } from '@travetto/runtime';
|
|
4
|
+
import { castTo, type Class, Runtime, RuntimeError } from '@travetto/runtime';
|
|
5
5
|
|
|
6
6
|
import { EMPTY_ELEMENT, getComponentName, type JSXElementByFn, type c } from '../jsx.ts';
|
|
7
7
|
import type { DocumentShape, RenderProvider, RenderState } from '../types.ts';
|
|
@@ -106,7 +106,7 @@ export class DocRenderer {
|
|
|
106
106
|
return renderer[name](state);
|
|
107
107
|
} else {
|
|
108
108
|
console.log(final);
|
|
109
|
-
throw new
|
|
109
|
+
throw new RuntimeError(`Unknown element: ${final.type}`);
|
|
110
110
|
}
|
|
111
111
|
} else {
|
|
112
112
|
switch (typeof input) {
|
|
@@ -124,7 +124,7 @@ export class DocRenderer {
|
|
|
124
124
|
return await this.#buildLink(renderer, castTo(input));
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
throw new
|
|
127
|
+
throw new RuntimeError(`Unknown object type: ${typeof input}`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -144,7 +144,7 @@ export class DocRenderer {
|
|
|
144
144
|
*/
|
|
145
145
|
async render(format: keyof typeof providers): Promise<string> {
|
|
146
146
|
if (!providers[format]) {
|
|
147
|
-
throw new
|
|
147
|
+
throw new RuntimeError(`Unknown renderer with format: ${format}`);
|
|
148
148
|
}
|
|
149
149
|
if (!this.#rootNode) {
|
|
150
150
|
this.#rootNode = (Array.isArray(this.#root.text) || isJSXElement(this.#root.text)) ?
|
package/support/cli.doc.ts
CHANGED
|
@@ -7,7 +7,10 @@ import { MinLength, Validator } from '@travetto/schema';
|
|
|
7
7
|
import { PackageUtil } from '@travetto/manifest';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
11
|
+
*
|
|
12
|
+
* Supports multiple output formats/targets and optional watch mode for
|
|
13
|
+
* iterative documentation authoring.
|
|
11
14
|
*/
|
|
12
15
|
@CliCommand()
|
|
13
16
|
@Validator(async (cmd) => {
|