-
Notifications
You must be signed in to change notification settings - Fork 186
/
lit-2.ts
233 lines (213 loc) · 6.15 KB
/
lit-2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import * as pathlib from 'path';
import {ReflectionKind} from 'typedoc';
import type {ApiDocsConfig} from '../types.js';
const root = pathlib.resolve(__dirname, '..', '..', '..', '..', '..');
const dataDir = pathlib.join(root, 'packages', 'lit-dev-api', 'api-data');
const workDir = pathlib.join(dataDir, 'lit-2');
const gitDir = pathlib.join(workDir, 'repo');
const litDir = pathlib.join(gitDir, 'packages', 'lit');
const srcDir = pathlib.join(litDir, 'src');
/**
* lit.dev API docs configuration for Lit 2.x
*/
export const lit2Config: ApiDocsConfig = {
repo: 'lit/lit',
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'),
extraSetupCommands: [
{
cmd: 'npm',
args: ['run', 'build:ts'],
},
],
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'),
],
symbolOrder: ['LitElement', 'ReactiveElement'],
pages: [
{
slug: 'LitElement',
title: 'LitElement',
versionLinks: {
v1: 'api/lit-element/LitElement/',
},
},
{
slug: 'ReactiveElement',
title: 'ReactiveElement',
versionLinks: {
v1: 'api/lit-element/UpdatingElement/',
},
},
{
slug: 'templates',
title: 'Templates',
versionLinks: {
v1: 'api/lit-html/templates/',
},
},
{
slug: 'styles',
title: 'Styles',
versionLinks: {
v1: 'api/lit-element/styles/',
},
},
{
slug: 'decorators',
title: 'Decorators',
versionLinks: {
v1: 'api/lit-element/decorators/',
},
},
{
slug: 'directives',
title: 'Directives',
tocFilter: (node) => node.kind === ReflectionKind.Function,
versionLinks: {
v1: 'api/lit-html/directives/',
},
},
{
slug: 'custom-directives',
title: 'Custom directives',
versionLinks: {
v1: 'api/lit-html/custom-directives/',
},
},
{
slug: 'static-html',
title: 'Static HTML',
versionLinks: {
v1: 'api/lit-html/templates/',
},
},
{
slug: 'controllers',
title: 'Controllers',
versionLinks: {
v1: 'api/lit-element/LitElement/',
},
},
{
slug: 'misc',
title: 'Misc',
versionLinks: {
v1: 'api/lit-element/LitElement/',
},
},
],
pageForSymbol(node): string {
const entrypoint = node.entrypointSources?.[0]?.fileName ?? '';
if (entrypoint.includes('/directives/')) {
return 'directives';
}
if (entrypoint.endsWith('/decorators.ts')) {
return 'decorators';
}
if (
entrypoint.endsWith('/directive.ts') ||
entrypoint.endsWith('/directive-helpers.ts') ||
entrypoint.endsWith('/async-directive.ts') ||
node.name === 'noChange' ||
node.name === 'Part' ||
node.name === 'AttributePart' ||
node.name === 'BooleanAttributePart' ||
node.name === 'ChildPart' ||
node.name === 'ElementPart' ||
node.name === 'EventPart' ||
node.name === 'PropertyPart'
) {
return 'custom-directives';
}
if (entrypoint.endsWith('/static-html.ts')) {
return 'static-html';
}
if (node.name === 'LitElement' || node.name === 'RenderOptions') {
return 'LitElement';
}
if (
node.name === 'ReactiveElement' ||
node.name === 'PropertyDeclaration' ||
node.name === 'PropertyDeclarations' ||
node.name === 'UpdatingElement' ||
node.name === 'PropertyValues' ||
node.name === 'ComplexAttributeConverter'
) {
return 'ReactiveElement';
}
if (
node.name === 'html' ||
node.name === 'svg' ||
node.name === 'render' ||
node.name === 'nothing' ||
node.name === 'SanitizerFactory' ||
node.name === 'Template' ||
node.name === 'TemplateResult' ||
node.name === 'SVGTemplateResult'
) {
return 'templates';
}
if (
node.name === 'css' ||
node.name === 'adoptStyles' ||
node.name === 'getCompatibleStyle' ||
node.name === 'unsafeCSS' ||
node.name === 'supportsAdoptingStyleSheets' ||
node.name.startsWith('CSS')
) {
return 'styles';
}
if (
node.name === 'ReactiveController' ||
node.name === 'ReactiveControllerHost'
) {
return 'controllers';
}
// TODO(aomarks) Make sure everything has a good final location, and then
// throw if we get here.
return 'misc';
},
locationToUrl({page, anchor}) {
return `/docs/v2/api/${page}/#${anchor}`;
},
fileToImportSpecifier(filename) {
const match = filename.match(/^packages\/(.+?)\/src\/(.+)\.ts$/);
if (!match) {
return '';
}
// TODO(aomarks) This pkg is only our local directory name, which isn't
// necessarily our NPM package name (e.g. it's @lit/reactive-element, not
// reactive-element). Right now all our exports are from 'lit', so this is
// fine in practice, but when we add e.g. @lit/localize we'll need to be
// smarter here.
let [_, pkg, pathMinusExtension] = match;
// TODO(aomarks) This wrongly assumes index.ts is always the package main.
return pathMinusExtension === 'index'
? pkg
: `${pkg}/${pathMinusExtension}.js`;
},
};