@travetto/doc 3.0.2 → 3.1.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/README.md +65 -83
- package/__index__.ts +3 -4
- package/package.json +3 -3
- package/src/jsx.ts +107 -0
- package/src/mapping/lib-mapping.ts +107 -0
- package/src/mapping/mod-mapping.ts +250 -0
- package/src/render/context.ts +95 -25
- package/src/render/html.ts +151 -71
- package/src/render/markdown.ts +123 -60
- package/src/render/renderer.ts +146 -0
- package/src/types.ts +23 -53
- package/src/util/file.ts +28 -13
- package/src/util/resolve.ts +39 -62
- package/src/util/run.ts +11 -22
- package/support/cli.doc.ts +58 -50
- package/src/doc.ts +0 -24
- package/src/lib.ts +0 -109
- package/src/mod-mapping.ts +0 -258
- package/src/mod.ts +0 -8
- package/src/nodes.ts +0 -334
- package/src/render/util.ts +0 -67
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
export const MOD_MAPPING = {
|
|
2
|
+
Asset: {
|
|
3
|
+
name: '@travetto/asset', folder: '@travetto/asset', displayName: 'Asset',
|
|
4
|
+
description: 'Modular library for storing and retrieving binary assets'
|
|
5
|
+
},
|
|
6
|
+
AssetRest: {
|
|
7
|
+
name: '@travetto/asset-rest', folder: '@travetto/asset-rest', displayName: 'Asset Rest Support',
|
|
8
|
+
description: 'Provides integration between the travetto asset and rest module.'
|
|
9
|
+
},
|
|
10
|
+
Auth: {
|
|
11
|
+
name: '@travetto/auth', folder: '@travetto/auth', displayName: 'Authentication',
|
|
12
|
+
description: 'Authentication scaffolding for the Travetto framework'
|
|
13
|
+
},
|
|
14
|
+
AuthModel: {
|
|
15
|
+
name: '@travetto/auth-model', folder: '@travetto/auth-model', displayName: 'Authentication Model',
|
|
16
|
+
description: 'Authentication model support for the Travetto framework'
|
|
17
|
+
},
|
|
18
|
+
AuthRest: {
|
|
19
|
+
name: '@travetto/auth-rest', folder: '@travetto/auth-rest', displayName: 'Rest Auth',
|
|
20
|
+
description: 'Rest authentication integration support for the Travetto framework'
|
|
21
|
+
},
|
|
22
|
+
AuthRestContext: {
|
|
23
|
+
name: '@travetto/auth-rest-context', folder: '@travetto/auth-rest-context', displayName: 'Rest Auth Context',
|
|
24
|
+
description: 'Rest authentication context integration support for the Travetto framework'
|
|
25
|
+
},
|
|
26
|
+
AuthRestJwt: {
|
|
27
|
+
name: '@travetto/auth-rest-jwt', folder: '@travetto/auth-rest-jwt', displayName: 'Rest Auth JWT',
|
|
28
|
+
description: 'Rest authentication JWT integration support for the Travetto framework'
|
|
29
|
+
},
|
|
30
|
+
AuthRestPassport: {
|
|
31
|
+
name: '@travetto/auth-rest-passport', folder: '@travetto/auth-rest-passport', displayName: 'Rest Auth Passport',
|
|
32
|
+
description: 'Rest authentication integration support for the Travetto framework'
|
|
33
|
+
},
|
|
34
|
+
AuthRestSession: {
|
|
35
|
+
name: '@travetto/auth-rest-session', folder: '@travetto/auth-rest-session', displayName: 'Rest Auth Session',
|
|
36
|
+
description: 'Rest authentication session integration support for the Travetto framework'
|
|
37
|
+
},
|
|
38
|
+
Base: {
|
|
39
|
+
name: '@travetto/base', folder: '@travetto/base', displayName: 'Base',
|
|
40
|
+
description: 'Environment config and common utilities for travetto applications.'
|
|
41
|
+
},
|
|
42
|
+
Cache: {
|
|
43
|
+
name: '@travetto/cache', folder: '@travetto/cache', displayName: 'Caching',
|
|
44
|
+
description: 'Caching functionality with decorators for declarative use.'
|
|
45
|
+
},
|
|
46
|
+
Cli: {
|
|
47
|
+
name: '@travetto/cli', folder: '@travetto/cli', displayName: 'Command Line Interface',
|
|
48
|
+
description: 'CLI infrastructure for Travetto framework'
|
|
49
|
+
},
|
|
50
|
+
Command: {
|
|
51
|
+
name: '@travetto/command', folder: '@travetto/command', displayName: 'Command',
|
|
52
|
+
description: 'Support for executing complex commands at runtime.'
|
|
53
|
+
},
|
|
54
|
+
Compiler: {
|
|
55
|
+
name: '@travetto/compiler', folder: '@travetto/compiler', displayName: 'Compiler',
|
|
56
|
+
description: 'The compiler infrastructure for the Travetto framework'
|
|
57
|
+
},
|
|
58
|
+
Config: {
|
|
59
|
+
name: '@travetto/config', folder: '@travetto/config', displayName: 'Configuration',
|
|
60
|
+
description: 'Configuration support'
|
|
61
|
+
},
|
|
62
|
+
Context: {
|
|
63
|
+
name: '@travetto/context', folder: '@travetto/context', displayName: 'Async Context',
|
|
64
|
+
description: 'Async-aware state management, maintaining context across asynchronous calls.'
|
|
65
|
+
},
|
|
66
|
+
Di: {
|
|
67
|
+
name: '@travetto/di', folder: '@travetto/di', displayName: 'Dependency Injection',
|
|
68
|
+
description: 'Dependency registration/management and injection support.'
|
|
69
|
+
},
|
|
70
|
+
Doc: {
|
|
71
|
+
name: '@travetto/doc', folder: '@travetto/doc', displayName: 'Documentation',
|
|
72
|
+
description: 'Documentation support for the Travetto framework'
|
|
73
|
+
},
|
|
74
|
+
Email: {
|
|
75
|
+
name: '@travetto/email', folder: '@travetto/email', displayName: 'Email',
|
|
76
|
+
description: 'Email transmission module.'
|
|
77
|
+
},
|
|
78
|
+
EmailNodemailer: {
|
|
79
|
+
name: '@travetto/email-nodemailer', folder: '@travetto/email-nodemailer', displayName: 'Email Nodemailer Support',
|
|
80
|
+
description: 'Email transmission module.'
|
|
81
|
+
},
|
|
82
|
+
EmailTemplate: {
|
|
83
|
+
name: '@travetto/email-template', folder: '@travetto/email-template', displayName: 'Email Templating',
|
|
84
|
+
description: 'Email templating module'
|
|
85
|
+
},
|
|
86
|
+
Eslint: {
|
|
87
|
+
name: '@travetto/eslint', folder: '@travetto/eslint', displayName: 'ES Linting Rules',
|
|
88
|
+
description: 'ES Linting Rules'
|
|
89
|
+
},
|
|
90
|
+
Image: {
|
|
91
|
+
name: '@travetto/image', folder: '@travetto/image', displayName: 'Image',
|
|
92
|
+
description: 'Image support, resizing, and optimization'
|
|
93
|
+
},
|
|
94
|
+
Jwt: {
|
|
95
|
+
name: '@travetto/jwt', folder: '@travetto/jwt', displayName: 'JWT',
|
|
96
|
+
description: 'JSON Web Token implementation'
|
|
97
|
+
},
|
|
98
|
+
Log: {
|
|
99
|
+
name: '@travetto/log', folder: '@travetto/log', displayName: 'Logging',
|
|
100
|
+
description: 'Logging framework that integrates at the console.log level.'
|
|
101
|
+
},
|
|
102
|
+
Manifest: {
|
|
103
|
+
name: '@travetto/manifest', folder: '@travetto/manifest', displayName: 'Manifest',
|
|
104
|
+
description: 'Support for project indexing, manifesting, along with file watching'
|
|
105
|
+
},
|
|
106
|
+
Model: {
|
|
107
|
+
name: '@travetto/model', folder: '@travetto/model', displayName: 'Data Modeling Support',
|
|
108
|
+
description: 'Datastore abstraction for core operations.'
|
|
109
|
+
},
|
|
110
|
+
ModelDynamodb: {
|
|
111
|
+
name: '@travetto/model-dynamodb', folder: '@travetto/model-dynamodb', displayName: 'DynamoDB Model Support',
|
|
112
|
+
description: 'DynamoDB backing for the travetto model module.'
|
|
113
|
+
},
|
|
114
|
+
ModelElasticsearch: {
|
|
115
|
+
name: '@travetto/model-elasticsearch', folder: '@travetto/model-elasticsearch', displayName: 'Elasticsearch Model Source',
|
|
116
|
+
description: 'Elasticsearch backing for the travetto model module, with real-time modeling support for Elasticsearch mappings.'
|
|
117
|
+
},
|
|
118
|
+
ModelFirestore: {
|
|
119
|
+
name: '@travetto/model-firestore', folder: '@travetto/model-firestore', displayName: 'Firestore Model Support',
|
|
120
|
+
description: 'Firestore backing for the travetto model module.'
|
|
121
|
+
},
|
|
122
|
+
ModelMongo: {
|
|
123
|
+
name: '@travetto/model-mongo', folder: '@travetto/model-mongo', displayName: 'MongoDB Model Support',
|
|
124
|
+
description: 'Mongo backing for the travetto model module.'
|
|
125
|
+
},
|
|
126
|
+
ModelMysql: {
|
|
127
|
+
name: '@travetto/model-mysql', folder: '@travetto/model-mysql', displayName: 'MySQL Model Service',
|
|
128
|
+
description: 'MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
|
|
129
|
+
},
|
|
130
|
+
ModelPostgres: {
|
|
131
|
+
name: '@travetto/model-postgres', folder: '@travetto/model-postgres', displayName: 'PostgreSQL Model Service',
|
|
132
|
+
description: 'PostgreSQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
|
|
133
|
+
},
|
|
134
|
+
ModelQuery: {
|
|
135
|
+
name: '@travetto/model-query', folder: '@travetto/model-query', displayName: 'Data Model Querying',
|
|
136
|
+
description: 'Datastore abstraction for advanced query support.'
|
|
137
|
+
},
|
|
138
|
+
ModelRedis: {
|
|
139
|
+
name: '@travetto/model-redis', folder: '@travetto/model-redis', displayName: 'Redis Model Support',
|
|
140
|
+
description: 'Redis backing for the travetto model module.'
|
|
141
|
+
},
|
|
142
|
+
ModelS3: {
|
|
143
|
+
name: '@travetto/model-s3', folder: '@travetto/model-s3', displayName: 'S3 Model Support',
|
|
144
|
+
description: 'S3 backing for the travetto model module.'
|
|
145
|
+
},
|
|
146
|
+
ModelSql: {
|
|
147
|
+
name: '@travetto/model-sql', folder: '@travetto/model-sql', displayName: 'SQL Model Service',
|
|
148
|
+
description: 'SQL backing for the travetto model module, with real-time modeling support for SQL schemas.'
|
|
149
|
+
},
|
|
150
|
+
ModelSqlite: {
|
|
151
|
+
name: '@travetto/model-sqlite', folder: '@travetto/model-sqlite', displayName: 'SQLite Model Service',
|
|
152
|
+
description: 'SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.'
|
|
153
|
+
},
|
|
154
|
+
Openapi: {
|
|
155
|
+
name: '@travetto/openapi', folder: '@travetto/openapi', displayName: 'OpenAPI Specification',
|
|
156
|
+
description: 'OpenAPI integration support for the Travetto framework'
|
|
157
|
+
},
|
|
158
|
+
Pack: {
|
|
159
|
+
name: '@travetto/pack', folder: '@travetto/pack', displayName: 'Pack',
|
|
160
|
+
description: 'Code packing utilities'
|
|
161
|
+
},
|
|
162
|
+
Registry: {
|
|
163
|
+
name: '@travetto/registry', folder: '@travetto/registry', displayName: 'Registry',
|
|
164
|
+
description: 'Patterns and utilities for handling registration of metadata and functionality for run-time use'
|
|
165
|
+
},
|
|
166
|
+
Repo: {
|
|
167
|
+
name: '@travetto/repo', folder: '@travetto/repo', displayName: 'Repo',
|
|
168
|
+
description: 'Monorepo utilities'
|
|
169
|
+
},
|
|
170
|
+
Rest: {
|
|
171
|
+
name: '@travetto/rest', folder: '@travetto/rest', displayName: 'RESTful API',
|
|
172
|
+
description: 'Declarative api for RESTful APIs with support for the dependency injection module.'
|
|
173
|
+
},
|
|
174
|
+
RestAwsLambda: {
|
|
175
|
+
name: '@travetto/rest-aws-lambda', folder: '@travetto/rest-aws-lambda', displayName: 'RESTful AWS Lambda',
|
|
176
|
+
description: 'RESTful APIs entry point support for AWS Lambdas.'
|
|
177
|
+
},
|
|
178
|
+
RestExpress: {
|
|
179
|
+
name: '@travetto/rest-express', folder: '@travetto/rest-express', displayName: 'Express REST Source',
|
|
180
|
+
description: 'Express provider for the travetto rest module.'
|
|
181
|
+
},
|
|
182
|
+
RestExpressLambda: {
|
|
183
|
+
name: '@travetto/rest-express-lambda', folder: '@travetto/rest-express-lambda', displayName: 'Express REST AWS Lambda Source',
|
|
184
|
+
description: 'Express AWS Lambda provider for the travetto rest module.'
|
|
185
|
+
},
|
|
186
|
+
RestFastify: {
|
|
187
|
+
name: '@travetto/rest-fastify', folder: '@travetto/rest-fastify', displayName: 'Fastify REST Source',
|
|
188
|
+
description: 'Fastify provider for the travetto rest module.'
|
|
189
|
+
},
|
|
190
|
+
RestFastifyLambda: {
|
|
191
|
+
name: '@travetto/rest-fastify-lambda', folder: '@travetto/rest-fastify-lambda', displayName: 'Fastify REST AWS Lambda Source',
|
|
192
|
+
description: 'Fastify AWS Lambda provider for the travetto rest module.'
|
|
193
|
+
},
|
|
194
|
+
RestKoa: {
|
|
195
|
+
name: '@travetto/rest-koa', folder: '@travetto/rest-koa', displayName: 'Koa REST Source',
|
|
196
|
+
description: 'Koa provider for the travetto rest module.'
|
|
197
|
+
},
|
|
198
|
+
RestKoaLambda: {
|
|
199
|
+
name: '@travetto/rest-koa-lambda', folder: '@travetto/rest-koa-lambda', displayName: 'Koa REST AWS Lambda Source',
|
|
200
|
+
description: 'Koa provider for the travetto rest module.'
|
|
201
|
+
},
|
|
202
|
+
RestModel: {
|
|
203
|
+
name: '@travetto/rest-model', folder: '@travetto/rest-model', displayName: 'RESTful Model Routes',
|
|
204
|
+
description: 'RESTful support for generating APIs from Model classes.'
|
|
205
|
+
},
|
|
206
|
+
RestModelQuery: {
|
|
207
|
+
name: '@travetto/rest-model-query', folder: '@travetto/rest-model-query', displayName: 'RESTful Model Query Routes',
|
|
208
|
+
description: 'RESTful support for generating query APIs from Model classes.'
|
|
209
|
+
},
|
|
210
|
+
RestSession: {
|
|
211
|
+
name: '@travetto/rest-session', folder: '@travetto/rest-session', displayName: 'REST Session',
|
|
212
|
+
description: 'Session provider for the travetto rest module.'
|
|
213
|
+
},
|
|
214
|
+
Scaffold: {
|
|
215
|
+
name: '@travetto/scaffold', folder: '@travetto/scaffold', displayName: 'App Scaffold',
|
|
216
|
+
description: 'App Scaffold for the Travetto framework'
|
|
217
|
+
},
|
|
218
|
+
Schema: {
|
|
219
|
+
name: '@travetto/schema', folder: '@travetto/schema', displayName: 'Schema',
|
|
220
|
+
description: 'Data type registry for runtime validation, reflection and binding.'
|
|
221
|
+
},
|
|
222
|
+
SchemaFaker: {
|
|
223
|
+
name: '@travetto/schema-faker', folder: '@travetto/schema-faker', displayName: 'Schema Faker',
|
|
224
|
+
description: 'Data generation for schema-registered objects.'
|
|
225
|
+
},
|
|
226
|
+
Terminal: {
|
|
227
|
+
name: '@travetto/terminal', folder: '@travetto/terminal', displayName: 'Terminal',
|
|
228
|
+
description: 'General terminal support'
|
|
229
|
+
},
|
|
230
|
+
Test: {
|
|
231
|
+
name: '@travetto/test', folder: '@travetto/test', displayName: 'Testing',
|
|
232
|
+
description: 'Declarative test framework'
|
|
233
|
+
},
|
|
234
|
+
TodoApp: {
|
|
235
|
+
name: '@travetto/todo-app', folder: '@travetto/todo-app', displayName: 'Todo Application',
|
|
236
|
+
description: ''
|
|
237
|
+
},
|
|
238
|
+
Transformer: {
|
|
239
|
+
name: '@travetto/transformer', folder: '@travetto/transformer', displayName: 'Transformation',
|
|
240
|
+
description: 'Functionality for AST transformations, with transformer registration, and general utils'
|
|
241
|
+
},
|
|
242
|
+
Worker: {
|
|
243
|
+
name: '@travetto/worker', folder: '@travetto/worker', displayName: 'Worker',
|
|
244
|
+
description: 'Process management utilities, with a focus on inter-process communication'
|
|
245
|
+
},
|
|
246
|
+
Yaml: {
|
|
247
|
+
name: '@travetto/yaml', folder: '@travetto/yaml', displayName: 'YAML',
|
|
248
|
+
description: 'Simple YAML support, provides only clean subset of yaml'
|
|
249
|
+
}
|
|
250
|
+
};
|
package/src/render/context.ts
CHANGED
|
@@ -1,59 +1,129 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { DocNode, RenderContextShape } from '../types';
|
|
3
|
+
import { PackageUtil, path, RootIndex } from '@travetto/manifest';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import { JSXElementByFn, c } from '../jsx';
|
|
6
|
+
import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
|
|
7
|
+
import { DocRunUtil } from '../util/run';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* Render
|
|
10
|
+
* Render Context
|
|
10
11
|
*/
|
|
11
|
-
export class RenderContext
|
|
12
|
+
export class RenderContext {
|
|
12
13
|
|
|
14
|
+
#executeCache: Record<string, string> = {};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Filename
|
|
18
|
+
*/
|
|
13
19
|
file: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Github root for project
|
|
23
|
+
*/
|
|
14
24
|
baseUrl: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Github root for Travetto framework
|
|
28
|
+
*/
|
|
15
29
|
travettoBaseUrl: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Repository root
|
|
33
|
+
*/
|
|
16
34
|
repoRoot: string;
|
|
17
35
|
|
|
18
|
-
constructor(file: string,
|
|
36
|
+
constructor(file: string, baseUrl: string, repoRoot: string) {
|
|
37
|
+
|
|
38
|
+
const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.sourcePath);
|
|
39
|
+
|
|
19
40
|
this.file = path.toPosix(file);
|
|
20
41
|
this.baseUrl = baseUrl;
|
|
21
42
|
this.repoRoot = repoRoot;
|
|
22
|
-
this.travettoBaseUrl =
|
|
43
|
+
this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.docBaseUrl!;
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.map(x => {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
32
|
-
const { title } = x as AllTypeMap['Section'];
|
|
33
|
-
return n.Anchor(title, title);
|
|
34
|
-
})
|
|
35
|
-
);
|
|
46
|
+
/**
|
|
47
|
+
* Get generated comment
|
|
48
|
+
*/
|
|
49
|
+
get generatedStamp(): string {
|
|
50
|
+
return 'This file was generated by @travetto/doc and should not be modified directly';
|
|
36
51
|
}
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
]);
|
|
53
|
+
/**
|
|
54
|
+
* Get rebuilt comment
|
|
55
|
+
*/
|
|
56
|
+
get rebuildStamp(): string {
|
|
57
|
+
return `Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "npx trv doc" to rebuild`;
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Generate link location
|
|
62
|
+
*/
|
|
46
63
|
link(text: string, line?: number | { [key: string]: unknown, line?: number }): string {
|
|
47
64
|
const num = typeof line === 'number' ? line : line?.line;
|
|
48
65
|
return `${text.replace(this.repoRoot, this.baseUrl)
|
|
49
66
|
.replace(/.*@travetto\//, `${this.travettoBaseUrl}/module/`)}${num ? `#L${num}` : ''}`;
|
|
50
67
|
}
|
|
51
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Clean text
|
|
71
|
+
*/
|
|
52
72
|
cleanText(a?: string): string {
|
|
53
73
|
return a ? a.replace(/^[\n ]+|[\n ]+$/gs, '') : '';
|
|
54
74
|
}
|
|
55
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Get a consistent anchor id
|
|
78
|
+
*/
|
|
56
79
|
getAnchorId(a: string): string {
|
|
57
80
|
return a.toLowerCase().replace(/<[^>]+>/g, ' ').replace(/[^a-z0-9]+/g, ' ').trim().replace(/ /g, '-');
|
|
58
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Execute a node that represents a code invocation
|
|
85
|
+
*/
|
|
86
|
+
async execute(node: JSXElementByFn<'Execution'>): Promise<string> {
|
|
87
|
+
const key = node[JSXRuntimeTag]?.id ?? 0;
|
|
88
|
+
if (key && this.#executeCache[key]) {
|
|
89
|
+
return this.#executeCache[key];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { cmd, args = [], config = {} } = node.props;
|
|
93
|
+
const result = await DocRunUtil.run(cmd, args, config);
|
|
94
|
+
return this.#executeCache[key] = result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve a reference to a given node
|
|
99
|
+
*/
|
|
100
|
+
async resolveRef(node: JSXElementByFn<'Ref'>): Promise<ResolvedRef> {
|
|
101
|
+
return DocResolveUtil.resolveRef(node.props.title, node.props.href);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Resolve code link
|
|
106
|
+
*/
|
|
107
|
+
async resolveCodeLink(node: JSXElementByFn<'CodeLink'>): Promise<ResolvedSnippetLink> {
|
|
108
|
+
const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
|
|
109
|
+
return DocResolveUtil.resolveCodeLink(src, node.props.startRe);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Resolve code/config
|
|
114
|
+
*/
|
|
115
|
+
async resolveCode(node: JSXElementByFn<'Code' | 'Config'>): Promise<ResolvedCode> {
|
|
116
|
+
const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
|
|
117
|
+
return node.props.startRe ?
|
|
118
|
+
DocResolveUtil.resolveSnippet(src, node.props.startRe, node.props.endRe, node.props.outline) :
|
|
119
|
+
DocResolveUtil.resolveCode(src, node.props.language, node.props.outline);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Create a new element from a given JSX factory
|
|
124
|
+
*/
|
|
125
|
+
createElement<K extends keyof typeof c>(name: K, props: JSXElementByFn<K>['props']): JSXElementByFn<K> {
|
|
126
|
+
// @ts-expect-error
|
|
127
|
+
return createElement(c[name], props) as JSXElementByFn<K>;
|
|
128
|
+
}
|
|
59
129
|
}
|
package/src/render/html.ts
CHANGED
|
@@ -1,81 +1,161 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import { JSXElement } from '@travetto/doc/jsx-runtime';
|
|
4
|
+
import { RootIndex, PackageUtil } from '@travetto/manifest';
|
|
5
|
+
|
|
3
6
|
import { highlight } from './code-highlight';
|
|
4
|
-
import {
|
|
7
|
+
import { RenderProvider, RenderState } from '../types';
|
|
8
|
+
import { c, getComponentName } from '../jsx';
|
|
9
|
+
import { MOD_MAPPING } from '../mapping/mod-mapping';
|
|
10
|
+
import { LIB_MAPPING } from '../mapping/lib-mapping';
|
|
11
|
+
import { RenderContext } from './context';
|
|
12
|
+
import { DocResolveUtil } from '../util/resolve';
|
|
5
13
|
|
|
6
14
|
const ESCAPE_ENTITIES: Record<string, string> = { '<': '<', '>': '>', '&': '&', '{': "{{'{'}}", '}': "{{'}'}}" };
|
|
7
15
|
const ENTITY_RE = new RegExp(`[${Object.keys(ESCAPE_ENTITIES).join('')}]`, 'gm');
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
const stdInline = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
|
|
18
|
+
`<${el.type}>${await recurse()}</${el.type}>`;
|
|
19
|
+
|
|
20
|
+
const std = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
|
|
21
|
+
`<${el.type}>${await recurse()}</${el.type}>\n`;
|
|
22
|
+
|
|
23
|
+
const stdFull = async ({ recurse, el }: RenderState<JSXElement, RenderContext>): Promise<string> =>
|
|
24
|
+
`\n<${el.type}>${await recurse()}</${el.type}>\n`;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const Html: RenderProvider<RenderContext> = {
|
|
10
28
|
ext: 'html',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
finalize: (text, context) => {
|
|
30
|
+
const brand = `<!-- ${context.generatedStamp} -->\n<!-- ${context.rebuildStamp} -->`;
|
|
31
|
+
const cleaned = text
|
|
32
|
+
.replace(/(<[/](?:a)>)([A-Za-z0-9$])/g, (_, tag, v) => `${tag} ${v}`)
|
|
33
|
+
.replace(/(<[uo]l>)(<li>)/g, (_, a, b) => `${a} ${b}`);
|
|
34
|
+
return `${brand}\n${cleaned}`;
|
|
35
|
+
},
|
|
36
|
+
br: async () => '<br><br>\n',
|
|
37
|
+
hr: async () => '<hr>\n',
|
|
38
|
+
strong: stdInline, em: stdInline,
|
|
39
|
+
h2: stdFull, h3: stdFull, h4: stdFull,
|
|
40
|
+
li: std, ol: stdFull, ul: stdFull,
|
|
41
|
+
table: stdFull, thead: std, tr: std, td: std, tbody: std,
|
|
42
|
+
Execution: async ({ context, el, props, createState }) => {
|
|
43
|
+
const output = await context.execute(el);
|
|
44
|
+
const displayCmd = props.config?.formatCommand?.(props.cmd, props.args ?? []) ??
|
|
45
|
+
`${el.props.cmd} ${(el.props.args ?? []).join(' ')}`;
|
|
46
|
+
const sub = createState('Terminal', {
|
|
47
|
+
language: 'bash',
|
|
48
|
+
title: props.title,
|
|
49
|
+
src: [`$ ${displayCmd}`, '', context.cleanText(output)].join('\n')
|
|
50
|
+
});
|
|
51
|
+
return Html.Terminal(sub);
|
|
52
|
+
},
|
|
53
|
+
Install: async ({ context, el }) => {
|
|
54
|
+
const highlighted = highlight(`
|
|
55
|
+
npm install ${el.props.pkg}
|
|
56
|
+
|
|
57
|
+
# or
|
|
58
|
+
|
|
59
|
+
yarn add ${el.props.pkg}
|
|
60
|
+
`, 'bash');
|
|
61
|
+
|
|
62
|
+
return `\n
|
|
63
|
+
<figure class="install">
|
|
64
|
+
<figcaption class="install">Install ${el.props.title}
|
|
65
|
+
|
|
66
|
+
</figcaption>
|
|
67
|
+
<pre><code class="language-bash">${highlighted}</code></pre>
|
|
68
|
+
</figure>\n\n
|
|
69
|
+
`;
|
|
70
|
+
},
|
|
71
|
+
Terminal: state => Html.Code(state),
|
|
72
|
+
Config: state => Html.Code(state),
|
|
73
|
+
Code: async ({ context, el, props }) => {
|
|
74
|
+
const cls = getComponentName(el.type).replace(/^[A-Z]/g, v => v.toLowerCase());
|
|
75
|
+
const content = await context.resolveCode(el);
|
|
76
|
+
let link: string = '';
|
|
77
|
+
if ('src' in props && content.file) {
|
|
78
|
+
let linkCtx: { file: string, line?: number } = { file: content.file! };
|
|
79
|
+
if (props.startRe) {
|
|
80
|
+
linkCtx = await DocResolveUtil.resolveCodeLink(linkCtx.file, props.startRe);
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return out.join('\n');
|
|
82
|
+
link = `<cite><a target="_blank" href="${context.link(content.file!, linkCtx)}">Source</a></cite>`;
|
|
83
|
+
}
|
|
84
|
+
let lang = props.language ?? content.language;
|
|
85
|
+
if (!lang) {
|
|
86
|
+
if (el.type === c.Terminal) {
|
|
87
|
+
lang = 'bash';
|
|
88
|
+
} else if (el.type === c.Code) {
|
|
89
|
+
lang = 'typescript';
|
|
72
90
|
}
|
|
73
|
-
case 'header':
|
|
74
|
-
return `<h1>${recurse(c.title)}
|
|
75
|
-
${c.description ? `<small>${recurse(c.description)}</small>\n` : ''}
|
|
76
|
-
</h1>\n${('install' in c && c.install) ? recurse(n.Install(`Install ${c.package}`, c.package)) : ''}\n`;
|
|
77
|
-
case 'text':
|
|
78
|
-
return c.content;
|
|
79
91
|
}
|
|
92
|
+
|
|
93
|
+
const highlighted = context.cleanText(highlight(content.text, lang));
|
|
94
|
+
return `\n
|
|
95
|
+
<figure class="${cls}">
|
|
96
|
+
<figcaption class="${cls}">${props.title}\n${link}\n\n</figcaption>
|
|
97
|
+
<pre><code class="language-${lang}">${highlighted}</code></pre>
|
|
98
|
+
</figure>\n\n`;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
Section: async ({ context, recurse, props: { title } }) =>
|
|
102
|
+
`\n<h2 id="${context.getAnchorId(title)}">${title}</h2>\n\n${await recurse()}\n`,
|
|
103
|
+
SubSection: async ({ context, recurse, props: { title } }) =>
|
|
104
|
+
`\n<h3 id="${context.getAnchorId(title)}">${title}</h3>\n\n${await recurse()}\n`,
|
|
105
|
+
SubSubSection: async ({ context, recurse, props: { title } }) =>
|
|
106
|
+
`\n<h4 id="${context.getAnchorId(title)}">${title}</h4>\n\n${await recurse()}\n`,
|
|
107
|
+
|
|
108
|
+
Command: state => Html.Input(state),
|
|
109
|
+
Method: state => Html.Input(state),
|
|
110
|
+
Path: state => Html.Input(state),
|
|
111
|
+
Class: state => Html.Input(state),
|
|
112
|
+
Field: state => Html.Input(state),
|
|
113
|
+
Input: async ({ el, context }) => {
|
|
114
|
+
const cls = getComponentName(el.type).replace(/^[A-Z]/g, v => v.toLowerCase());
|
|
115
|
+
return `<code class="item ${cls}">${context.cleanText(el.props.name.replace(ENTITY_RE, k => ESCAPE_ENTITIES[k]))}</code>`;
|
|
116
|
+
},
|
|
117
|
+
CodeLink: async ({ context, props, el }) => {
|
|
118
|
+
const target = await context.resolveCodeLink(el);
|
|
119
|
+
return `<a target="_blank" class="source-link" href="${context.link(target.file, target)}">${props.title}</a>`;
|
|
120
|
+
},
|
|
121
|
+
Anchor: async ({ context, props }) =>
|
|
122
|
+
`<a class="anchor-link" routerLink="." fragment="${context.getAnchorId(props.href)}">${props.title}</a>`,
|
|
123
|
+
|
|
124
|
+
File: state => Html.Ref(state),
|
|
125
|
+
Ref: async ({ context, props }) =>
|
|
126
|
+
`<a target="_blank" class="source-link" href="${context.link(props.href, props)}">${props.title}</a>`,
|
|
127
|
+
Image: async ({ context, props }) => {
|
|
128
|
+
if (!/^https?:/.test(props.href) && !(await fs.stat(props.href).catch(() => false))) {
|
|
129
|
+
throw new Error(`${props.href} is not a valid location`);
|
|
130
|
+
}
|
|
131
|
+
return `<img src="${context.link(props.href, props)}" alt="${props.title}">`;
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
Mod: async ({ context, props }) => {
|
|
135
|
+
const cfg = MOD_MAPPING[props.name];
|
|
136
|
+
return `<a class="module-link" href="${context.link(cfg.folder, cfg)}" title="${cfg.description}">${cfg.displayName}</a>`;
|
|
137
|
+
},
|
|
138
|
+
Library: async ({ context, props }) => {
|
|
139
|
+
const cfg = LIB_MAPPING[props.name];
|
|
140
|
+
return `<a target="_blank" class="external-link" href="${context.link(cfg.href, cfg)}">${cfg.title}</a>`;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
Note: async ({ recurse }) => `\n\n<p class="note"><strong>Note</strong> ${await recurse()}</p>\n`,
|
|
144
|
+
Header: async ({ props }) => `<h1>${props.title} ${props.description ? `\n<small>${props.description}</small>\n` : ''}</h1>\n`,
|
|
145
|
+
|
|
146
|
+
StdHeader: async state => {
|
|
147
|
+
const mod = state.el.props.mod ?? RootIndex.mainPackage.name;
|
|
148
|
+
const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.sourcePath);
|
|
149
|
+
const title = pkg.travetto?.displayName ?? pkg.name;
|
|
150
|
+
const desc = pkg.description;
|
|
151
|
+
let install = '';
|
|
152
|
+
if (state.el.props.install !== false) {
|
|
153
|
+
const sub = state.createState('Install', {
|
|
154
|
+
title: pkg.name,
|
|
155
|
+
pkg: pkg.name,
|
|
156
|
+
});
|
|
157
|
+
install = await Html.Install(sub);
|
|
158
|
+
}
|
|
159
|
+
return `<h1>${title}${desc ? `\n<small>${desc}</small>\n` : ''}</h1>\n${install}\n`;
|
|
80
160
|
}
|
|
81
|
-
};
|
|
161
|
+
};
|