33import path from "node:path" ;
44
55import { documentComponents , documentTestUtils } from "@cloudscape-design/documenter" ;
6- import { dashCase , listPublicDirs , writeSourceFile } from "./utils.js" ;
6+
7+ import { listPublicDirs , writeSourceFile } from "./utils.js" ;
78
89const publicDirs = listPublicDirs ( "src" ) ;
910const targetDir = "lib/components/internal/api-docs" ;
@@ -20,27 +21,22 @@ function validatePublicFiles(definitionFiles) {
2021}
2122
2223function componentDocs ( ) {
23- const definitions = documentComponents ( path . resolve ( "tsconfig.json" ) , "src/*/index.tsx" ) ;
24+ const definitions = documentComponents ( {
25+ tsconfigPath : path . resolve ( "tsconfig.json" ) ,
26+ publicFilesGlob : "src/*/index.tsx" ,
27+ } ) ;
2428 const outDir = path . join ( targetDir , "components" ) ;
25- const fileNames = definitions
26- . filter ( ( definition ) => {
27- const fileName = dashCase ( definition . name ) ;
28- if ( ! publicDirs . includes ( fileName ) ) {
29- console . warn ( `Excluded "${ fileName } " from components definitions.` ) ;
30- return false ;
31- }
32- return true ;
33- } )
34- . map ( ( definition ) => {
35- const fileName = dashCase ( definition . name ) ;
36- writeSourceFile ( path . join ( outDir , fileName + ".js" ) , `module.exports = ${ JSON . stringify ( definition , null , 2 ) } ;` ) ;
37- return fileName ;
38- } ) ;
39- validatePublicFiles ( fileNames ) ;
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+ }
4035 const indexContent = `module.exports = {
41- ${ fileNames . map ( ( name ) => `${ JSON . stringify ( name ) } :require('./${ name } ')` ) . join ( ",\n" ) }
36+ ${ definitions . map ( ( definition ) => `${ JSON . stringify ( definition . dashCaseName ) } :require('./${ definition . dashCaseName } ')` ) . join ( ",\n" ) }
4237 }` ;
4338 writeSourceFile ( path . join ( outDir , "index.js" ) , indexContent ) ;
39+ validatePublicFiles ( definitions . map ( ( def ) => def . dashCaseName ) ) ;
4440}
4541
4642function testUtilDocs ( ) {
0 commit comments