@travetto/doc 8.0.0-alpha.2 → 8.0.0-alpha.20
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 +41 -31
- package/__index__.ts +3 -3
- package/package.json +5 -3
- package/src/jsx.ts +53 -19
- package/src/mapping/library.ts +7 -4
- package/src/mapping/module.ts +177 -61
- package/src/render/code-highlight.ts +3 -5
- package/src/render/context.ts +28 -13
- package/src/render/html.ts +63 -22
- package/src/render/markdown.ts +37 -11
- package/src/render/renderer.ts +26 -24
- package/src/types.ts +7 -8
- package/src/util/file.ts +37 -37
- package/src/util/package.ts +19 -13
- package/src/util/resolve.ts +11 -12
- package/src/util/run.ts +14 -10
- package/src/util/types.ts +1 -1
- package/support/cli.doc.ts +12 -11
- package/support/jsx-runtime.ts +26 -15
package/README.md
CHANGED
|
@@ -13,32 +13,33 @@ npm install @travetto/doc
|
|
|
13
13
|
yarn add @travetto/doc
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
This module provides the ability to generate documentation in [HTML](https://en.wikipedia.org/wiki/HTML) and/or [Markdown](https://en.wikipedia.org/wiki/Markdown).
|
|
16
|
+
This module provides the ability to generate documentation in [HTML](https://en.wikipedia.org/wiki/HTML) and/or [Markdown](https://en.wikipedia.org/wiki/Markdown). The module relies on integrating with the source of the project, and providing a fully referenced code-base. This allows for automatic updates when code is changed and/or refactored.
|
|
17
17
|
|
|
18
18
|
**Code: Document Sample**
|
|
19
19
|
```typescript
|
|
20
20
|
/** @jsxImportSource @travetto/doc/support */
|
|
21
21
|
import { c } from '@travetto/doc';
|
|
22
22
|
|
|
23
|
-
export const text =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
export const text = (
|
|
24
|
+
<>
|
|
25
|
+
<c.StdHeader />
|
|
26
|
+
Sample documentation for fictional module. This module fictitiously relies upon <c.Module name="Cache" /> functionality.
|
|
27
|
+
<ol>
|
|
28
|
+
<li>First</li>
|
|
29
|
+
<li>Second</li>
|
|
30
|
+
<li>
|
|
31
|
+
<c.Path name="Special" />
|
|
32
|
+
</li>
|
|
33
|
+
</ol>
|
|
34
|
+
<c.Section title="Content">
|
|
35
|
+
<c.Code title="Document Sample" src="./src/test.ts" />
|
|
36
|
+
|
|
37
|
+
<c.SubSection title="Output">
|
|
38
|
+
<c.Execution title="Run program" cmd="trv" />
|
|
39
|
+
</c.SubSection>
|
|
40
|
+
</c.Section>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
**Code: Document Context**
|
|
@@ -51,12 +52,15 @@ export interface DocumentShape {
|
|
|
51
52
|
|
|
52
53
|
As you can see, you need to export a field named `text` as the body of the help text. The `text` field can be either a direct invocation or an async function that returns the expected document output.
|
|
53
54
|
|
|
54
|
-
**Note**: By design all the node types provided are synchronous in nature.
|
|
55
|
+
**Note**: By design all the node types provided are synchronous in nature. This is intentionally, specifically with respect to invoking commands and ensuring singular operation.
|
|
55
56
|
|
|
56
57
|
## Node Types
|
|
57
58
|
|
|
58
59
|
* `Anchor` - In page anchor reference
|
|
59
60
|
* `Class` - Class reference
|
|
61
|
+
* `CliHelpDescription` - Standardized CLI command help description
|
|
62
|
+
* `CliHelpExecution` - Standardized CLI command help execution
|
|
63
|
+
* `CliHelpSection` - Standardized CLI command help section
|
|
60
64
|
* `Code` - Code sample
|
|
61
65
|
* `CodeLink` - Code link with regexp for detecting line
|
|
62
66
|
* `Command` - Command invocation
|
|
@@ -81,25 +85,31 @@ As you can see, you need to export a field named `text` as the body of the help
|
|
|
81
85
|
* `Terminal` - Terminal output
|
|
82
86
|
|
|
83
87
|
## Libraries
|
|
84
|
-
Some of the more common libraries are provided as the `d.library` method.
|
|
88
|
+
Some of the more common libraries are provided as the `d.library` method. The purpose of this is to have consistent references to common utilities to help keep external linking simple.
|
|
85
89
|
|
|
86
90
|
## Modules
|
|
87
|
-
You can also link to other [Travetto](https://travetto.dev) based modules as needed.
|
|
91
|
+
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
92
|
|
|
89
93
|
## CLI - doc
|
|
90
|
-
|
|
94
|
+
Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
91
95
|
|
|
92
|
-
**Terminal:
|
|
96
|
+
**Terminal: Help for doc**
|
|
93
97
|
```bash
|
|
94
98
|
$ trv doc --help
|
|
95
99
|
|
|
96
100
|
Usage: doc [options]
|
|
97
101
|
|
|
102
|
+
Description:
|
|
103
|
+
Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
104
|
+
|
|
105
|
+
Supports multiple output formats/targets and optional watch mode for
|
|
106
|
+
iterative documentation authoring.
|
|
107
|
+
|
|
98
108
|
Options:
|
|
99
109
|
-i, --input <string> Input File (default: "DOC.tsx")
|
|
100
|
-
-o, --outputs <string> Outputs (default: ["README.md"])
|
|
110
|
+
-o, --outputs <string> Outputs (default: ["README.md","DOC.html"])
|
|
101
111
|
-w, --watch Watch? (default: false)
|
|
102
|
-
|
|
112
|
+
--help display help for command
|
|
103
113
|
```
|
|
104
114
|
|
|
105
115
|
By default, running the command will output the [Markdown](https://en.wikipedia.org/wiki/Markdown) content directly to the terminal.
|
|
@@ -123,7 +133,7 @@ $ trv doc -o html
|
|
|
123
133
|
<span class="token function">yarn</span> <span class="token function">add</span> @travetto-doc/doc</code></pre>
|
|
124
134
|
</figure>
|
|
125
135
|
|
|
126
|
-
Sample documentation for fictional module.
|
|
136
|
+
Sample documentation for fictional module. This module fictitiously relies upon <a class="module-link" href="https://github.com/travetto/travetto/tree/main/module/cache" title="Caching functionality with decorators for declarative use.">Caching</a> functionality.
|
|
127
137
|
<ol> <li>First</li>
|
|
128
138
|
<li>Second</li>
|
|
129
139
|
<li><code class="item path">Special</code></li>
|
|
@@ -137,7 +147,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
|
|
|
137
147
|
|
|
138
148
|
</figcaption>
|
|
139
149
|
<pre><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name">TestFile</span> <span class="token punctuation">{{'{'}}</span>
|
|
140
|
-
<span class="token keyword">static</span> <span class="token function">method</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{{'{'}}</span
|
|
150
|
+
<span class="token keyword">static</span> <span class="token function">method</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">{{'{'}}</span><span class="token punctuation">{{'}'}}</span>
|
|
141
151
|
<span class="token punctuation">{{'}'}}</span></code></pre>
|
|
142
152
|
</figure>
|
|
143
153
|
|
|
@@ -152,7 +162,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
|
|
|
152
162
|
Usage: <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token punctuation">[</span>command<span class="token punctuation">]</span>
|
|
153
163
|
|
|
154
164
|
Commands:
|
|
155
|
-
doc
|
|
156
|
-
<span class="token function">service</span>
|
|
165
|
+
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.
|
|
166
|
+
<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
167
|
</figure>
|
|
158
168
|
```
|
package/__index__.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { type JSXElement as DocJSXElement, isJSXElement as isDocJSXElement } from './support/jsx-runtime.ts';
|
|
2
1
|
export { c, d, JSXElementByFn as DocJSXElementByFn } from './src/jsx.ts';
|
|
3
2
|
export { MODULES as module } from './src/mapping/module.ts';
|
|
4
3
|
export { DocFileUtil } from './src/util/file.ts';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { PackageDocUtil } from './src/util/package.ts';
|
|
5
|
+
export { COMMON_DATE, DocRunUtil } from './src/util/run.ts';
|
|
6
|
+
export { isJSXElement as isDocJSXElement, type JSXElement as DocJSXElement } from './support/jsx-runtime.ts';
|
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.20",
|
|
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.20",
|
|
28
|
+
"@types/markdown-it": "^14.1.2",
|
|
28
29
|
"@types/prismjs": "^1.26.6",
|
|
30
|
+
"markdown-it": "^14.3.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.28"
|
|
33
35
|
},
|
|
34
36
|
"peerDependenciesMeta": {
|
|
35
37
|
"@travetto/cli": {
|
package/src/jsx.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import { castTo, TypedObject } from '@travetto/runtime';
|
|
1
|
+
import { type Class as ClassType, castTo, TypedObject } from '@travetto/runtime';
|
|
2
2
|
|
|
3
|
+
import { type JSXComponentFunction as CompFn, createElement, type JSXElement } from '../support/jsx-runtime.ts';
|
|
3
4
|
import type { LIBRARIES } from './mapping/library.ts';
|
|
4
5
|
import type { MODULES } from './mapping/module.ts';
|
|
5
|
-
import type { CodeProps, CodeSourceInput, RunConfig } from './util/types.ts';
|
|
6
|
-
|
|
7
|
-
import { createElement, type JSXElement, type JSXComponentFunction as CompFn } from '../support/jsx-runtime.ts';
|
|
8
6
|
import { PackageDocUtil } from './util/package.ts';
|
|
7
|
+
import type { CodeProps, CodeSourceInput, RunConfig } from './util/types.ts';
|
|
9
8
|
|
|
10
|
-
type InstallProps = { title: string
|
|
11
|
-
type ExecProps = {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
type InstallProps = { title: string; pkg: string };
|
|
10
|
+
type ExecProps = {
|
|
11
|
+
title: string;
|
|
12
|
+
cmd: string;
|
|
13
|
+
args?: string[];
|
|
14
|
+
config?: RunConfig & { formatCommand?(cmd: string, args: string[]): string };
|
|
15
|
+
};
|
|
16
|
+
type CliHelpProps = { commandClass: ClassType };
|
|
17
|
+
type CliHelpExecutionProps = CliHelpProps & { config?: RunConfig };
|
|
18
|
+
type StdHeaderProps = { module?: string; install?: boolean };
|
|
19
|
+
type HeaderProps = { title: string; description?: string };
|
|
14
20
|
type ModuleProps = { name: keyof typeof MODULES };
|
|
15
21
|
type LibraryProps = { name: keyof typeof LIBRARIES };
|
|
16
|
-
type LinkProps = { title: string
|
|
17
|
-
type CodeLinkProps = { title: string
|
|
22
|
+
type LinkProps = { title: string; href: string; line?: number };
|
|
23
|
+
type CodeLinkProps = { title: string; src: CodeSourceInput; startRe: RegExp };
|
|
18
24
|
type Named = { name: string };
|
|
19
25
|
type Titled = { title: string };
|
|
20
26
|
|
|
@@ -46,23 +52,48 @@ const Config: CompFn<CodeProps> = () => EMPTY; // Configuration block
|
|
|
46
52
|
const StdHeader: CompFn<StdHeaderProps> = () => EMPTY; // Standard module header
|
|
47
53
|
const Header: CompFn<HeaderProps> = () => EMPTY; // Basic module header
|
|
48
54
|
const Execution: CompFn<ExecProps> = () => EMPTY; // Run a command, and include the output as part of the document
|
|
55
|
+
const CliHelpSection: CompFn<CliHelpProps> = () => EMPTY; // Standardized CLI command help section
|
|
56
|
+
const CliHelpDescription: CompFn<CliHelpProps & { short?: boolean }> = () => EMPTY; // Standardized CLI command help description
|
|
57
|
+
const CliHelpExecution: CompFn<CliHelpExecutionProps> = () => EMPTY; // Standardized CLI command help execution
|
|
49
58
|
|
|
50
59
|
const Module: CompFn<ModuleProps> = () => EMPTY; // Node Module Reference
|
|
51
60
|
const Library: CompFn<LibraryProps> = () => EMPTY; // Library reference
|
|
52
61
|
|
|
53
62
|
export const c = {
|
|
54
|
-
Input,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
Input,
|
|
64
|
+
Field,
|
|
65
|
+
Method,
|
|
66
|
+
Command,
|
|
67
|
+
Path,
|
|
68
|
+
Class,
|
|
69
|
+
Anchor,
|
|
70
|
+
Library,
|
|
71
|
+
Ref,
|
|
72
|
+
File,
|
|
73
|
+
Image,
|
|
74
|
+
CodeLink,
|
|
75
|
+
Module,
|
|
76
|
+
Note,
|
|
77
|
+
Header,
|
|
78
|
+
StdHeader,
|
|
79
|
+
Section,
|
|
80
|
+
SubSection,
|
|
81
|
+
SubSubSection,
|
|
82
|
+
Code,
|
|
83
|
+
Execution,
|
|
84
|
+
Terminal,
|
|
85
|
+
Install,
|
|
86
|
+
Config,
|
|
87
|
+
CliHelpSection,
|
|
88
|
+
CliHelpDescription,
|
|
89
|
+
CliHelpExecution
|
|
59
90
|
} as const;
|
|
60
91
|
|
|
61
92
|
type C = typeof c;
|
|
62
93
|
|
|
63
94
|
// @ts-expect-error
|
|
64
95
|
export type JSXElementByFn<K extends keyof C> = JSXElement<C[K], Parameters<C[K]>[0]>;
|
|
65
|
-
export type JSXElements = { [K in keyof C]: JSXElementByFn<K
|
|
96
|
+
export type JSXElements = { [K in keyof C]: JSXElementByFn<K> };
|
|
66
97
|
|
|
67
98
|
export const EMPTY_ELEMENT = EMPTY;
|
|
68
99
|
|
|
@@ -83,7 +114,8 @@ function CodeLinker(titleOrNode: string | JSXElement, src?: string, startRe?: Re
|
|
|
83
114
|
props = { title: titleOrNode, src: src!, startRe: startRe! };
|
|
84
115
|
} else if (titleOrNode.type === Code) {
|
|
85
116
|
const node: JSXElementByFn<'Code'> = castTo(titleOrNode);
|
|
86
|
-
const srcName =
|
|
117
|
+
const srcName =
|
|
118
|
+
typeof node.props.src === 'string' ? node.props.src : typeof node.props.src === 'function' ? node.props.src.name : '<UNNAMED>';
|
|
87
119
|
props = {
|
|
88
120
|
title: node.props.title ?? srcName,
|
|
89
121
|
src: node.props.src,
|
|
@@ -106,5 +138,7 @@ export const d = {
|
|
|
106
138
|
field: (name: string) => createElement(c.Field, { name }),
|
|
107
139
|
library: (name: keyof typeof LIBRARIES) => createElement(c.Library, { name }),
|
|
108
140
|
module: (name: keyof typeof MODULES) => createElement(c.Module, { name }),
|
|
109
|
-
get trv() {
|
|
110
|
-
|
|
141
|
+
get trv() {
|
|
142
|
+
return PackageDocUtil.getPackageCommand('trv');
|
|
143
|
+
}
|
|
144
|
+
};
|
package/src/mapping/library.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const LIBRARIES = {
|
|
|
7
7
|
Npm: { title: 'Npm', href: 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm' },
|
|
8
8
|
Yarn: { title: 'Yarn', href: 'https://yarnpkg.com' },
|
|
9
9
|
Pnpm: { title: 'Pnpm', href: 'https://pnpm.io/' },
|
|
10
|
-
|
|
10
|
+
Biome: { title: 'Biome', href: 'https://biomejs.dev/' },
|
|
11
11
|
Rollup: { title: 'Rollup', href: 'https://rollupjs.org/' },
|
|
12
12
|
TSConfig: { title: 'TS Config', href: 'https://www.typescriptlang.org/docs/handbook/tsconfig-json.html' },
|
|
13
13
|
|
|
@@ -35,7 +35,10 @@ export const LIBRARIES = {
|
|
|
35
35
|
DependencyInjection: { title: 'Dependency injection', href: 'https://en.wikipedia.org/wiki/Dependency_injection' },
|
|
36
36
|
OpenAPI: { title: 'OpenAPI', href: 'https://github.com/OAI/OpenAPI-Specification' },
|
|
37
37
|
JSDoc: { title: 'JSDoc', href: 'http://usejsdoc.org/about-getting-started.html' },
|
|
38
|
-
CodeLens: {
|
|
38
|
+
CodeLens: {
|
|
39
|
+
title: 'CodeLens',
|
|
40
|
+
href: 'https://code.visualstudio.com/api/language-extensions/programmatic-language-features#codelens-show-actionable-context-information-within-source-code'
|
|
41
|
+
},
|
|
39
42
|
ORM: { title: 'Object Relationship Mapping', href: 'https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping' },
|
|
40
43
|
UUID: { title: 'UUID', href: 'https://en.wikipedia.org/wiki/Universally_unique_identifier' },
|
|
41
44
|
|
|
@@ -113,5 +116,5 @@ export const LIBRARIES = {
|
|
|
113
116
|
ServerlessExpress: { title: 'aws-serverless-express', href: 'https://github.com/awslabs/aws-serverless-express/blob/master/README.md' },
|
|
114
117
|
AwsLambdaFastify: { title: '@fastify/aws-lambda', href: 'https://github.com/fastify/aws-lambda-fastify/blob/master/README.md' },
|
|
115
118
|
Fastify: { title: 'fastify', href: 'https://www.fastify.io/' },
|
|
116
|
-
Koa: { title: 'koa', href: 'https://koajs.com/' }
|
|
117
|
-
} as const;
|
|
119
|
+
Koa: { title: 'koa', href: 'https://koajs.com/' }
|
|
120
|
+
} as const;
|