@@ -7,33 +7,28 @@ import { fileURLToPath } from "url";
77
88const __filename = fileURLToPath ( import . meta. url ) ;
99const __dirname = path . dirname ( __filename ) ;
10- const componentsDir = path . join ( __dirname , "../../core /src/components" ) ;
10+ const componentsDir = path . join ( __dirname , "../../docs /src/pages/ components/ " ) ;
1111const outputDir = path . join ( __dirname , "../dist/generated/" ) ;
1212if ( ! fs . existsSync ( outputDir ) ) {
13- fs . mkdirSync ( outputDir ) ;
13+ fs . mkdirSync ( outputDir ) ;
1414}
1515
1616function getStoryFiles ( ) {
1717 const storyFiles = [ ] ;
1818
1919 function traverseDirectory ( dir ) {
2020 const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
21-
21+
2222 for ( const entry of entries ) {
2323 const fullPath = path . join ( dir , entry . name ) ;
24-
24+
2525 if ( entry . isDirectory ( ) ) {
26- if ( entry . name === "__stories__" ) {
27- // Found stories directory, get all .stories.tsx files
28- const storyDirEntries = fs . readdirSync ( fullPath , { withFileTypes : true } ) ;
29- for ( const storyEntry of storyDirEntries ) {
30- if ( storyEntry . isFile ( ) && ( storyEntry . name . endsWith ( ".stories.tsx" ) || storyEntry . name . endsWith ( ".stories.js" ) ) ) {
31- storyFiles . push ( path . relative ( __dirname , path . join ( fullPath , storyEntry . name ) ) ) ;
32- }
33- }
34- } else {
35- // Recursively traverse other directories
36- traverseDirectory ( fullPath ) ;
26+ // Recursively traverse subdirectories
27+ traverseDirectory ( fullPath ) ;
28+ } else if ( entry . isFile ( ) ) {
29+ // Check for story files
30+ if ( entry . name . endsWith ( ".stories.tsx" ) || entry . name . endsWith ( ".stories.js" ) ) {
31+ storyFiles . push ( path . relative ( __dirname , fullPath ) ) ;
3732 }
3833 }
3934 }
@@ -50,10 +45,10 @@ function generateCodeForOneLiner(ast, constName) {
5045 traverse . default ( ast , {
5146 VariableDeclarator ( path ) {
5247 if ( path . node . id . name === constName ) {
53- if ( path . node . init ?. callee ?. name !== ' createComponentTemplate' ) {
48+ if ( path . node . init ?. callee ?. name !== " createComponentTemplate" ) {
5449 calleeCode = "const " + generate . default ( path . node ) . code ;
5550 } else {
56- return calleeCode = ""
51+ return ( calleeCode = "" ) ;
5752 }
5853 }
5954 }
@@ -62,16 +57,13 @@ function generateCodeForOneLiner(ast, constName) {
6257}
6358
6459function extractMarkdown ( file ) {
65- const inputFile = path . join (
66- __dirname ,
67- file
68- ) ;
60+ const inputFile = path . join ( __dirname , file ) ;
6961 const inputFileComponentName = path . basename ( inputFile ) . split ( "." ) [ 0 ] ;
7062 const outputFile = path . resolve ( __dirname , outputDir , inputFileComponentName + ".md" ) ;
7163
7264 const fileContent = fs . readFileSync ( inputFile , "utf-8" ) ;
7365
74- console . log ( `Generating markdown for ${ inputFileComponentName } ` )
66+ console . log ( `Generating markdown for ${ inputFileComponentName } ` ) ;
7567
7668 // Parse the file using Babel parser with TypeScript and JSX support
7769 const ast = parser . parse ( fileContent , {
@@ -115,23 +107,24 @@ function extractMarkdown(file) {
115107 } ) ;
116108 if ( renderProp ) {
117109 // If render is a function, generate its code
118- if ( renderProp . type == 'ArrowFunctionExpression' ) {
119- if ( renderProp . body . type == 'JSXFragment' || renderProp . body . type == 'MemberExpression' || renderProp . body . type == 'JSXElement' ) {
120- codeBlock = generate . default ( renderProp . body ) . code ;
121- }
122- else if ( renderProp . body . type == 'BlockStatement' ) {
123- codeBlock = renderProp . body . body . map ( line => generate . default ( line ) . code ) . join ( '\n' )
124- }
125- else {
110+ if ( renderProp . type == "ArrowFunctionExpression" ) {
111+ if (
112+ renderProp . body . type == "JSXFragment" ||
113+ renderProp . body . type == "MemberExpression" ||
114+ renderProp . body . type == "JSXElement"
115+ ) {
116+ codeBlock = generate . default ( renderProp . body ) . code ;
117+ } else if ( renderProp . body . type == "BlockStatement" ) {
118+ codeBlock = renderProp . body . body . map ( line => generate . default ( line ) . code ) . join ( "\n" ) ;
119+ } else {
126120 console . log ( `${ nameProp || storyName } is a ${ renderProp . body . type } ` ) ;
127121 codeBlock = generate . default ( renderProp . body ) . code ;
128122 }
129- } else if ( renderProp . type == ' CallExpression' ) {
123+ } else if ( renderProp . type == " CallExpression" ) {
130124 // console.log(renderProp.callee.object.name);
131125 const calleeName = renderProp . callee . object . name ;
132- codeBlock = generateCodeForOneLiner ( ast , calleeName )
133- }
134- else {
126+ codeBlock = generateCodeForOneLiner ( ast , calleeName ) ;
127+ } else {
135128 console . log ( `${ nameProp || storyName } is a ${ renderProp . type } ` ) ;
136129 }
137130 }
0 commit comments