@@ -18,10 +18,11 @@ const SEO_FILES = ['robots.txt', 'llm.txt', 'sitemap.xml'];
1818/**
1919 * Recursively finds application root directories by looking for index.html.
2020 * Excludes 'examples' directory.
21- * @param {string } currentDir
22- * @returns {string[] } Array of absolute paths to app roots.
21+ * @param {string } currentDir - The directory to start searching from.
22+ * @param {string } baseAppDir - The base 'apps' directory to calculate relative paths from.
23+ * @returns {Array<{appRootPath: string, appRelativePath: string}> } Array of objects with absolute and relative paths.
2324 */
24- function findAppRoots ( currentDir ) {
25+ function findAppRoots ( currentDir , baseAppDir ) {
2526 let appRoots = [ ] ;
2627 const entries = fs . readdirSync ( currentDir , { withFileTypes : true } ) ;
2728
@@ -31,10 +32,11 @@ function findAppRoots(currentDir) {
3132 if ( entry . isDirectory ( ) ) {
3233 // Check if current directory contains index.html
3334 if ( fs . existsSync ( path . join ( fullPath , 'index.html' ) ) ) {
34- appRoots . push ( fullPath ) ;
35+ const appRelativePath = path . relative ( baseAppDir , fullPath ) ;
36+ appRoots . push ( { appRootPath : fullPath , appRelativePath : appRelativePath } ) ;
3537 }
3638 // Recurse into subdirectories
37- appRoots = appRoots . concat ( findAppRoots ( fullPath ) ) ;
39+ appRoots = appRoots . concat ( findAppRoots ( fullPath , baseAppDir ) ) ;
3840 }
3941 }
4042 return appRoots ;
@@ -43,22 +45,19 @@ function findAppRoots(currentDir) {
4345/**
4446 * Copies SEO files from an app root to its corresponding dist folders.
4547 * @param {string } appRootPath - Absolute path to the app's root directory.
48+ * @param {string } appRelativePath - Relative path of the app from the base 'apps' directory.
4649 * @param {string } env - The build environment ('all', 'dev', 'prod').
4750 */
48- function copySeoFilesForApp ( appRootPath , env ) {
49- const appName = path . basename ( appRootPath ) ;
50- console . log ( chalk . blue ( `Copying SEO files for app: ${ appName } ` ) ) ;
51+ function copySeoFilesForApp ( appRootPath , appRelativePath , env ) {
52+ console . log ( chalk . blue ( `Copying SEO files for app: ${ appRelativePath } ` ) ) ;
5153
5254 const targetEnvs = [ ] ;
53- if ( env === 'all' || env === 'dev' ) {
54- targetEnvs . push ( 'development' ) ;
55- }
56- if ( env === 'all' || env === 'prod' ) {
57- targetEnvs . push ( 'production' ) ;
58- }
55+ if ( env === 'all' || env === 'dev' ) { targetEnvs . push ( 'development' ) ; }
56+ if ( env === 'all' || env === 'esm' ) { targetEnvs . push ( 'esm' ) ; }
57+ if ( env === 'all' || env === 'prod' ) { targetEnvs . push ( 'production' ) ; }
5958
6059 for ( const targetEnv of targetEnvs ) {
61- const targetDistDir = path . join ( DIST_DIR , targetEnv , appName ) ;
60+ const targetDistDir = path . join ( DIST_DIR , targetEnv , 'apps' , appRelativePath ) ;
6261 if ( ! fs . existsSync ( targetDistDir ) ) {
6362 console . warn ( chalk . yellow ( ` Warning: Target directory ${ targetDistDir } does not exist. Skipping SEO file copy.` ) ) ;
6463 continue ;
@@ -94,9 +93,9 @@ console.log(chalk.green(programName));
9493
9594// --- Start SEO file copying logic ---
9695console . log ( chalk . blue ( 'Copying SEO files for applications...' ) ) ;
97- const appRoots = findAppRoots ( APP_DIR ) ;
98- for ( const appRoot of appRoots ) {
99- copySeoFilesForApp ( appRoot , env ) ;
96+ const appData = findAppRoots ( APP_DIR , APP_DIR ) ; // Pass APP_DIR as baseAppDir
97+ for ( const app of appData ) {
98+ copySeoFilesForApp ( app . appRootPath , app . appRelativePath , env ) ;
10099}
101100// --- End SEO file copying logic ---
102101
0 commit comments