@travetto/doc 3.4.3 → 4.0.0-rc.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/package.json +4 -3
- package/src/mapping/lib-mapping.ts +1 -0
- package/src/render/context.ts +5 -5
- package/src/render/html.ts +4 -4
- package/src/render/markdown.ts +4 -4
- package/src/render/renderer.ts +9 -10
- package/src/util/file.ts +9 -10
- package/src/util/run.ts +17 -16
- package/support/cli.doc.ts +15 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/doc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.0",
|
|
4
4
|
"description": "Documentation support for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
"directory": "module/doc"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/base": "^
|
|
27
|
+
"@travetto/base": "^4.0.0-rc.0",
|
|
28
|
+
"@travetto/terminal": "^4.0.0-rc.0",
|
|
28
29
|
"@types/prismjs": "^1.26.3",
|
|
29
30
|
"prismjs": "^1.29.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"@travetto/cli": "^
|
|
33
|
+
"@travetto/cli": "^4.0.0-rc.0"
|
|
33
34
|
},
|
|
34
35
|
"peerDependenciesMeta": {
|
|
35
36
|
"@travetto/cli": {
|
|
@@ -39,6 +39,7 @@ export const LIB_MAPPING = {
|
|
|
39
39
|
UUID: { title: 'UUID', href: 'https://en.wikipedia.org/wiki/Universally_unique_identifier' },
|
|
40
40
|
|
|
41
41
|
// Node
|
|
42
|
+
Process: { title: 'process', href: 'https://nodejs.org/api/process.html' },
|
|
42
43
|
ChildProcess: { title: 'child_process', href: 'https://nodejs.org/api/child_process.html' },
|
|
43
44
|
AsyncHooks: { title: 'async_hooks', href: 'https://nodejs.org/api/async_hooks.html' },
|
|
44
45
|
Http: { title: 'http', href: 'https://nodejs.org/api/http.html' },
|
package/src/render/context.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
import { PackageUtil, path,
|
|
3
|
+
import { PackageUtil, path, RuntimeIndex } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
import { JSXElementByFn, c } from '../jsx';
|
|
6
6
|
import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
|
|
@@ -35,12 +35,12 @@ export class RenderContext {
|
|
|
35
35
|
|
|
36
36
|
constructor(file: string, baseUrl: string, repoRoot: string) {
|
|
37
37
|
|
|
38
|
-
const manifestPkg = PackageUtil.readPackage(
|
|
38
|
+
const manifestPkg = PackageUtil.readPackage(RuntimeIndex.getModule('@travetto/manifest')!.sourcePath);
|
|
39
39
|
|
|
40
40
|
this.file = path.toPosix(file);
|
|
41
41
|
this.baseUrl = baseUrl;
|
|
42
42
|
this.repoRoot = repoRoot;
|
|
43
|
-
this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.
|
|
43
|
+
this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.doc!.baseUrl!;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -105,7 +105,7 @@ export class RenderContext {
|
|
|
105
105
|
* Resolve code link
|
|
106
106
|
*/
|
|
107
107
|
async resolveCodeLink(node: JSXElementByFn<'CodeLink'>): Promise<ResolvedSnippetLink> {
|
|
108
|
-
const src = typeof node.props.src === 'string' ? node.props.src :
|
|
108
|
+
const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
|
|
109
109
|
return DocResolveUtil.resolveCodeLink(src, node.props.startRe);
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -113,7 +113,7 @@ export class RenderContext {
|
|
|
113
113
|
* Resolve code/config
|
|
114
114
|
*/
|
|
115
115
|
async resolveCode(node: JSXElementByFn<'Code' | 'Config'>): Promise<ResolvedCode> {
|
|
116
|
-
const src = typeof node.props.src === 'string' ? node.props.src :
|
|
116
|
+
const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
|
|
117
117
|
return node.props.startRe ?
|
|
118
118
|
DocResolveUtil.resolveSnippet(src, node.props.startRe, node.props.endRe, node.props.outline) :
|
|
119
119
|
DocResolveUtil.resolveCode(src, node.props.language, node.props.outline);
|
package/src/render/html.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
3
|
import { JSXElement } from '@travetto/doc/jsx-runtime';
|
|
4
|
-
import {
|
|
4
|
+
import { RuntimeIndex, PackageUtil, RuntimeContext } from '@travetto/manifest';
|
|
5
5
|
|
|
6
6
|
import { highlight } from './code-highlight';
|
|
7
7
|
import { RenderProvider, RenderState } from '../types';
|
|
@@ -144,8 +144,8 @@ yarn add ${el.props.pkg}
|
|
|
144
144
|
Header: async ({ props }) => `<h1>${props.title} ${props.description ? `\n<small>${props.description}</small>\n` : ''}</h1>\n`,
|
|
145
145
|
|
|
146
146
|
StdHeader: async state => {
|
|
147
|
-
const mod = state.el.props.mod ??
|
|
148
|
-
const pkg = PackageUtil.readPackage(
|
|
147
|
+
const mod = state.el.props.mod ?? RuntimeContext.main.name;
|
|
148
|
+
const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
|
|
149
149
|
const title = pkg.travetto?.displayName ?? pkg.name;
|
|
150
150
|
const desc = pkg.description;
|
|
151
151
|
let install = '';
|
package/src/render/markdown.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import { PackageUtil,
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { PackageUtil, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
|
|
3
3
|
|
|
4
4
|
import { RenderProvider } from '../types';
|
|
5
5
|
import { c, getComponentName } from '../jsx';
|
|
@@ -108,8 +108,8 @@ ${context.cleanText(content.text)}
|
|
|
108
108
|
Header: async ({ props }) => `# ${props.title}\n${props.description ? `## ${props.description}\n` : ''}\n`,
|
|
109
109
|
|
|
110
110
|
StdHeader: async state => {
|
|
111
|
-
const mod = state.el.props.mod ??
|
|
112
|
-
const pkg = PackageUtil.readPackage(
|
|
111
|
+
const mod = state.el.props.mod ?? RuntimeContext.main.name;
|
|
112
|
+
const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
|
|
113
113
|
const title = pkg.travetto?.displayName ?? pkg.name;
|
|
114
114
|
const desc = pkg.description;
|
|
115
115
|
let install = '';
|
package/src/render/renderer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ManifestContext, PackageUtil, path, RuntimeIndex } from '@travetto/manifest';
|
|
2
2
|
|
|
3
|
-
import { isJSXElement, JSXElement,
|
|
3
|
+
import { isJSXElement, JSXElement, JSXFragmentType } from '@travetto/doc/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
import { EMPTY_ELEMENT, getComponentName, JSXElementByFn, c } from '../jsx';
|
|
6
6
|
import { DocumentShape, RenderProvider, RenderState } from '../types';
|
|
@@ -17,16 +17,15 @@ const providers = { [Html.ext]: Html, [Markdown.ext]: Markdown };
|
|
|
17
17
|
*/
|
|
18
18
|
export class DocRenderer {
|
|
19
19
|
|
|
20
|
-
static async get(file: string, manifest:
|
|
21
|
-
const mod =
|
|
20
|
+
static async get(file: string, manifest: ManifestContext): Promise<DocRenderer> {
|
|
21
|
+
const mod = RuntimeIndex.getFromSource(file)?.import;
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
23
|
const res = await import(mod!) as DocumentShape;
|
|
24
24
|
|
|
25
|
-
const pkg = PackageUtil.readPackage(manifest.
|
|
26
|
-
const
|
|
27
|
-
const repoBaseUrl = pkg.travetto?.docBaseUrl ?? mainPath;
|
|
25
|
+
const pkg = PackageUtil.readPackage(manifest.workspace.path);
|
|
26
|
+
const repoBaseUrl = pkg.travetto?.doc?.baseUrl ?? manifest.workspace.path;
|
|
28
27
|
return new DocRenderer(res,
|
|
29
|
-
new RenderContext(file, repoBaseUrl, path.resolve(pkg.travetto?.
|
|
28
|
+
new RenderContext(file, repoBaseUrl, path.resolve(pkg.travetto?.doc?.root ?? manifest.workspace.path))
|
|
30
29
|
);
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -62,7 +61,7 @@ export class DocRenderer {
|
|
|
62
61
|
final = out !== EMPTY_ELEMENT ? out : final;
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
if (final.type ===
|
|
64
|
+
if (final.type === JSXFragmentType) {
|
|
66
65
|
return this.#render(renderer, final.props.children ?? []);
|
|
67
66
|
}
|
|
68
67
|
|
|
@@ -91,7 +90,7 @@ export class DocRenderer {
|
|
|
91
90
|
case 'bigint':
|
|
92
91
|
case 'boolean': return `${node}`;
|
|
93
92
|
default: {
|
|
94
|
-
const meta = (typeof node === 'function' ?
|
|
93
|
+
const meta = (typeof node === 'function' ? RuntimeIndex.getFunctionMetadata(node) : undefined);
|
|
95
94
|
if (meta && typeof node === 'function') {
|
|
96
95
|
const title = (await DocFileUtil.isDecorator(node.name, meta.source)) ? `@${node.name}` : node.name;
|
|
97
96
|
const el = this.#support.createElement('CodeLink', {
|
package/src/util/file.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { ManifestModuleUtil, path,
|
|
3
|
+
import { ManifestModuleUtil, path, RuntimeIndex } from '@travetto/manifest';
|
|
4
4
|
|
|
5
|
-
const ESLINT_PATTERN = /\s*\/\/ eslint
|
|
5
|
+
const ESLINT_PATTERN = /\s*\/\/ eslint.*$/g;
|
|
6
|
+
const ENV_KEY = /Env.([^.]+)[.]key/g;
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Standard file utilities
|
|
@@ -31,7 +32,7 @@ export class DocFileUtil {
|
|
|
31
32
|
let resolved = path.resolve(file);
|
|
32
33
|
if (!(await fs.stat(resolved).catch(() => false))) {
|
|
33
34
|
if (ManifestModuleUtil.getFileType(file) === 'ts') {
|
|
34
|
-
resolved =
|
|
35
|
+
resolved = RuntimeIndex.getSourceFile(file);
|
|
35
36
|
}
|
|
36
37
|
if (!(await fs.stat(resolved).catch(() => false))) {
|
|
37
38
|
throw new Error(`Unknown file to resolve: ${file}`);
|
|
@@ -57,12 +58,10 @@ export class DocFileUtil {
|
|
|
57
58
|
text = await fs.readFile(file, 'utf8');
|
|
58
59
|
|
|
59
60
|
text = text.split(/\n/)
|
|
60
|
-
.map(x =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return x;
|
|
65
|
-
})
|
|
61
|
+
.map(x => x
|
|
62
|
+
.replace(ESLINT_PATTERN, '')
|
|
63
|
+
.replace(ENV_KEY, (_, k) => `'${k}'`)
|
|
64
|
+
)
|
|
66
65
|
.filter(x => !x.includes('@doc-exclude'))
|
|
67
66
|
.join('\n');
|
|
68
67
|
}
|
package/src/util/run.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import os from 'os';
|
|
1
|
+
import os from 'node:os';
|
|
2
2
|
|
|
3
|
-
import { path,
|
|
4
|
-
import { ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
|
|
5
|
-
import {
|
|
3
|
+
import { path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
|
|
4
|
+
import { Env, ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
|
|
5
|
+
import { StyleUtil } from '@travetto/terminal';
|
|
6
6
|
|
|
7
7
|
export const COMMON_DATE = new Date('2029-03-14T00:00:00.000').getTime();
|
|
8
8
|
|
|
@@ -51,7 +51,7 @@ export class DocRunUtil {
|
|
|
51
51
|
static #docState = new DocState();
|
|
52
52
|
|
|
53
53
|
static runState(cmd: string, args: string[], config: RunConfig = {}): RunState {
|
|
54
|
-
const cwd = config.cwd ?? (config.module ?
|
|
54
|
+
const cwd = config.cwd ?? (config.module ? RuntimeIndex.getModule(config.module)! : RuntimeIndex.mainModule).sourcePath;
|
|
55
55
|
args = [...args];
|
|
56
56
|
return {
|
|
57
57
|
cmd,
|
|
@@ -61,13 +61,14 @@ export class DocRunUtil {
|
|
|
61
61
|
shell: '/bin/bash',
|
|
62
62
|
env: {
|
|
63
63
|
...process.env,
|
|
64
|
-
DEBUG
|
|
65
|
-
TRV_CAN_RESTART
|
|
66
|
-
TRV_CLI_IPC
|
|
67
|
-
TRV_MANIFEST
|
|
68
|
-
TRV_BUILD
|
|
69
|
-
|
|
70
|
-
...(config.
|
|
64
|
+
...Env.DEBUG.export(false),
|
|
65
|
+
...Env.TRV_CAN_RESTART.export(false),
|
|
66
|
+
...Env.TRV_CLI_IPC.export(undefined),
|
|
67
|
+
...Env.TRV_MANIFEST.export(''),
|
|
68
|
+
...Env.TRV_BUILD.export('none'),
|
|
69
|
+
...Env.TRV_ROLE.export(undefined),
|
|
70
|
+
...Env.TRV_MODULE.export(config.module ?? ''),
|
|
71
|
+
...(config.envName ? Env.TRV_ENV.export(config.envName) : {}),
|
|
71
72
|
...(config.env ?? {})
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -78,11 +79,11 @@ export class DocRunUtil {
|
|
|
78
79
|
* Clean run output
|
|
79
80
|
*/
|
|
80
81
|
static cleanRunOutput(text: string, cfg: RunConfig): string {
|
|
81
|
-
const cwd = path.toPosix((cfg.module ?
|
|
82
|
-
text =
|
|
82
|
+
const cwd = path.toPosix((cfg.module ? RuntimeIndex.getModule(cfg.module)! : RuntimeIndex.mainModule).sourcePath);
|
|
83
|
+
text = StyleUtil.cleanText(text.trim())
|
|
83
84
|
.replaceAll(cwd, '.')
|
|
84
85
|
.replaceAll(os.tmpdir(), '/tmp')
|
|
85
|
-
.replaceAll(
|
|
86
|
+
.replaceAll(RuntimeContext.workspace.path, '<workspace-root>')
|
|
86
87
|
.replace(/[/]tmp[/][a-z_A-Z0-9\/\-]+/g, '/tmp/<temp-folder>')
|
|
87
88
|
.replace(/^(\s*framework:\s*')(\d+[.]\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x${post}`)
|
|
88
89
|
.replace(/^(\s*nodeVersion:\s*'v)(\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x.x${post}`)
|
|
@@ -119,7 +120,7 @@ export class DocRunUtil {
|
|
|
119
120
|
if (!res.valid) {
|
|
120
121
|
throw new Error(res.stderr);
|
|
121
122
|
}
|
|
122
|
-
final =
|
|
123
|
+
final = StyleUtil.cleanText(res.stdout.toString()).trim() || StyleUtil.cleanText(res.stderr.toString()).trim();
|
|
123
124
|
} catch (err) {
|
|
124
125
|
if (err instanceof Error) {
|
|
125
126
|
final = err.message;
|
package/support/cli.doc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
-
import { PackageUtil, path,
|
|
4
|
-
import { ExecUtil,
|
|
3
|
+
import { PackageUtil, path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
|
|
4
|
+
import { ExecUtil, Env, watchCompiler } from '@travetto/base';
|
|
5
5
|
import { CliCommandShape, CliCommand, CliValidationError, CliUtil } from '@travetto/cli';
|
|
6
6
|
import { MinLength } from '@travetto/schema';
|
|
7
7
|
|
|
@@ -22,18 +22,16 @@ export class DocCommand implements CliCommandShape {
|
|
|
22
22
|
watch = false;
|
|
23
23
|
|
|
24
24
|
preMain(): void {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
defineEnv({ debug: false, });
|
|
25
|
+
Env.DEBUG.set(false);
|
|
26
|
+
Env.TRV_ROLE.set('doc');
|
|
27
|
+
Env.TRV_CLI_IPC.clear();
|
|
28
|
+
Env.TRV_LOG_PLAIN.set(true);
|
|
29
|
+
Env.FORCE_COLOR.set(false);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
preBind(): void {
|
|
35
|
-
const workspacePkg = PackageUtil.readPackage(
|
|
36
|
-
this.outputs = workspacePkg.travetto?.
|
|
33
|
+
const workspacePkg = PackageUtil.readPackage(RuntimeContext.workspace.path);
|
|
34
|
+
this.outputs = workspacePkg.travetto?.doc?.outputs ?? ['README.md'];
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
preHelp(): void {
|
|
@@ -53,20 +51,20 @@ export class DocCommand implements CliCommandShape {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
const args = process.argv.slice(2).filter(x => !/(-w|--watch)/.test(x));
|
|
56
|
-
await
|
|
54
|
+
await watchCompiler(async ({ action, file }) => {
|
|
57
55
|
if (action === 'update' && file === this.input) {
|
|
58
56
|
await ExecUtil.spawn('npx', ['trv', ...args], {
|
|
59
|
-
cwd:
|
|
60
|
-
env: { TRV_QUIET
|
|
57
|
+
cwd: RuntimeIndex.mainModule.sourcePath,
|
|
58
|
+
env: { ...Env.TRV_QUIET.export(true) },
|
|
61
59
|
stdio: 'inherit', catchAsResult: true
|
|
62
60
|
});
|
|
63
61
|
}
|
|
64
|
-
}, true);
|
|
62
|
+
}, { restartOnExit: true });
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
async render(): Promise<void> {
|
|
68
66
|
const { DocRenderer } = await import('../src/render/renderer.js');
|
|
69
|
-
const ctx = await DocRenderer.get(this.input,
|
|
67
|
+
const ctx = await DocRenderer.get(this.input, RuntimeContext);
|
|
70
68
|
const outputs = this.outputs.map(output =>
|
|
71
69
|
output.includes('.') ? [path.extname(output).replace('.', ''), path.resolve(output)] :
|
|
72
70
|
[output, null] as const
|