@@ -8,6 +8,7 @@ const __dirname = new URL('.', import.meta.url).pathname;
88
99const PATH_DEMO_SRC = path . join ( __dirname , '..' , 'src' ) ;
1010const PATH_LIB_SRC = path . join ( __dirname , ".." , ".." , ".." , "packages" , "react-tools-lib" , "src" ) ;
11+ const PATH_UTILITY_MODEL_TYPES_FILE = path . join ( __dirname , ".." , ".." , ".." , "packages" , "react-tools-lib" , "src" , "models" , "utilityTypes.model.ts" ) ;
1112const DEMO_COMPONENT_DIR_NAME = "pages" ;
1213const MARKDOWWN_DIR_NAME = "markdown" ;
1314const HOOKS_DIR_NAME = "hooks" ;
@@ -213,13 +214,15 @@ ${jsDoc.usage ? `\n## Usage\n\n${jsDoc.usage}\n`:""}
213214${ jsDoc . type }
214215\`\`\`
215216
216- > ### Params
217+ ${ jsDoc . params && jsDoc . params . length > 0 ?
218+ `> ### Params
217219>
218220${ jsDoc . params && jsDoc . params . length > 0
219- ? jsDoc . params . map ( el => `> - __${ el . name } __: _${ el . type } _${ el . description ? ' \n' + el . description : "" } ` ) . join ( "\n" )
221+ ? jsDoc . params . map ( el => `> - __${ el . name } __: _${ el . type } _${ el . description ? ' \n' + el . description : "" } ` ) . join ( "\n" )
220222 : ">"
221223}
222224>
225+ ` :"" }
223226
224227> ### Returns
225228>
@@ -452,11 +455,72 @@ async function generateComponentsMarkDown() {
452455 }
453456}
454457
458+ async function generateModelMarkDown ( ) {
459+ const utilityTypesFile = await fs . readFile ( path . join ( PATH_UTILITY_MODEL_TYPES_FILE ) , { encoding : "utf8" } ) ;
460+ const stringBuffer = {
461+ value : "" ,
462+ /**
463+ *
464+ * @param {string } s
465+ * @returns {this }
466+ */
467+ add ( s ) {
468+ this . value += s + "\n" ;
469+ return this ;
470+ } ,
471+ /**
472+ *
473+ * @param {string[] } s
474+ * @returns {this }
475+ */
476+ set ( s ) {
477+ s . forEach ( slice => { this . value += slice + "\n" } ) ;
478+ return this ;
479+ }
480+ }
481+ const utilityTypesFileSplitted = utilityTypesFile . split ( "\n" ) . slice ( 2 ) . filter ( el => ! [ "/**" , " */" , "" ] . includes ( el ) ) ;
482+ stringBuffer . set ( [
483+ "# Utility Types" ,
484+ "" ,
485+ "Typescript utility types for specified use cases." ,
486+ ""
487+ ] ) ;
488+ for ( let i = 0 , size = utilityTypesFileSplitted . length ; i < size ; ) {
489+ const description = utilityTypesFileSplitted [ i ] . substring ( 3 ) ;
490+ const type = utilityTypesFileSplitted [ i + 1 ] ;
491+ let title , generics ;
492+ if ( type . indexOf ( "> =" ) !== - 1 ) {
493+ title = type . substring ( 12 , type . indexOf ( "<" ) ) ;
494+ generics = type . substring ( type . indexOf ( "<" ) , type . indexOf ( "> =" ) + 1 ) ;
495+ } else {
496+ title = type . substring ( 12 , type . indexOf ( " =" ) ) ;
497+ }
498+ stringBuffer . set ( [
499+ "## " + title ,
500+ "" ,
501+ description ,
502+ "```tsx" ,
503+ "type " + title + ( generics ? generics : "" ) ,
504+ "```" ,
505+ ""
506+ ] ) ;
507+ i ++ ;
508+ while ( ! utilityTypesFileSplitted [ i ] . startsWith ( " * " ) ) {
509+ i ++ ;
510+ if ( i === size ) {
511+ break ;
512+ }
513+ }
514+ }
515+ await fs . writeFile ( path . join ( PATH_DEMO_SRC , MARKDOWWN_DIR_NAME , "utilityTypes.md" ) , stringBuffer . value , { encoding : "utf8" } ) ;
516+ }
517+
455518async function generateMarkDown ( ) {
456519 try {
457520 await deleteAllFiles ( path . join ( PATH_DEMO_SRC , MARKDOWWN_DIR_NAME ) ) ;
458521 await generateUtilsMarkDown ( ) ;
459522 await generateHooksMarkDown ( ) ;
523+ await generateModelMarkDown ( ) ;
460524 await generateComponentsMarkDown ( ) ;
461525 process . exit ( 0 ) ;
462526 } catch ( error ) {
0 commit comments