-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lit-labs/context docs #1100
base: main
Are you sure you want to change the base?
Changes from all commits
da3a262
93d8e76
760db7e
da539ca
495af6e
ca5321d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ const gitDir = pathlib.join(workDir, 'repo'); | |
const litDir = pathlib.join(gitDir, 'packages', 'lit'); | ||
const srcDir = pathlib.join(litDir, 'src'); | ||
|
||
const contextDir = pathlib.join(gitDir, 'packages', 'labs', 'context'); | ||
const contextSrcDir = pathlib.join(contextDir, 'src'); | ||
|
||
/** | ||
* lit.dev API docs configuration for Lit 2.x | ||
*/ | ||
|
@@ -24,7 +27,6 @@ export const lit2Config: ApiDocsConfig = { | |
commit: 'c134604f178e36444261d83eabe9e578c1ed90c4', | ||
workDir, | ||
gitDir, | ||
tsConfigPath: pathlib.join(litDir, 'tsconfig.json'), | ||
pagesOutPath: pathlib.resolve(workDir, 'pages.json'), | ||
symbolsOutPath: pathlib.resolve(workDir, 'symbols.json'), | ||
typedocRoot: pathlib.join(root, 'packages'), | ||
|
@@ -36,24 +38,51 @@ export const lit2Config: ApiDocsConfig = { | |
}, | ||
], | ||
|
||
entrypointModules: [ | ||
pathlib.join(srcDir, 'async-directive.ts'), | ||
pathlib.join(srcDir, 'decorators.ts'), | ||
pathlib.join(srcDir, 'directives/'), // Entire directory | ||
pathlib.join(srcDir, 'directive.ts'), | ||
pathlib.join(srcDir, 'directive-helpers.ts'), | ||
// Don't include html.ts because it is already re-exported by index.ts. | ||
// pathlib.join(srcDir, 'html.ts'), | ||
// Don't include hydration because it's not ready yet. | ||
// pathlib.join(srcDir, 'hydrate.ts'), | ||
// pathlib.join(srcDir, 'hydrate-support.ts'), | ||
pathlib.join(srcDir, 'index.ts'), | ||
// Don't include polyfill-support.ts because it doesn't export anything. | ||
// pathlib.join(srcDir, 'polyfill-support.ts'), | ||
pathlib.join(srcDir, 'static-html.ts'), | ||
packages: [ | ||
// 'lit' module documentation | ||
{ | ||
tsConfigPath: pathlib.join(litDir, 'tsconfig.json'), | ||
|
||
entrypointModules: [ | ||
pathlib.join(srcDir, 'async-directive.ts'), | ||
pathlib.join(srcDir, 'decorators.ts'), | ||
pathlib.join(srcDir, 'directives/*'), // Entire directory | ||
pathlib.join(srcDir, 'directive.ts'), | ||
pathlib.join(srcDir, 'directive-helpers.ts'), | ||
// Don't include html.ts because it is already re-exported by index.ts. | ||
// pathlib.join(srcDir, 'html.ts'), | ||
// Don't include hydration because it's not ready yet. | ||
// pathlib.join(srcDir, 'hydrate.ts'), | ||
// pathlib.join(srcDir, 'hydrate-support.ts'), | ||
pathlib.join(srcDir, 'index.ts'), | ||
// Don't include polyfill-support.ts because it doesn't export anything. | ||
// pathlib.join(srcDir, 'polyfill-support.ts'), | ||
pathlib.join(srcDir, 'static-html.ts'), | ||
], | ||
}, | ||
// @lit-labs/context documentation | ||
{ | ||
tsConfigPath: pathlib.join(contextDir, 'tsconfig.json'), | ||
entrypointModules: [ | ||
pathlib.join(contextSrcDir, 'index.ts'), | ||
pathlib.join(contextSrcDir, 'lib/context-request-event.ts'), | ||
pathlib.join(contextSrcDir, 'lib/create-context.ts'), | ||
pathlib.join(contextSrcDir, 'lib/controllers/context-consumer.ts'), | ||
pathlib.join(contextSrcDir, 'lib/controllers/context-provider.ts'), | ||
pathlib.join(contextSrcDir, 'lib/decorators/provide.ts'), | ||
pathlib.join(contextSrcDir, 'lib/decorators/consume.ts'), | ||
], | ||
}, | ||
], | ||
|
||
symbolOrder: ['LitElement', 'ReactiveElement'], | ||
symbolOrder: [ | ||
'LitElement', | ||
'ReactiveElement', | ||
/** @lit-labs/context symbol ordering */ | ||
'createContext', | ||
'consume', | ||
'provide', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add ContextConsumer, ContextProvider, and ContextRoot here for now. |
||
], | ||
|
||
pages: [ | ||
{ | ||
|
@@ -127,6 +156,12 @@ export const lit2Config: ApiDocsConfig = { | |
v1: 'api/lit-element/LitElement/', | ||
}, | ||
}, | ||
// Add @lit-labs/context page. | ||
{ | ||
slug: 'context', | ||
title: 'Context', | ||
labs: true, | ||
}, | ||
], | ||
|
||
pageForSymbol(node): string { | ||
|
@@ -139,6 +174,10 @@ export const lit2Config: ApiDocsConfig = { | |
return 'decorators'; | ||
} | ||
|
||
if (entrypoint.includes('/context/')) { | ||
return 'context'; | ||
} | ||
|
||
if ( | ||
entrypoint.endsWith('/directive.ts') || | ||
entrypoint.endsWith('/directive-helpers.ts') || | ||
|
@@ -225,6 +264,14 @@ export const lit2Config: ApiDocsConfig = { | |
// fine in practice, but when we add e.g. @lit/localize we'll need to be | ||
// smarter here. | ||
let [_, pkg, pathMinusExtension] = match; | ||
|
||
if (pkg === 'labs/context') { | ||
console.log(pkg, pathMinusExtension); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
// There are no @lit-labs/context path extensions because everything is | ||
// re-exported from root. | ||
return '@lit-labs/context'; | ||
} | ||
|
||
// TODO(aomarks) This wrongly assumes index.ts is always the package main. | ||
return pathMinusExtension === 'index' | ||
? pkg | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import * as fs from 'fs/promises'; | |
import * as pathlib from 'path'; | ||
import {execFile} from 'child_process'; | ||
import {promisify} from 'util'; | ||
import {ApiDocsTransformer} from './transformer.js'; | ||
import {ApiDocsTransformer, Pages, SymbolMap} from './transformer.js'; | ||
import {lit2Config} from './configs/lit-2.js'; | ||
|
||
import type {ApiDocsConfig} from './types.js'; | ||
|
@@ -89,37 +89,42 @@ const analyze = async (config: ApiDocsConfig) => { | |
} | ||
|
||
console.log(`Analyzing ${config.gitDir}`); | ||
const app = new typedoc.Application(); | ||
app.options.addReader(new typedoc.TSConfigReader()); | ||
app.bootstrap({ | ||
tsconfig: config.tsConfigPath, | ||
entryPoints: config.entrypointModules, | ||
entryPointStrategy: typedoc.EntryPointStrategy.Expand, | ||
}); | ||
const root = app.convert(); | ||
if (!root) { | ||
throw new Error('TypeDoc.Application.convert() returned undefined'); | ||
} | ||
const allPages: Pages = []; | ||
const allSymbols: SymbolMap = {}; | ||
for (const pkg of config.packages) { | ||
const app = new typedoc.Application(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point I thought I read some docs that typedoc had options for a monorepo, so you didn't need to make a new app for each package. I can't remember it though. This might matter for getting crosslinks between packages. Right now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - I need to investigate this further. I feel like I read that somewhere as well. |
||
app.options.addReader(new typedoc.TSConfigReader()); | ||
app.bootstrap({ | ||
tsconfig: pkg.tsConfigPath, | ||
entryPoints: pkg.entrypointModules, | ||
}); | ||
const root = app.convert(); | ||
if (!root) { | ||
throw new Error('TypeDoc.Application.convert() returned undefined'); | ||
} | ||
|
||
const json = await app.serializer.projectToObject( | ||
root, | ||
pathlib.resolve(config.tsConfigPath, '..') | ||
); | ||
const transformer = new ApiDocsTransformer(json, config); | ||
const {pages, symbolMap} = await transformer.transform(); | ||
const json = app.serializer.projectToObject( | ||
root, | ||
pathlib.resolve(pkg.tsConfigPath, '..') | ||
); | ||
const transformer = new ApiDocsTransformer(json, config); | ||
const {pages, symbolMap} = await transformer.transform(); | ||
allPages.push(...pages); | ||
Object.assign(allSymbols, symbolMap); | ||
} | ||
|
||
await fs.mkdir(pathlib.dirname(config.pagesOutPath), {recursive: true}); | ||
await fs.writeFile( | ||
config.pagesOutPath, | ||
JSON.stringify(pages, null, 2), | ||
JSON.stringify(allPages, null, 2), | ||
'utf8' | ||
); | ||
console.log(`Wrote ${config.pagesOutPath}`); | ||
|
||
await fs.mkdir(pathlib.dirname(config.symbolsOutPath), {recursive: true}); | ||
await fs.writeFile( | ||
config.symbolsOutPath, | ||
JSON.stringify(symbolMap, null, 2), | ||
JSON.stringify(allSymbols, null, 2), | ||
'utf8' | ||
); | ||
console.log(`Wrote ${config.symbolsOutPath}`); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these other files as entrypoint modules? Since we want everything importing from index, can typedoc not just find them in the module graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree - I have to investigate this now that I have stabilized updating all the underlying stuff & fixed many other confounding issues.
Previously when I only used the entrypoint we only got a small cross section of APIs generated. See https://pr1092-ec9e4af---lit-dev-5ftespv5na-uc.a.run.app/docs/api/context/ as an example.
But many things have been fixed since then & I understand what is going on better now. Will try this again to clean it up.
Great comment!