Skip to content

Commit da539ca

Browse files
Changes required to include @lit-labs/context to generated documentation
1 parent 760db7e commit da539ca

File tree

7 files changed

+113
-60
lines changed

7 files changed

+113
-60
lines changed

packages/lit-dev-content/site/_includes/docs-nav-collapsing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<li{% if child.url == page.url %} class="active"{% endif %}>
2929
<a href="{{ child.url | url }}">
3030
{{ child.title }}
31-
{% if child.labs == true %}
31+
{% if child.labs == true or child.labs == "true" %}
3232
<img class="labs" src="/images/alerts/labs.svg" alt="labs" loading="lazy" fetchpriority="low" />
3333
{% endif %}
3434
</a>

packages/lit-dev-content/site/_includes/docs-nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<li{% if child.url == page.url %} class="active"{% endif %}>
4040
<a href="{{ child.url | url }}">
4141
{{ child.title }}
42-
{% if child.labs == true %}
42+
{% if child.labs == true or child.labs == "true" %}
4343
<img class="labs" src="/images/alerts/labs.svg" alt="labs" loading="lazy" fetchpriority="low" />
4444
{% endif %}
4545
</a>

packages/lit-dev-content/site/docs/api/api.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
title: "{{ data.title }}"
1414
eleventyNavigation:
1515
key: "{{ data.title }}"
16+
labs: "{{ data.labs }}"
1617
parent: API
1718
apiPath: /docs/api
1819
---

packages/lit-dev-tools-cjs/src/api-docs/configs/lit-2.ts

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const gitDir = pathlib.join(workDir, 'repo');
1616
const litDir = pathlib.join(gitDir, 'packages', 'lit');
1717
const srcDir = pathlib.join(litDir, 'src');
1818

19+
const contextDir = pathlib.join(gitDir, 'packages', 'labs', 'context');
20+
const contextSrcDir = pathlib.join(contextDir, 'src');
21+
1922
/**
2023
* lit.dev API docs configuration for Lit 2.x
2124
*/
@@ -24,7 +27,6 @@ export const lit2Config: ApiDocsConfig = {
2427
commit: 'c134604f178e36444261d83eabe9e578c1ed90c4',
2528
workDir,
2629
gitDir,
27-
tsConfigPath: pathlib.join(litDir, 'tsconfig.json'),
2830
pagesOutPath: pathlib.resolve(workDir, 'pages.json'),
2931
symbolsOutPath: pathlib.resolve(workDir, 'symbols.json'),
3032
typedocRoot: pathlib.join(root, 'packages'),
@@ -36,21 +38,41 @@ export const lit2Config: ApiDocsConfig = {
3638
},
3739
],
3840

39-
entrypointModules: [
40-
pathlib.join(srcDir, 'async-directive.ts'),
41-
pathlib.join(srcDir, 'decorators.ts'),
42-
pathlib.join(srcDir, 'directives/'), // Entire directory
43-
pathlib.join(srcDir, 'directive.ts'),
44-
pathlib.join(srcDir, 'directive-helpers.ts'),
45-
// Don't include html.ts because it is already re-exported by index.ts.
46-
// pathlib.join(srcDir, 'html.ts'),
47-
// Don't include hydration because it's not ready yet.
48-
// pathlib.join(srcDir, 'hydrate.ts'),
49-
// pathlib.join(srcDir, 'hydrate-support.ts'),
50-
pathlib.join(srcDir, 'index.ts'),
51-
// Don't include polyfill-support.ts because it doesn't export anything.
52-
// pathlib.join(srcDir, 'polyfill-support.ts'),
53-
pathlib.join(srcDir, 'static-html.ts'),
41+
packages: [
42+
// 'lit' module documentation
43+
{
44+
tsConfigPath: pathlib.join(litDir, 'tsconfig.json'),
45+
46+
entrypointModules: [
47+
pathlib.join(srcDir, 'async-directive.ts'),
48+
pathlib.join(srcDir, 'decorators.ts'),
49+
pathlib.join(srcDir, 'directives/*'), // Entire directory
50+
pathlib.join(srcDir, 'directive.ts'),
51+
pathlib.join(srcDir, 'directive-helpers.ts'),
52+
// Don't include html.ts because it is already re-exported by index.ts.
53+
// pathlib.join(srcDir, 'html.ts'),
54+
// Don't include hydration because it's not ready yet.
55+
// pathlib.join(srcDir, 'hydrate.ts'),
56+
// pathlib.join(srcDir, 'hydrate-support.ts'),
57+
pathlib.join(srcDir, 'index.ts'),
58+
// Don't include polyfill-support.ts because it doesn't export anything.
59+
// pathlib.join(srcDir, 'polyfill-support.ts'),
60+
pathlib.join(srcDir, 'static-html.ts'),
61+
],
62+
},
63+
// @lit-labs/context documentation
64+
{
65+
tsConfigPath: pathlib.join(contextDir, 'tsconfig.json'),
66+
entrypointModules: [
67+
pathlib.join(contextSrcDir, 'index.ts'),
68+
pathlib.join(contextSrcDir, 'lib/context-request-event.ts'),
69+
pathlib.join(contextSrcDir, 'lib/create-context.ts'),
70+
pathlib.join(contextSrcDir, 'lib/controllers/context-consumer.ts'),
71+
pathlib.join(contextSrcDir, 'lib/controllers/context-provider.ts'),
72+
pathlib.join(contextSrcDir, 'lib/decorators/provide.ts'),
73+
pathlib.join(contextSrcDir, 'lib/decorators/consume.ts'),
74+
],
75+
},
5476
],
5577

5678
symbolOrder: ['LitElement', 'ReactiveElement'],
@@ -127,6 +149,12 @@ export const lit2Config: ApiDocsConfig = {
127149
v1: 'api/lit-element/LitElement/',
128150
},
129151
},
152+
// Add @lit-labs/context page.
153+
{
154+
slug: 'context',
155+
title: 'Context',
156+
labs: true,
157+
},
130158
],
131159

132160
pageForSymbol(node): string {
@@ -139,6 +167,10 @@ export const lit2Config: ApiDocsConfig = {
139167
return 'decorators';
140168
}
141169

170+
if (entrypoint.includes('/context/')) {
171+
return 'context';
172+
}
173+
142174
if (
143175
entrypoint.endsWith('/directive.ts') ||
144176
entrypoint.endsWith('/directive-helpers.ts') ||
@@ -225,6 +257,13 @@ export const lit2Config: ApiDocsConfig = {
225257
// fine in practice, but when we add e.g. @lit/localize we'll need to be
226258
// smarter here.
227259
let [_, pkg, pathMinusExtension] = match;
260+
261+
if (pkg === "labs/context") {
262+
// There are no @lit-labs/context path extensions because everything is
263+
// re-exported from root.
264+
return "@lit-labs/context"
265+
}
266+
228267
// TODO(aomarks) This wrongly assumes index.ts is always the package main.
229268
return pathMinusExtension === 'index'
230269
? pkg

packages/lit-dev-tools-cjs/src/api-docs/generate.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as fs from 'fs/promises';
99
import * as pathlib from 'path';
1010
import {execFile} from 'child_process';
1111
import {promisify} from 'util';
12-
import {ApiDocsTransformer} from './transformer.js';
12+
import {ApiDocsTransformer, Pages, SymbolMap} from './transformer.js';
1313
import {lit2Config} from './configs/lit-2.js';
1414

1515
import type {ApiDocsConfig} from './types.js';
@@ -89,37 +89,42 @@ const analyze = async (config: ApiDocsConfig) => {
8989
}
9090

9191
console.log(`Analyzing ${config.gitDir}`);
92-
const app = new typedoc.Application();
93-
app.options.addReader(new typedoc.TSConfigReader());
94-
app.bootstrap({
95-
tsconfig: config.tsConfigPath,
96-
entryPoints: config.entrypointModules,
97-
entryPointStrategy: typedoc.EntryPointStrategy.Expand,
98-
});
99-
const root = app.convert();
100-
if (!root) {
101-
throw new Error('TypeDoc.Application.convert() returned undefined');
102-
}
92+
const allPages: Pages = [];
93+
const allSymbols: SymbolMap = {};
94+
for (const pkg of config.packages) {
95+
const app = new typedoc.Application();
96+
app.options.addReader(new typedoc.TSConfigReader());
97+
app.bootstrap({
98+
tsconfig: pkg.tsConfigPath,
99+
entryPoints: pkg.entrypointModules,
100+
});
101+
const root = app.convert();
102+
if (!root) {
103+
throw new Error('TypeDoc.Application.convert() returned undefined');
104+
}
103105

104-
const json = await app.serializer.projectToObject(
105-
root,
106-
pathlib.resolve(config.tsConfigPath, '..')
107-
);
108-
const transformer = new ApiDocsTransformer(json, config);
109-
const {pages, symbolMap} = await transformer.transform();
106+
const json = app.serializer.projectToObject(
107+
root,
108+
pathlib.resolve(pkg.tsConfigPath, '..')
109+
);
110+
const transformer = new ApiDocsTransformer(json, config);
111+
const {pages, symbolMap} = await transformer.transform();
112+
allPages.push(...pages);
113+
Object.assign(allSymbols, symbolMap);
114+
}
110115

111116
await fs.mkdir(pathlib.dirname(config.pagesOutPath), {recursive: true});
112117
await fs.writeFile(
113118
config.pagesOutPath,
114-
JSON.stringify(pages, null, 2),
119+
JSON.stringify(allPages, null, 2),
115120
'utf8'
116121
);
117122
console.log(`Wrote ${config.pagesOutPath}`);
118123

119124
await fs.mkdir(pathlib.dirname(config.symbolsOutPath), {recursive: true});
120125
await fs.writeFile(
121126
config.symbolsOutPath,
122-
JSON.stringify(symbolMap, null, 2),
127+
JSON.stringify(allSymbols, null, 2),
123128
'utf8'
124129
);
125130
console.log(`Wrote ${config.symbolsOutPath}`);

packages/lit-dev-tools-cjs/src/api-docs/transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const symbolToExternalLink = new Map([
6666
* Data consumed by lit.dev API docs Eleventy template. Each item is a separate
6767
* page.
6868
*/
69-
type Pages = Array<{
69+
export type Pages = Array<{
7070
slug: string;
7171
title: string;
7272
items: Array<DeclarationReflection>;
@@ -76,7 +76,7 @@ type Pages = Array<{
7676
* Map from $symbol to the location it appears in our docs. If there is more
7777
* than one item, then the symbol is ambiguous.
7878
*/
79-
type SymbolMap = {
79+
export type SymbolMap = {
8080
[symbol: string]: Array<Location>;
8181
};
8282

packages/lit-dev-tools-cjs/src/api-docs/types.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ export interface Location {
5757
excludeFromTOC?: boolean;
5858
}
5959

60+
/**
61+
* A package, such as `lit` or `@lit-labs/context`.
62+
*/
63+
export interface Package {
64+
/**
65+
* Path to the tsconfig.json that owns the entrypoint modules.
66+
*/
67+
tsConfigPath: string;
68+
69+
/**
70+
* Entrypoint TypeScript modules for TypeDoc to analyze.
71+
*
72+
* The modules listed here should be the preferred modules that users should
73+
* import from, because import statements will be generated using these
74+
* entrypoints as the module specifier (e.g. `import {LitElement} from
75+
* 'lit'`). GitHub source links will be generated pointing at the ultimate
76+
* location where the symbol is concretely defined (e.g.
77+
* `packages/lit-element/src/lit-element.ts`).
78+
*
79+
* If a directory, all .ts files within it are included.
80+
*/
81+
entrypointModules: Array<string>;
82+
}
83+
6084
export interface ApiDocsConfig {
6185
/**
6286
* Git repo remote URL.
@@ -78,37 +102,20 @@ export interface ApiDocsConfig {
78102
*/
79103
gitDir: string;
80104

81-
/**
82-
* Path to the tsconfig.json that owns the entrypoint modules.
83-
*/
84-
tsConfigPath: string;
85-
86105
/**
87106
* The directory that TypeDoc chooses as the root of this package. Unclear why
88107
* this is unpredictable.
89108
*/
90109
typedocRoot: string;
91110

111+
packages: Package[];
112+
92113
/**
93114
* Extra setup/build commands to run after NPM install and before running
94115
* TypeDoc.
95116
*/
96117
extraSetupCommands?: Array<{cmd: string; args: string[]}>;
97118

98-
/**
99-
* Entrypoint TypeScript modules for TypeDoc to analyze.
100-
*
101-
* The modules listed here should be the preferred modules that users should
102-
* import from, because import statements will be generated using these
103-
* entrypoints as the module specifier (e.g. `import {LitElement} from
104-
* 'lit'`). GitHub source links will be generated pointing at the ultimate
105-
* location where the symbol is concretely defined (e.g.
106-
* `packages/lit-element/src/lit-element.ts`).
107-
*
108-
* If a directory, all .ts files within it are included.
109-
*/
110-
entrypointModules: string[];
111-
112119
/**
113120
* Where to write the API data that is consumed by our Eleventy template.
114121
*/
@@ -133,7 +140,8 @@ export interface ApiDocsConfig {
133140
slug: string;
134141
title: string;
135142
tocFilter?: (node: DeclarationReflection) => boolean;
136-
versionLinks?: {[version: string]: string};
143+
versionLinks?: { [version: string]: string };
144+
labs?: true;
137145
}>;
138146

139147
/**

0 commit comments

Comments
 (0)