1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
const path = require ( 'path' ) ;
4
- const { paramCase } = require ( 'change-case' ) ;
5
4
const { documentComponents, documentTestUtils } = require ( '@cloudscape-design/documenter' ) ;
6
5
const { writeFile } = require ( '../utils/files' ) ;
7
6
const { listPublicItems } = require ( '../utils/files' ) ;
@@ -24,32 +23,26 @@ function validatePublicFiles(definitionFiles) {
24
23
}
25
24
26
25
function componentDocs ( ) {
27
- const definitions = documentComponents ( require . resolve ( '../../tsconfig.json' ) , 'src/*/index.tsx' , undefined , {
26
+ const definitions = documentComponents ( {
27
+ tsconfigPath : require . resolve ( '../../tsconfig.json' ) ,
28
+ publicFilesGlob : 'src/*/index.tsx' ,
28
29
extraExports : {
29
30
FileDropzone : [ 'useFilesDragging' ] ,
30
31
TagEditor : [ 'getTagsDiff' ] ,
31
32
} ,
32
33
} ) ;
33
34
const outDir = path . join ( workspace . apiDocsPath , 'components' ) ;
34
- const fileNames = definitions
35
- . filter ( definition => {
36
- const fileName = paramCase ( definition . name ) ;
37
- if ( ! publicDirs . includes ( fileName ) ) {
38
- console . warn ( `Excluded "${ fileName } " from components definitions.` ) ;
39
- return false ;
40
- }
41
- return true ;
42
- } )
43
- . map ( definition => {
44
- const fileName = paramCase ( definition . name ) ;
45
- writeFile ( path . join ( outDir , fileName + '.js' ) , `module.exports = ${ JSON . stringify ( definition , null , 2 ) } ;` ) ;
46
- return fileName ;
47
- } ) ;
48
- validatePublicFiles ( fileNames ) ;
35
+ for ( const definition of definitions ) {
36
+ writeFile (
37
+ path . join ( outDir , definition . dashCaseName + '.js' ) ,
38
+ `module.exports = ${ JSON . stringify ( definition , null , 2 ) } ;`
39
+ ) ;
40
+ }
49
41
const indexContent = `module.exports = {
50
- ${ fileNames . map ( name => `${ JSON . stringify ( name ) } :require('./${ name } ')` ) . join ( ',\n' ) }
42
+ ${ definitions . map ( definition => `${ JSON . stringify ( definition . dashCaseName ) } :require('./${ definition . dashCaseName } ')` ) . join ( ',\n' ) }
51
43
}` ;
52
44
writeFile ( path . join ( outDir , 'index.js' ) , indexContent ) ;
45
+ validatePublicFiles ( definitions . map ( def => def . dashCaseName ) ) ;
53
46
}
54
47
55
48
function testUtilDocs ( ) {
0 commit comments