Skip to content

Commit 8abde3a

Browse files
committed
chore: Migrate to the new documenter API
1 parent 5ef2c97 commit 8abde3a

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

scripts/docs.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,21 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import path from "node:path";
44

5-
import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter";
5+
import { documentTestUtils, writeComponentsDocumentation } from "@cloudscape-design/documenter";
66

7-
import { listPublicDirs, writeSourceFile } from "./utils.js";
7+
import { writeSourceFile } from "./utils.js";
88

9-
const publicDirs = listPublicDirs("src");
109
const targetDir = "lib/components/internal/api-docs";
1110

1211
componentDocs();
1312
testUtilDocs();
1413

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-
2314
function componentDocs() {
24-
const definitions = documentComponents({
15+
writeComponentsDocumentation({
16+
outDir: path.join(targetDir, "components"),
2517
tsconfigPath: path.resolve("tsconfig.json"),
2618
publicFilesGlob: "src/*/index.tsx",
2719
});
28-
const outDir = path.join(targetDir, "components");
29-
for (const definition of definitions) {
30-
writeSourceFile(
31-
path.join(outDir, definition.dashCaseName + ".js"),
32-
`module.exports = ${JSON.stringify(definition, null, 2)};`,
33-
);
34-
}
35-
const indexContent = `module.exports = {
36-
${definitions.map((definition) => `${JSON.stringify(definition.dashCaseName)}:require('./${definition.dashCaseName}')`).join(",\n")}
37-
}`;
38-
writeSourceFile(path.join(outDir, "index.js"), indexContent);
39-
validatePublicFiles(definitions.map((def) => def.dashCaseName));
4020
}
4121

4222
function testUtilDocs() {

src/__tests__/documenter.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { expect, test } from "vitest";
44

5-
// @ts-expect-error no types here
65
import apiDocs from "../../lib/components/internal/api-docs/components";
76

8-
test.each(Object.entries(apiDocs))("definition for $0 matches the snapshot", (name, definition) => {
7+
test.each(Object.entries(apiDocs))("definition for $0 matches the snapshot", (_name, definition) => {
98
expect(definition).toMatchSnapshot();
109
});

0 commit comments

Comments
 (0)