@@ -15,6 +15,7 @@ import {
15
15
getAppConfigPath ,
16
16
cleanEmptyExprFromModule ,
17
17
cleanEmptyExprFromProviders ,
18
+ getWorkspace ,
18
19
} from '../../utils' ;
19
20
import { ThemeOptionsEnum } from './theme-options.enum' ;
20
21
import { findNodes , getDecoratorMetadata , getMetadataField } from '../../utils/angular/ast-utils' ;
@@ -82,6 +83,7 @@ function updateAppModule(selectedProject: string, targetThemeName: ThemeOptionsE
82
83
insertImports ( selectedProject , targetThemeName ) ,
83
84
insertProviders ( selectedProject , targetThemeName ) ,
84
85
adjustProvideAbpThemeShared ( appModulePath , targetThemeName ) ,
86
+ updateIndexHtml ( selectedProject , targetThemeName ) ,
85
87
formatFile ( appModulePath ) ,
86
88
cleanEmptyExpressions ( appModulePath , isStandalone ) ,
87
89
] ) ;
@@ -534,3 +536,39 @@ function findProvideAbpThemeSharedCalls(source: ts.SourceFile): ts.CallExpressio
534
536
535
537
return result ;
536
538
}
539
+
540
+ export function updateIndexHtml ( projectName : string , themeName : ThemeOptionsEnum ) : Rule {
541
+ return async ( host : Tree ) => {
542
+ const workspace = await getWorkspace ( host ) ;
543
+ const project = workspace . projects . get ( projectName ) ;
544
+
545
+ if ( ! project ) {
546
+ throw new Error ( `Project "${ projectName } " not found in workspace.` ) ;
547
+ }
548
+
549
+ const buildOptions = project . targets . get ( 'build' ) ?. options ;
550
+ const indexPath = buildOptions ?. index as string ;
551
+
552
+ if ( ! indexPath || ! host . exists ( indexPath ) ) {
553
+ throw new Error ( `index.html not found at path: ${ indexPath } ` ) ;
554
+ }
555
+
556
+ const buffer = host . read ( indexPath ) ;
557
+ if ( ! buffer ) return ;
558
+ const content = buffer . toString ( 'utf-8' ) ;
559
+
560
+ const loaderDiv = `<div id="lp-page-loader"></div>` ;
561
+ let updatedContent = content ;
562
+
563
+ if ( themeName === ThemeOptionsEnum . LeptonX ) {
564
+ if ( ! content . includes ( loaderDiv ) ) {
565
+ updatedContent = content . replace ( / < b o d y ( [ ^ > ] * ) > / i, `<body$1>\n ${ loaderDiv } ` ) ;
566
+ }
567
+ } else {
568
+ if ( content . includes ( loaderDiv ) ) {
569
+ updatedContent = content . replace ( loaderDiv , '' ) ;
570
+ }
571
+ }
572
+ host . overwrite ( indexPath , updatedContent ) ;
573
+ } ;
574
+ }
0 commit comments