@@ -8,6 +8,15 @@ const inputDir = path.join(__dirname, '../src');
88// DONOT MODIFY THIS
99const outputDir = path . join ( __dirname , './dev-temp' ) ; // this directory will be automatically removed (required for automative processes, the final output will be in API directory).
1010
11+ // Set up paths for the build process
12+ const buildDir = __dirname ;
13+ const jsdocFile = path . join ( buildDir , 'jsdoc.json' ) ;
14+ const configFile = path . join ( buildDir , 'config.json' ) ;
15+ const sourceDir = path . join ( buildDir , 'dev-temp' ) ;
16+ const devApiDir = path . join ( buildDir , 'dev-api' ) ;
17+ const tempDir = path . join ( devApiDir , 'temp' ) ;
18+ const mdxApiDir = path . join ( __dirname , 'api' ) ;
19+
1120
1221/**
1322 * Checks if a file contains a specific line.
@@ -169,15 +178,6 @@ console.log("Successfully removed redundant JS code");
169178
170179// Conversion of MDX from JS files starts here
171180
172- // Set up paths for the build process
173- const buildDir = __dirname ;
174- const jsdocFile = path . join ( buildDir , 'jsdoc.json' ) ;
175- const configFile = path . join ( buildDir , 'config.json' ) ;
176- const sourceDir = path . join ( buildDir , 'dev-temp' ) ;
177- const devApiDir = path . join ( buildDir , 'dev-api' ) ;
178- const tempDir = path . join ( devApiDir , 'temp' ) ;
179- const mdxApiDir = path . join ( __dirname , 'api' ) ;
180-
181181
182182/**
183183 * Generates MDX files from JS files using jsdoc-to-mdx.
@@ -512,37 +512,6 @@ generateMdxFiles();
512512
513513console . log ( "Redundant files generated for conversion process are removed!" ) ;
514514
515- // Root directories
516- const docsDir = './docs' ;
517-
518- /**
519- * Copies markdown files from the docs directory to the API directory.
520- *
521- * @param {string } sourceDir - Source directory containing markdown files
522- * @param {string } destDir - Destination directory for copied files
523- */
524- const copyMarkdownFiles = ( sourceDir , destDir ) => {
525- // Create the destination directory if it doesn't exist
526- if ( ! fs . existsSync ( destDir ) ) {
527- fs . mkdirSync ( destDir , { recursive : true } ) ;
528- }
529-
530- fs . readdirSync ( sourceDir ) . forEach ( ( file ) => {
531- const sourcePath = path . join ( sourceDir , file ) ;
532- const destPath = path . join ( destDir , file ) ;
533- const stat = fs . lstatSync ( sourcePath ) ;
534-
535- // Only copy if it's a file and has .md extension
536- if ( stat . isFile ( ) && path . extname ( sourcePath ) === '.md' ) {
537- fs . copyFileSync ( sourcePath , destPath ) ;
538- }
539- } ) ;
540- } ;
541-
542- // Execute the function
543- copyMarkdownFiles ( docsDir , mdxApiDir ) ;
544-
545-
546515const notificationUIPath = './build/api/widgets/NotificationUI.mdx' ;
547516
548517/**
@@ -591,15 +560,15 @@ function moveToApiReference(sourceDir, destDir) {
591560 if ( entry . isDirectory ( ) ) {
592561 // Skip the "API reference" folder itself
593562 if ( entry . name === "API reference" ) continue ;
594-
563+
595564 // Create the corresponding directory in the destination
596565 if ( ! fs . existsSync ( destPath ) ) {
597566 fs . mkdirSync ( destPath , { recursive : true } ) ;
598567 }
599-
568+
600569 // Move contents of the directory
601570 moveToApiReference ( srcPath , destPath ) ;
602-
571+
603572 // Remove the now-empty directory from the source
604573 if ( fs . readdirSync ( srcPath ) . length === 0 ) {
605574 fs . rmdirSync ( srcPath ) ;
@@ -615,4 +584,61 @@ const apiReferenceDir = path.join(__dirname, 'api', 'API reference');
615584moveToApiReference ( path . join ( __dirname , 'api' ) , apiReferenceDir ) ;
616585console . log ( "All MDX files have been moved to the API reference folder" ) ;
617586
618- console . log ( "All set! Just move the API folder to the docs site" ) ;
587+
588+ /**
589+ * Delete the docs/generatedApiDocs directory and all its content, to add the new generated content there
590+ */
591+ function removeGeneratedApiDocs ( ) {
592+ const generatedApiDocsDir = './docs/generatedApiDocs' ;
593+ try {
594+ fs . rmSync ( generatedApiDocsDir , { recursive : true , force : true } ) ;
595+ } catch ( err ) {
596+ console . error ( `Error while deleting the generatedApiDocs directory: ${ err } ` ) ;
597+ }
598+ }
599+
600+ removeGeneratedApiDocs ( ) ;
601+
602+
603+ /**
604+ * Move the API reference directory from the 'build' directory to the 'docs' directory
605+ * @param {string } sourceDir Takes the input dir address
606+ * @param {string } destDir Takes the output dir address
607+ */
608+ function moveApiReferenceDir ( sourceDir , destDir ) {
609+
610+ // check if API Reference dir already exists in destination. If yes, remove it
611+ if ( fs . existsSync ( path . join ( destDir , 'API Reference' ) ) ) {
612+ fs . rmSync ( path . join ( destDir , 'API Reference' ) , { recursive : true , force : true } ) ;
613+ }
614+
615+ // add full paths
616+ sourceDir = path . join ( sourceDir , 'API Reference' ) ;
617+ destDir = path . join ( destDir , 'API Reference' ) ;
618+
619+ // Move the directory
620+ try {
621+ fs . renameSync ( sourceDir , destDir ) ;
622+ } catch ( err ) {
623+ console . error ( `Error while moving the directory from build to docs: ${ err } ` ) ;
624+ }
625+ }
626+
627+ moveApiReferenceDir ( mdxApiDir , './docs' ) ;
628+
629+ /**
630+ * Delete the API directory i.e. inside the 'build' directory as all its contents are now moved to docs directory
631+ * @param {string } mdxApiDir Path of the api dir
632+ */
633+ function removeApiDir ( mdxApiDir ) {
634+ try {
635+ fs . rmSync ( mdxApiDir , { recursive : true , force : true } ) ;
636+ } catch ( err ) {
637+ console . error ( `Error while deleting the Api directory present inside build directory: ${ err } ` ) ;
638+ }
639+ }
640+
641+ removeApiDir ( mdxApiDir ) ;
642+
643+
644+ console . log ( "All set! Just copy the docs directory to the docs site." ) ;
0 commit comments