|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | import path from "node:path"; |
4 | 4 |
|
5 | | -import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter"; |
| 5 | +import { documentTestUtils, writeComponentsDocumentation } from "@cloudscape-design/documenter"; |
6 | 6 |
|
7 | | -import { dashCase, listPublicDirs, writeSourceFile } from "./utils.js"; |
| 7 | +import { writeSourceFile } from "./utils.js"; |
8 | 8 |
|
9 | | -const publicDirs = listPublicDirs("src"); |
10 | 9 | const targetDir = "lib/components/internal/api-docs"; |
11 | 10 |
|
12 | 11 | componentDocs(); |
13 | 12 | testUtilDocs(); |
14 | 13 |
|
15 | | -function validatePublicFiles(definitionFiles) { |
16 | | - for (const publicDir of publicDirs) { |
17 | | - if (!definitionFiles.includes(publicDir)) { |
18 | | - throw new Error(`Directory src/${publicDir} does not have a corresponding API definition`); |
19 | | - } |
20 | | - } |
21 | | -} |
22 | | - |
23 | 14 | function componentDocs() { |
24 | | - const definitions = documentComponents({ |
| 15 | + writeComponentsDocumentation({ |
| 16 | + outDir: path.join(targetDir, "components"), |
25 | 17 | tsconfigPath: path.resolve("tsconfig.json"), |
26 | 18 | publicFilesGlob: "src/*/index.tsx", |
27 | 19 | }); |
28 | | - const outDir = path.join(targetDir, "components"); |
29 | | - const fileNames = definitions |
30 | | - .filter((definition) => { |
31 | | - const fileName = dashCase(definition.name); |
32 | | - if (!publicDirs.includes(fileName)) { |
33 | | - console.warn(`Excluded "${fileName}" from components definitions.`); |
34 | | - return false; |
35 | | - } |
36 | | - return true; |
37 | | - }) |
38 | | - .map((definition) => { |
39 | | - const fileName = dashCase(definition.name); |
40 | | - writeSourceFile(path.join(outDir, fileName + ".js"), `module.exports = ${JSON.stringify(definition, null, 2)};`); |
41 | | - return fileName; |
42 | | - }); |
43 | | - validatePublicFiles(fileNames); |
44 | | - const indexContent = `module.exports = { |
45 | | - ${fileNames.map((name) => `${JSON.stringify(name)}:require('./${name}')`).join(",\n")} |
46 | | - }`; |
47 | | - writeSourceFile(path.join(outDir, "index.js"), indexContent); |
48 | 20 | } |
49 | 21 |
|
50 | 22 | function testUtilDocs() { |
|
0 commit comments