@patternfly/documentation-framework 2.0.0-alpha.7 → 2.0.0-alpha.70
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/CHANGELOG.md +582 -0
- package/README.md +1 -1
- package/app.js +20 -14
- package/components/autoLinkHeader/autoLinkHeader.css +2 -2
- package/components/autoLinkHeader/autoLinkHeader.js +18 -13
- package/components/cssVariables/cssSearch.js +3 -4
- package/components/cssVariables/cssVariables.css +4 -4
- package/components/cssVariables/cssVariables.js +83 -84
- package/components/example/example.css +29 -29
- package/components/example/example.js +34 -6
- package/components/footer/footer.css +16 -16
- package/components/footer/footer.js +16 -16
- package/components/functionsTable/functionsTable.js +57 -0
- package/components/gdprBanner/gdprBanner.css +2 -2
- package/components/gdprBanner/gdprBanner.js +3 -3
- package/components/inlineAlert/inlineAlert.js +1 -1
- package/components/link/link.js +1 -2
- package/components/propsTable/propsTable.js +85 -79
- package/components/sectionGallery/TextSummary.js +31 -0
- package/components/sectionGallery/sectionDataListLayout.js +51 -0
- package/components/sectionGallery/sectionGallery.css +53 -0
- package/components/sectionGallery/sectionGallery.js +76 -0
- package/components/sectionGallery/sectionGalleryLayout.js +41 -0
- package/components/sectionGallery/sectionGalleryToolbar.js +38 -0
- package/components/sectionGallery/sectionGalleryWrapper.js +110 -0
- package/components/sideNav/sideNav.css +12 -12
- package/components/sideNav/sideNav.js +44 -16
- package/components/tableOfContents/tableOfContents.css +17 -17
- package/helpers/codesandbox.js +3 -5
- package/helpers/getTitle.js +2 -2
- package/layouts/sideNavLayout/sideNavLayout.css +7 -11
- package/layouts/sideNavLayout/sideNavLayout.js +59 -45
- package/package.json +28 -25
- package/pages/404/404.css +2 -2
- package/pages/404/index.js +1 -1
- package/pages/global-css-variables.md +16 -16
- package/routes.js +20 -10
- package/scripts/cli/build.js +6 -1
- package/scripts/cli/cli.js +3 -1
- package/scripts/cli/generate.js +2 -2
- package/scripts/cli/start.js +6 -8
- package/scripts/md/parseMD.js +46 -11
- package/scripts/md/styled-tags.js +8 -4
- package/scripts/tsDocgen.js +119 -91
- package/scripts/typeDocGen.js +209 -0
- package/scripts/webpack/getHtmlWebpackPlugins.js +1 -2
- package/scripts/webpack/prerender.js +1 -2
- package/scripts/webpack/webpack.base.config.js +35 -35
- package/scripts/webpack/webpack.client.config.js +11 -8
- package/scripts/webpack/webpack.server.config.js +8 -5
- package/scripts/writeScreenshots.js +3 -3
- package/templates/html.ejs +2 -4
- package/templates/mdx.css +156 -161
- package/templates/mdx.js +122 -51
- package/templates/patternfly-docs/content/extensions/extension/design-guidelines/design-guidelines.md +2 -0
- package/templates/patternfly-docs/content/extensions/extension/examples/basic.md +2 -0
- package/templates/sitemap.ejs +1 -1
- package/versions.json +29 -9
- package/components/topNav/topNav.css +0 -30
- package/pages/red-hat-font.md +0 -40
package/scripts/md/parseMD.js
CHANGED
|
@@ -12,10 +12,12 @@ const { typecheck } = require('./typecheck');
|
|
|
12
12
|
const { makeSlug } = require('../../helpers/slugger');
|
|
13
13
|
const { liveCodeTypes } = require('../../helpers/liveCodeTypes');
|
|
14
14
|
const { tsDocgen } = require('../tsDocgen');
|
|
15
|
+
const { getPackageFunctionDocumentation } = require("../typeDocGen");
|
|
15
16
|
|
|
16
17
|
let exitCode = 0;
|
|
17
18
|
const outputBase = path.join(process.cwd(), `patternfly-docs/generated`);
|
|
18
19
|
const tsDocs = {};
|
|
20
|
+
let functionDocs = {};
|
|
19
21
|
const routes = {};
|
|
20
22
|
const globs = {
|
|
21
23
|
props: [],
|
|
@@ -75,6 +77,24 @@ function toReactComponent(mdFilePath, source, buildMode) {
|
|
|
75
77
|
return acc;
|
|
76
78
|
}, []);
|
|
77
79
|
|
|
80
|
+
const functionDocumentation = Object.keys(
|
|
81
|
+
frontmatter.functions || {}
|
|
82
|
+
).reduce((acc, fileName) => {
|
|
83
|
+
const functionNames = frontmatter.functions[fileName];
|
|
84
|
+
|
|
85
|
+
functionNames.forEach((functionName) => {
|
|
86
|
+
if (functionDocs[fileName] && functionDocs[fileName][functionName]) {
|
|
87
|
+
const functionDescriptionWithName = { functionName, ...functionDocs[fileName][functionName]}
|
|
88
|
+
acc.push(functionDescriptionWithName);
|
|
89
|
+
} else {
|
|
90
|
+
file.message(
|
|
91
|
+
`function documentation for ${functionName} is missing from function docs generation`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return acc;
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
78
98
|
const normalizedPath = relPath
|
|
79
99
|
.replace('node_modules/@patternfly/patternfly/docs', 'src/patternfly')
|
|
80
100
|
.replace(/node_modules\/@patternfly\/react-([\w-])/, (_, match) => `packages/react-${match}`)
|
|
@@ -84,7 +104,12 @@ function toReactComponent(mdFilePath, source, buildMode) {
|
|
|
84
104
|
id: frontmatter.id,
|
|
85
105
|
section: frontmatter.section || '',
|
|
86
106
|
subsection: frontmatter.subsection || '',
|
|
107
|
+
deprecated: frontmatter.deprecated || false,
|
|
108
|
+
beta: frontmatter.beta || false,
|
|
109
|
+
demo: frontmatter.demo || false,
|
|
110
|
+
newImplementationLink: frontmatter.newImplementationLink || false,
|
|
87
111
|
source,
|
|
112
|
+
tabName: frontmatter.tabName || null,
|
|
88
113
|
slug,
|
|
89
114
|
sourceLink: frontmatter.sourceLink || `https://github.com/patternfly/${
|
|
90
115
|
sourceRepo}/blob/main/${
|
|
@@ -106,26 +131,26 @@ function toReactComponent(mdFilePath, source, buildMode) {
|
|
|
106
131
|
if (propComponents.length > 0) {
|
|
107
132
|
pageData.propComponents = propComponents;
|
|
108
133
|
}
|
|
134
|
+
if (functionDocumentation.length > 0) {
|
|
135
|
+
pageData.functionDocumentation = functionDocumentation;
|
|
136
|
+
}
|
|
109
137
|
if (frontmatter.optIn) {
|
|
110
138
|
pageData.optIn = frontmatter.optIn;
|
|
111
139
|
}
|
|
112
|
-
if (frontmatter.beta) {
|
|
113
|
-
pageData.beta = frontmatter.beta;
|
|
114
|
-
}
|
|
115
140
|
if (frontmatter.cssPrefix) {
|
|
116
141
|
pageData.cssPrefix = Array.isArray(frontmatter.cssPrefix)
|
|
117
142
|
? frontmatter.cssPrefix
|
|
118
143
|
: [frontmatter.cssPrefix];
|
|
119
144
|
}
|
|
120
|
-
if (frontmatter.katacodaBroken) {
|
|
121
|
-
pageData.katacodaBroken = frontmatter.katacodaBroken;
|
|
122
|
-
}
|
|
123
|
-
if (frontmatter.katacodaLayout) {
|
|
124
|
-
pageData.katacodaLayout = frontmatter.katacodaLayout;
|
|
125
|
-
}
|
|
126
145
|
if (frontmatter.hideNavItem) {
|
|
127
146
|
pageData.hideNavItem = frontmatter.hideNavItem;
|
|
128
147
|
}
|
|
148
|
+
if (frontmatter.sortValue) {
|
|
149
|
+
pageData.sortValue = frontmatter.sortValue;
|
|
150
|
+
}
|
|
151
|
+
if (frontmatter.subsectionSortValue) {
|
|
152
|
+
pageData.subsectionSortValue = frontmatter.subsectionSortValue;
|
|
153
|
+
}
|
|
129
154
|
})
|
|
130
155
|
// Delete HTML comments
|
|
131
156
|
.use(require('./remove-comments'))
|
|
@@ -266,12 +291,21 @@ function sourceMDFile(file, source, buildMode) {
|
|
|
266
291
|
section: pageData.section,
|
|
267
292
|
subsection: pageData.subsection,
|
|
268
293
|
source: pageData.source,
|
|
269
|
-
|
|
270
|
-
...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem })
|
|
294
|
+
tabName: pageData.tabName,
|
|
295
|
+
...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem }),
|
|
296
|
+
...(pageData.beta && { beta: pageData.beta }),
|
|
297
|
+
...(pageData.deprecated && { deprecated: pageData.deprecated }),
|
|
298
|
+
...(pageData.demo && { demo: pageData.demo }),
|
|
299
|
+
...(pageData.sortValue && { sortValue: pageData.sortValue }),
|
|
300
|
+
...(pageData.subsectionSortValue && { subsectionSortValue: pageData.subsectionSortValue })
|
|
271
301
|
};
|
|
272
302
|
}
|
|
273
303
|
}
|
|
274
304
|
|
|
305
|
+
function sourceFunctionDocs(packageName) {
|
|
306
|
+
functionDocs = getPackageFunctionDocumentation(packageName);
|
|
307
|
+
}
|
|
308
|
+
|
|
275
309
|
function writeIndex() {
|
|
276
310
|
const stringifyRoute = ([route, pageData]) => `'${route}': {\n ${Object.entries(pageData)
|
|
277
311
|
.map(([key, val]) => `${key}: ${JSON.stringify(val)}`)
|
|
@@ -310,6 +344,7 @@ module.exports = {
|
|
|
310
344
|
globs.md.push({ glob, source, ignore });
|
|
311
345
|
sync(glob, { ignore }).forEach(file => sourceMDFile(file, source, buildMode));
|
|
312
346
|
},
|
|
347
|
+
sourceFunctionDocs,
|
|
313
348
|
writeIndex,
|
|
314
349
|
watchMD() {
|
|
315
350
|
globs.props.forEach(({ glob, ignore }) => {
|
|
@@ -24,22 +24,23 @@ function styledTags() {
|
|
|
24
24
|
node.properties.className = node.properties.className || '';
|
|
25
25
|
node.properties.className += node.properties.className ? ' ' : '';
|
|
26
26
|
node.properties.className += `ws-${node.tagName}`;
|
|
27
|
-
// Match pf-c-table implementation
|
|
27
|
+
// Match pf-v5-c-table implementation
|
|
28
28
|
// https://pf4.patternfly.org/components/table/html/basic-table/
|
|
29
29
|
if (node.tagName === 'table') {
|
|
30
|
-
node.properties.className += ' pf-c-table pf-m-grid-lg pf-m-compact';
|
|
30
|
+
node.properties.className += ' pf-v5-c-table pf-m-grid-lg pf-m-compact';
|
|
31
31
|
node.properties.role = 'grid';
|
|
32
32
|
let columnHeaders = [];
|
|
33
33
|
for (let child of node.children) {
|
|
34
34
|
if (child.tagName === 'thead') {
|
|
35
|
+
child.properties.className = 'pf-v5-c-table__thead';
|
|
35
36
|
// Find column headers
|
|
36
37
|
const tr = child.children.find(child => child.tagName === 'tr');
|
|
37
38
|
tr.properties.role = 'row';
|
|
39
|
+
tr.properties.className = 'pf-v5-c-table__tr';
|
|
38
40
|
tr.children
|
|
39
41
|
.filter(child => child.tagName === 'th')
|
|
40
42
|
.forEach(th => {
|
|
41
|
-
th.properties.className = th.properties.className
|
|
42
|
-
th.properties.className += ' pf-m-wrap';
|
|
43
|
+
th.properties.className = `${th.properties.className} pf-v5-c-table__th pf-m-wrap`;
|
|
43
44
|
th.properties.role = 'columnheader';
|
|
44
45
|
th.properties.scope = 'col';
|
|
45
46
|
let colName = '';
|
|
@@ -56,14 +57,17 @@ function styledTags() {
|
|
|
56
57
|
}
|
|
57
58
|
else if (child.tagName === 'tbody') {
|
|
58
59
|
child.properties.role = 'rowgroup';
|
|
60
|
+
child.properties.className = 'pf-v5-c-table__tbody';
|
|
59
61
|
child.children
|
|
60
62
|
.filter(tr => tr.tagName === 'tr')
|
|
61
63
|
.forEach(tr => {
|
|
62
64
|
tr.properties.role = 'row';
|
|
65
|
+
tr.properties.className = 'pf-v5-c-table__tr';
|
|
63
66
|
tr.children
|
|
64
67
|
.filter(td => td.tagName === 'td')
|
|
65
68
|
.forEach((td, i) => {
|
|
66
69
|
td.properties.role = 'cell';
|
|
70
|
+
td.properties.className = 'pf-v5-c-table__td';
|
|
67
71
|
if (columnHeaders[i]) {
|
|
68
72
|
td.properties['data-label'] = columnHeaders[i];
|
|
69
73
|
}
|
package/scripts/tsDocgen.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const reactDocgen = require(
|
|
3
|
-
const ts = require(
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const reactDocgen = require("react-docgen");
|
|
3
|
+
const ts = require("typescript");
|
|
4
4
|
|
|
5
5
|
const annotations = [
|
|
6
6
|
{
|
|
7
7
|
regex: /@deprecated/,
|
|
8
|
-
name:
|
|
9
|
-
type:
|
|
8
|
+
name: "deprecated",
|
|
9
|
+
type: "Boolean",
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
regex: /@hide/,
|
|
13
|
-
name:
|
|
14
|
-
type:
|
|
13
|
+
name: "hide",
|
|
14
|
+
type: "Boolean",
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
regex: /@beta/,
|
|
18
|
-
name:
|
|
19
|
-
type:
|
|
18
|
+
name: "beta",
|
|
19
|
+
type: "Boolean",
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
regex: /@propType\s+(.*)/,
|
|
23
|
-
name:
|
|
24
|
-
type:
|
|
25
|
-
}
|
|
23
|
+
name: "type",
|
|
24
|
+
type: "String",
|
|
25
|
+
},
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
function addAnnotations(prop) {
|
|
@@ -30,12 +30,12 @@ function addAnnotations(prop) {
|
|
|
30
30
|
annotations.forEach(({ regex, name }) => {
|
|
31
31
|
const match = prop.description.match(regex);
|
|
32
32
|
if (match) {
|
|
33
|
-
prop.description = prop.description.replace(regex,
|
|
33
|
+
prop.description = prop.description.replace(regex, "").trim();
|
|
34
34
|
if (name) {
|
|
35
35
|
prop[name] = match[2] || match[1] || true;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
})
|
|
38
|
+
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return prop;
|
|
@@ -55,74 +55,101 @@ function getComponentMetadata(filename, sourceText) {
|
|
|
55
55
|
// console.warn(`No component found in ${filename}:`, err);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
return (parsedComponents || []).filter(
|
|
58
|
+
return (parsedComponents || []).filter(
|
|
59
|
+
(parsed) => parsed && parsed.displayName
|
|
60
|
+
);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
const getNodeText = (node, sourceText) => {
|
|
64
|
+
if (!node || !node.pos || !node.end) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return sourceText.substring(node.pos, node.end).trim();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const buildJsDocProps = (nodes, sourceText) =>
|
|
72
|
+
nodes?.reduce((acc, member) => {
|
|
73
|
+
const name =
|
|
74
|
+
(member.name && member.name.escapedText) ||
|
|
75
|
+
(member.parameters &&
|
|
76
|
+
`[${getNodeText(member.parameters[0], sourceText)}]`) ||
|
|
77
|
+
"Unknown";
|
|
78
|
+
acc[name] = {
|
|
79
|
+
description: member.jsDoc
|
|
80
|
+
? member.jsDoc.map((doc) => doc.comment).join("\n")
|
|
81
|
+
: null,
|
|
82
|
+
required: member.questionToken === undefined,
|
|
83
|
+
type: {
|
|
84
|
+
raw: getNodeText(member.type, sourceText).trim(),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
return acc;
|
|
88
|
+
}, {});
|
|
89
|
+
|
|
90
|
+
const getSourceFileStatements = (filename, sourceText) => {
|
|
91
|
+
const { statements } = ts.createSourceFile(
|
|
63
92
|
filename,
|
|
64
93
|
sourceText,
|
|
65
94
|
ts.ScriptTarget.Latest // languageVersion
|
|
66
95
|
);
|
|
67
|
-
|
|
68
|
-
function getText(node) {
|
|
69
|
-
if (!node || !node.pos || !node.end) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
return sourceText.substring(node.pos, node.end).trim();
|
|
73
|
-
}
|
|
74
96
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
return statements;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const getInterfaceMetadata = (filename, sourceText) =>
|
|
101
|
+
getSourceFileStatements(filename, sourceText).reduce(
|
|
102
|
+
(metaDataAcc, statement) => {
|
|
103
|
+
if (statement.kind === ts.SyntaxKind.InterfaceDeclaration) {
|
|
104
|
+
metaDataAcc.push({
|
|
105
|
+
displayName: statement.name.escapedText,
|
|
106
|
+
description: statement.jsDoc?.map((doc) => doc.comment).join("\n"),
|
|
107
|
+
props: buildJsDocProps(statement.members, sourceText),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return metaDataAcc;
|
|
112
|
+
},
|
|
113
|
+
[]
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const getTypeAliasMetadata = (filename, sourceText) =>
|
|
117
|
+
getSourceFileStatements(filename, sourceText).reduce(
|
|
118
|
+
(metaDataAcc, statement) => {
|
|
119
|
+
if (statement.kind === ts.SyntaxKind.TypeAliasDeclaration) {
|
|
120
|
+
const props = statement.type.types?.reduce((propAcc, type) => {
|
|
121
|
+
if (type.members) {
|
|
122
|
+
propAcc.push(buildJsDocProps(type.members, sourceText));
|
|
91
123
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
124
|
+
|
|
125
|
+
return propAcc;
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
metaDataAcc.push({
|
|
129
|
+
props,
|
|
130
|
+
displayName: statement.name.escapedText,
|
|
131
|
+
description: statement.jsDoc?.map((doc) => doc.comment).join("\n"),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return metaDataAcc;
|
|
136
|
+
},
|
|
137
|
+
[]
|
|
138
|
+
);
|
|
106
139
|
|
|
107
140
|
function normalizeProp([
|
|
108
141
|
name,
|
|
109
|
-
{
|
|
110
|
-
required,
|
|
111
|
-
annotatedType,
|
|
112
|
-
type,
|
|
113
|
-
tsType,
|
|
114
|
-
description,
|
|
115
|
-
defaultValue
|
|
116
|
-
}
|
|
142
|
+
{ required, annotatedType, type, tsType, description, defaultValue },
|
|
117
143
|
]) {
|
|
118
144
|
const res = {
|
|
119
145
|
name,
|
|
120
|
-
type:
|
|
121
|
-
||
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
||
|
|
125
|
-
|
|
146
|
+
type:
|
|
147
|
+
annotatedType ||
|
|
148
|
+
(type && type.name) ||
|
|
149
|
+
(type && (type.raw || type.name)) ||
|
|
150
|
+
(tsType && (tsType.raw || tsType.name)) ||
|
|
151
|
+
"No type info",
|
|
152
|
+
description,
|
|
126
153
|
};
|
|
127
154
|
if (required) {
|
|
128
155
|
res.required = true;
|
|
@@ -134,45 +161,46 @@ function normalizeProp([
|
|
|
134
161
|
return res;
|
|
135
162
|
}
|
|
136
163
|
|
|
137
|
-
function getDescription(parsed, ) {
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
164
|
function tsDocgen(file) {
|
|
142
|
-
const sourceText = fs.readFileSync(file,
|
|
165
|
+
const sourceText = fs.readFileSync(file, "utf8");
|
|
143
166
|
const componentMeta = getComponentMetadata(file, sourceText); // Array of components with props
|
|
144
167
|
const interfaceMeta = getInterfaceMetadata(file, sourceText); // Array of interfaces with props
|
|
145
|
-
const
|
|
146
|
-
|
|
168
|
+
const typeAliasMeta = getTypeAliasMetadata(file, sourceText); // Array of type aliases with props
|
|
169
|
+
const propsMetaMap = [...interfaceMeta, ...typeAliasMeta].reduce(function (
|
|
170
|
+
target,
|
|
171
|
+
interfaceOrTypeAlias
|
|
172
|
+
) {
|
|
173
|
+
target[interfaceOrTypeAlias.displayName] = interfaceOrTypeAlias;
|
|
147
174
|
return target;
|
|
148
|
-
},
|
|
175
|
+
},
|
|
176
|
+
{});
|
|
149
177
|
|
|
150
|
-
// Go through each component and check if they have an interface with a jsDoc description
|
|
178
|
+
// Go through each component and check if they have an interface or type alias with a jsDoc description
|
|
151
179
|
// If so copy it over (fix for https://github.com/patternfly/patternfly-react/issues/7612)
|
|
152
|
-
componentMeta.forEach(c => {
|
|
180
|
+
componentMeta.forEach((c) => {
|
|
153
181
|
if (c.description) {
|
|
154
182
|
return c;
|
|
155
183
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
184
|
+
|
|
185
|
+
const propsName = `${c.displayName}Props`;
|
|
186
|
+
if (propsMetaMap[propsName]?.description) {
|
|
187
|
+
c.description = propsMetaMap[propsName].description;
|
|
159
188
|
}
|
|
160
|
-
})
|
|
189
|
+
});
|
|
161
190
|
|
|
162
|
-
return componentMeta
|
|
163
|
-
|
|
164
|
-
.map(parsed => ({
|
|
191
|
+
return [...componentMeta, ...interfaceMeta, ...typeAliasMeta].map(
|
|
192
|
+
(parsed) => ({
|
|
165
193
|
name: parsed.displayName,
|
|
166
|
-
description: parsed.description ||
|
|
194
|
+
description: parsed.description || "",
|
|
167
195
|
props: Object.entries(parsed.props || {})
|
|
168
196
|
.map(normalizeProp)
|
|
169
197
|
.map(addAnnotations)
|
|
170
|
-
.filter(prop => !prop.hide)
|
|
171
|
-
.sort((p1, p2) => p1.name.localeCompare(p2.name))
|
|
172
|
-
})
|
|
198
|
+
.filter((prop) => !prop.hide)
|
|
199
|
+
.sort((p1, p2) => p1.name.localeCompare(p2.name)),
|
|
200
|
+
})
|
|
201
|
+
);
|
|
173
202
|
}
|
|
174
203
|
|
|
175
204
|
module.exports = {
|
|
176
|
-
tsDocgen
|
|
205
|
+
tsDocgen,
|
|
177
206
|
};
|
|
178
|
-
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
const TypeDoc = require("typedoc");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
/** Compiles variable types if a type is generic. */
|
|
5
|
+
function getVariableType(typeArguments) {
|
|
6
|
+
if (!typeArguments || typeArguments.length === 0) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const typeArgs = typeArguments.map((type) => getType(type));
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
typeArgs.reduce((acc, type) => acc + type + ", ", "<").slice(0, -2) + ">"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** compiles key/value pairs of a Type or Interface. */
|
|
18
|
+
function getPropertyTypes(properties) {
|
|
19
|
+
const formattedProperties = properties.reduce((acc, property) => {
|
|
20
|
+
const { flags, name, type } = property;
|
|
21
|
+
const formattedName = flags.isOptional ? name + "?" : name;
|
|
22
|
+
return `${acc}${formattedName}: ${getType(type)}; `;
|
|
23
|
+
}, "");
|
|
24
|
+
|
|
25
|
+
return `{ ${formattedProperties} }`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Compiles the subtypes of a tuple. */
|
|
29
|
+
function getTupleTypes(tupleElements) {
|
|
30
|
+
const [firstType, secondType] = tupleElements.map((element) =>
|
|
31
|
+
getType(element)
|
|
32
|
+
);
|
|
33
|
+
return `[${firstType}, ${secondType}]`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Compiles the different subtypes of a union or intersection. */
|
|
37
|
+
function getJoinedTypes(types, joinChar) {
|
|
38
|
+
const joinedTypes = types.map((type) => getType(type));
|
|
39
|
+
return joinedTypes
|
|
40
|
+
.reduce((acc, type) => `${acc} ${joinChar} ${type}`, "")
|
|
41
|
+
.slice(2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Return the type of a reflection.
|
|
45
|
+
* For anything that has, or can have, multiple subtypes (i.e. variable types in a generic, properties in an interface,
|
|
46
|
+
* several types in a union, callbacks, etc.) it will recursively navigate the parsed type info as needed to resolve
|
|
47
|
+
* all relevant subtypes.
|
|
48
|
+
*/
|
|
49
|
+
function getType(reflection) {
|
|
50
|
+
switch (reflection.type) {
|
|
51
|
+
case "intrinsic":
|
|
52
|
+
case "reference":
|
|
53
|
+
return reflection.name + getVariableType(reflection.typeArguments);
|
|
54
|
+
case "union":
|
|
55
|
+
return getJoinedTypes(reflection.types, "|");
|
|
56
|
+
case "reflection":
|
|
57
|
+
const { signatures, children } = reflection.declaration;
|
|
58
|
+
if (signatures) {
|
|
59
|
+
return getFunctionDocumentation(signatures[0]).type;
|
|
60
|
+
} else if (children) {
|
|
61
|
+
return getPropertyTypes(children);
|
|
62
|
+
} else {
|
|
63
|
+
return "Props";
|
|
64
|
+
}
|
|
65
|
+
case "array":
|
|
66
|
+
return reflection.elementType.name + "[]";
|
|
67
|
+
case "tuple":
|
|
68
|
+
return getTupleTypes(reflection.elements);
|
|
69
|
+
case "intersection":
|
|
70
|
+
return getJoinedTypes(reflection.types, "&");
|
|
71
|
+
case "literal":
|
|
72
|
+
return reflection.value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Compiles information about the parameters of a function.
|
|
77
|
+
* Includes the name, default value, type, and whether it is optional.
|
|
78
|
+
*/
|
|
79
|
+
function getParamInfo(parameters = []) {
|
|
80
|
+
return parameters.map((parameter) => {
|
|
81
|
+
const { name, defaultValue, type, flags } = parameter;
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
default: defaultValue,
|
|
85
|
+
type: getType(type),
|
|
86
|
+
optional: flags.isOptional,
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Formats call signature for a function. */
|
|
92
|
+
function formatFunctionType(parameters, returnType) {
|
|
93
|
+
const annotatedParams = parameters.map((parameter) => {
|
|
94
|
+
const { name, type, optional } = parameter;
|
|
95
|
+
|
|
96
|
+
return [optional ? name + "?" : name, type];
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const formattedParams = annotatedParams
|
|
100
|
+
.reduce((acc, param) => `${acc}, ${param[0]}: ${param[1]}`, "")
|
|
101
|
+
.slice(2);
|
|
102
|
+
|
|
103
|
+
return `(${formattedParams}) => ${returnType}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Primary entry point for gathering type information from a typedoc function reflection. */
|
|
107
|
+
function getFunctionDocumentation(callSignatureReflection) {
|
|
108
|
+
const { type, parameters, comment } = callSignatureReflection;
|
|
109
|
+
const params = getParamInfo(parameters);
|
|
110
|
+
|
|
111
|
+
const returnType = type?.name || getType(type);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
params,
|
|
115
|
+
returnType,
|
|
116
|
+
type: formatFunctionType(params, returnType),
|
|
117
|
+
description: comment?.shortText,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Parses the source for a package using TypeDoc. */
|
|
122
|
+
function typeDocGen(entryPoint, tsconfigLocation) {
|
|
123
|
+
const app = new TypeDoc.Application();
|
|
124
|
+
app.options.addReader(new TypeDoc.TSConfigReader());
|
|
125
|
+
app.bootstrap({
|
|
126
|
+
// typedoc options here
|
|
127
|
+
entryPointStrategy: "expand",
|
|
128
|
+
entryPoints: [entryPoint],
|
|
129
|
+
tsconfig: tsconfigLocation,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// this non-standard reflection creation allows us to ignore any type errors in a package
|
|
133
|
+
const project = app.converter.convert(app.getEntryPoints() ?? []);
|
|
134
|
+
|
|
135
|
+
// if something caused project conversion to fail log an error
|
|
136
|
+
if (project) {
|
|
137
|
+
return project;
|
|
138
|
+
} else {
|
|
139
|
+
console.error("Something went wrong during typedoc project conversion");
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Takes package information and returns an object with all tsdoc standard format info about the functions in it.
|
|
145
|
+
*
|
|
146
|
+
* The object has file names as keys, with values being an additional object which has the function names in that file
|
|
147
|
+
* as keys and the information about that function as the value, also in object form.
|
|
148
|
+
* Information includes the name of the file in which it's defined, the parameters, description, default values and
|
|
149
|
+
* type information.
|
|
150
|
+
*
|
|
151
|
+
* Example structure:
|
|
152
|
+
* {
|
|
153
|
+
* "components/component.tsx": {
|
|
154
|
+
* "boolToString": {
|
|
155
|
+
* "description": "Converts a boolean to a string",
|
|
156
|
+
* "params": [
|
|
157
|
+
* {
|
|
158
|
+
* "default": false,
|
|
159
|
+
* "name": "booleanValue",
|
|
160
|
+
* "optional": true,
|
|
161
|
+
* "type": "boolean",
|
|
162
|
+
* },
|
|
163
|
+
* ],
|
|
164
|
+
* "returnType": "string",
|
|
165
|
+
* "type": "(booleanValue?: boolean) => string",
|
|
166
|
+
* },
|
|
167
|
+
* },
|
|
168
|
+
* }
|
|
169
|
+
*/
|
|
170
|
+
function getPackageFunctionDocumentation(
|
|
171
|
+
packageName,
|
|
172
|
+
pathToRoot = "dist/js/index.js",
|
|
173
|
+
srcPath = "src",
|
|
174
|
+
tsconfigPath = "tsconfig.json"
|
|
175
|
+
) {
|
|
176
|
+
const packageRoot = require.resolve(packageName).replace(pathToRoot, "");
|
|
177
|
+
const entry = path.relative(process.cwd(), path.join(packageRoot, srcPath));
|
|
178
|
+
const configLocation = path.relative(
|
|
179
|
+
process.cwd(),
|
|
180
|
+
path.join(packageRoot, tsconfigPath)
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const packageReflection = typeDocGen(entry, configLocation);
|
|
184
|
+
|
|
185
|
+
// 64 corresponds with functions, see all reflection kinds here: https://typedoc.org/api/enums/Models.ReflectionKind-1.html
|
|
186
|
+
const functionReflections = packageReflection.getReflectionsByKind(64);
|
|
187
|
+
|
|
188
|
+
const functionsMap = functionReflections.reduce((acc, functionReflection) => {
|
|
189
|
+
const { name, sources, signatures } = functionReflection;
|
|
190
|
+
|
|
191
|
+
const sourceFile = sources[0].fileName;
|
|
192
|
+
const shortSourceFile = sourceFile.replace(
|
|
193
|
+
`${packageName}/${srcPath}/`,
|
|
194
|
+
""
|
|
195
|
+
);
|
|
196
|
+
const obj = getFunctionDocumentation(signatures[0]);
|
|
197
|
+
|
|
198
|
+
if (acc[shortSourceFile]) {
|
|
199
|
+
acc[shortSourceFile] = { ...acc[shortSourceFile], [name]: obj };
|
|
200
|
+
} else {
|
|
201
|
+
acc[shortSourceFile] = { [name]: obj };
|
|
202
|
+
}
|
|
203
|
+
return acc;
|
|
204
|
+
}, {});
|
|
205
|
+
|
|
206
|
+
return functionsMap;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
module.exports = { getPackageFunctionDocumentation };
|
|
@@ -9,7 +9,6 @@ async function getHtmlWebpackPlugin({
|
|
|
9
9
|
isProd,
|
|
10
10
|
googleAnalyticsID,
|
|
11
11
|
algolia,
|
|
12
|
-
pathPrefix = '',
|
|
13
12
|
url,
|
|
14
13
|
title,
|
|
15
14
|
isFullscreen
|
|
@@ -20,7 +19,7 @@ async function getHtmlWebpackPlugin({
|
|
|
20
19
|
templateParameters: {
|
|
21
20
|
title: getTitle(title),
|
|
22
21
|
// Don't prerender fullscreen pages (expensive!)
|
|
23
|
-
prerendering: (isProd && !isFullscreen && !url.includes('topology') && !url.includes('extensions')) ? await prerender(url
|
|
22
|
+
prerendering: (isProd && !isFullscreen && !url.includes('topology') && !url.includes('extensions')) ? await prerender(url) : null,
|
|
24
23
|
// Don't use GA in dev mode
|
|
25
24
|
googleAnalyticsID: isProd ? googleAnalyticsID : false,
|
|
26
25
|
algolia
|
|
@@ -8,8 +8,7 @@ const ssrPrepass = require('react-ssr-prepass');
|
|
|
8
8
|
|
|
9
9
|
// This function is effectively synchronous because it mutates global.setTimeout
|
|
10
10
|
// Only allow one copy at a time to run
|
|
11
|
-
async function prerender(url
|
|
12
|
-
url = `${pathPrefix}${url}`;
|
|
11
|
+
async function prerender(url) {
|
|
13
12
|
const location = { pathname: url };
|
|
14
13
|
// For @reach/router
|
|
15
14
|
global.history = {};
|