Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions scripts/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
import path from "node:path";

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

import { listPublicDirs, writeSourceFile } from "./utils.js";
import { writeSourceFile } from "./utils.js";

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

componentDocs();
testUtilDocs();

function validatePublicFiles(definitionFiles) {
for (const publicDir of publicDirs) {
if (!definitionFiles.includes(publicDir)) {
throw new Error(`Directory src/${publicDir} does not have a corresponding API definition`);
}
}
}

function componentDocs() {
const definitions = documentComponents({
writeComponentsDocumentation({
outDir: path.join(targetDir, "components"),
tsconfigPath: path.resolve("tsconfig.json"),
publicFilesGlob: "src/*/index.tsx",
});
const outDir = path.join(targetDir, "components");
for (const definition of definitions) {
writeSourceFile(
path.join(outDir, definition.dashCaseName + ".js"),
`module.exports = ${JSON.stringify(definition, null, 2)};`,
);
}
const indexContent = `module.exports = {
${definitions.map((definition) => `${JSON.stringify(definition.dashCaseName)}:require('./${definition.dashCaseName}')`).join(",\n")}
}`;
writeSourceFile(path.join(outDir, "index.js"), indexContent);
validatePublicFiles(definitions.map((def) => def.dashCaseName));
}

function testUtilDocs() {
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/documenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import { expect, test } from "vitest";

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

test.each(Object.entries(apiDocs))("definition for $0 matches the snapshot", (name, definition) => {
test.each(Object.entries(apiDocs))("definition for $0 matches the snapshot", (_name, definition) => {
expect(definition).toMatchSnapshot();
});
Loading