@travetto/doc 8.0.0-alpha.19 → 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 +26 -25
- package/__index__.ts +3 -3
- package/package.json +3 -3
- package/src/jsx.ts +48 -20
- package/src/mapping/library.ts +7 -4
- package/src/mapping/module.ts +170 -58
- package/src/render/code-highlight.ts +3 -5
- package/src/render/context.ts +19 -15
- package/src/render/html.ts +41 -27
- package/src/render/markdown.ts +18 -16
- package/src/render/renderer.ts +23 -21
- 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 +7 -9
- 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,7 +52,7 @@ 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
|
|
|
@@ -84,10 +85,10 @@ As you can see, you need to export a field named `text` as the body of the help
|
|
|
84
85
|
* `Terminal` - Terminal output
|
|
85
86
|
|
|
86
87
|
## Libraries
|
|
87
|
-
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.
|
|
88
89
|
|
|
89
90
|
## Modules
|
|
90
|
-
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.
|
|
91
92
|
|
|
92
93
|
## CLI - doc
|
|
93
94
|
Generate documentation outputs from a module `DOC.tsx` entry file.
|
|
@@ -132,7 +133,7 @@ $ trv doc -o html
|
|
|
132
133
|
<span class="token function">yarn</span> <span class="token function">add</span> @travetto-doc/doc</code></pre>
|
|
133
134
|
</figure>
|
|
134
135
|
|
|
135
|
-
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.
|
|
136
137
|
<ol> <li>First</li>
|
|
137
138
|
<li>Second</li>
|
|
138
139
|
<li><code class="item path">Special</code></li>
|
|
@@ -146,7 +147,7 @@ Sample documentation for fictional module. This module fictitiously relies upon
|
|
|
146
147
|
|
|
147
148
|
</figcaption>
|
|
148
149
|
<pre><code class="language-typescript"><span class="token keyword">class</span> <span class="token class-name">TestFile</span> <span class="token punctuation">{{'{'}}</span>
|
|
149
|
-
<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>
|
|
150
151
|
<span class="token punctuation">{{'}'}}</span></code></pre>
|
|
151
152
|
</figure>
|
|
152
153
|
|
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,14 +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
28
|
"@types/markdown-it": "^14.1.2",
|
|
29
29
|
"@types/prismjs": "^1.26.6",
|
|
30
30
|
"markdown-it": "^14.3.0",
|
|
31
31
|
"prismjs": "^1.30.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
34
|
+
"@travetto/cli": "^8.0.0-alpha.28"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@travetto/cli": {
|
package/src/jsx.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import {
|
|
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 = {
|
|
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
|
+
};
|
|
12
16
|
type CliHelpProps = { commandClass: ClassType };
|
|
13
17
|
type CliHelpExecutionProps = CliHelpProps & { config?: RunConfig };
|
|
14
|
-
type StdHeaderProps = { module?: string
|
|
15
|
-
type HeaderProps = { title: string
|
|
18
|
+
type StdHeaderProps = { module?: string; install?: boolean };
|
|
19
|
+
type HeaderProps = { title: string; description?: string };
|
|
16
20
|
type ModuleProps = { name: keyof typeof MODULES };
|
|
17
21
|
type LibraryProps = { name: keyof typeof LIBRARIES };
|
|
18
|
-
type LinkProps = { title: string
|
|
19
|
-
type CodeLinkProps = { title: string
|
|
22
|
+
type LinkProps = { title: string; href: string; line?: number };
|
|
23
|
+
type CodeLinkProps = { title: string; src: CodeSourceInput; startRe: RegExp };
|
|
20
24
|
type Named = { name: string };
|
|
21
25
|
type Titled = { title: string };
|
|
22
26
|
|
|
@@ -56,19 +60,40 @@ const Module: CompFn<ModuleProps> = () => EMPTY; // Node Module Reference
|
|
|
56
60
|
const Library: CompFn<LibraryProps> = () => EMPTY; // Library reference
|
|
57
61
|
|
|
58
62
|
export const c = {
|
|
59
|
-
Input,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
65
90
|
} as const;
|
|
66
91
|
|
|
67
92
|
type C = typeof c;
|
|
68
93
|
|
|
69
94
|
// @ts-expect-error
|
|
70
95
|
export type JSXElementByFn<K extends keyof C> = JSXElement<C[K], Parameters<C[K]>[0]>;
|
|
71
|
-
export type JSXElements = { [K in keyof C]: JSXElementByFn<K
|
|
96
|
+
export type JSXElements = { [K in keyof C]: JSXElementByFn<K> };
|
|
72
97
|
|
|
73
98
|
export const EMPTY_ELEMENT = EMPTY;
|
|
74
99
|
|
|
@@ -89,7 +114,8 @@ function CodeLinker(titleOrNode: string | JSXElement, src?: string, startRe?: Re
|
|
|
89
114
|
props = { title: titleOrNode, src: src!, startRe: startRe! };
|
|
90
115
|
} else if (titleOrNode.type === Code) {
|
|
91
116
|
const node: JSXElementByFn<'Code'> = castTo(titleOrNode);
|
|
92
|
-
const srcName =
|
|
117
|
+
const srcName =
|
|
118
|
+
typeof node.props.src === 'string' ? node.props.src : typeof node.props.src === 'function' ? node.props.src.name : '<UNNAMED>';
|
|
93
119
|
props = {
|
|
94
120
|
title: node.props.title ?? srcName,
|
|
95
121
|
src: node.props.src,
|
|
@@ -112,5 +138,7 @@ export const d = {
|
|
|
112
138
|
field: (name: string) => createElement(c.Field, { name }),
|
|
113
139
|
library: (name: keyof typeof LIBRARIES) => createElement(c.Library, { name }),
|
|
114
140
|
module: (name: keyof typeof MODULES) => createElement(c.Module, { name }),
|
|
115
|
-
get trv() {
|
|
116
|
-
|
|
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;
|