diff --git a/scripts/docs.js b/scripts/docs.js index 01fa00a5..51f128d6 100644 --- a/scripts/docs.js +++ b/scripts/docs.js @@ -3,7 +3,8 @@ import path from "node:path"; import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter"; -import { dashCase, listPublicDirs, writeSourceFile } from "./utils.js"; + +import { listPublicDirs, writeSourceFile } from "./utils.js"; const publicDirs = listPublicDirs("src"); const targetDir = "lib/components/internal/api-docs"; @@ -20,27 +21,22 @@ function validatePublicFiles(definitionFiles) { } function componentDocs() { - const definitions = documentComponents(path.resolve("tsconfig.json"), "src/*/index.tsx"); + const definitions = documentComponents({ + tsconfigPath: path.resolve("tsconfig.json"), + publicFilesGlob: "src/*/index.tsx", + }); const outDir = path.join(targetDir, "components"); - const fileNames = definitions - .filter((definition) => { - const fileName = dashCase(definition.name); - if (!publicDirs.includes(fileName)) { - console.warn(`Excluded "${fileName}" from components definitions.`); - return false; - } - return true; - }) - .map((definition) => { - const fileName = dashCase(definition.name); - writeSourceFile(path.join(outDir, fileName + ".js"), `module.exports = ${JSON.stringify(definition, null, 2)};`); - return fileName; - }); - validatePublicFiles(fileNames); + for (const definition of definitions) { + writeSourceFile( + path.join(outDir, definition.dashCaseName + ".js"), + `module.exports = ${JSON.stringify(definition, null, 2)};`, + ); + } const indexContent = `module.exports = { - ${fileNames.map((name) => `${JSON.stringify(name)}:require('./${name}')`).join(",\n")} + ${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() { diff --git a/scripts/utils.js b/scripts/utils.js index 238238bf..9285648d 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -1,17 +1,13 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import lodash from "lodash"; import fs from "node:fs"; import path from "node:path"; -import lodash from "lodash"; export function pascalCase(text) { return capitalize(lodash.camelCase(text)); } -export function dashCase(text) { - return lodash.kebabCase(text); -} - function capitalize(text) { return text[0].toUpperCase() + text.slice(1); } diff --git a/src/__tests__/__snapshots__/documenter.test.ts.snap b/src/__tests__/__snapshots__/documenter.test.ts.snap index e28b06c9..ca8abe3f 100644 --- a/src/__tests__/__snapshots__/documenter.test.ts.snap +++ b/src/__tests__/__snapshots__/documenter.test.ts.snap @@ -2,6 +2,7 @@ exports[`definition for board matches the snapshot > board 1`] = ` { + "dashCaseName": "board", "events": [ { "cancelable": false, @@ -181,6 +182,7 @@ When items are loading the slot can be used to render the loading indicator.", exports[`definition for board-item matches the snapshot > board-item 1`] = ` { + "dashCaseName": "board-item", "events": [], "functions": [], "name": "BoardItem", @@ -259,6 +261,7 @@ ARIA labels: exports[`definition for items-palette matches the snapshot > items-palette 1`] = ` { + "dashCaseName": "items-palette", "events": [], "functions": [], "name": "ItemsPalette",