From 9e36de5aecf3d8a7d91eb66981827e752b9a68e4 Mon Sep 17 00:00:00 2001 From: erdemcaygor Date: Wed, 16 Apr 2025 15:51:33 +0300 Subject: [PATCH] refactoring --- .../src/commands/change-theme/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts b/npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts index 22b8ccf2ba..9fae76efe2 100644 --- a/npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts +++ b/npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts @@ -7,8 +7,7 @@ import { ChangeThemeOptions } from './model'; import { addRootImport, addRootProvider, - createDefaultPath, - getWorkspace, + getAppModulePath, isLibrary, isStandaloneApp, updateWorkspace, @@ -16,6 +15,7 @@ import { } from '../../utils'; import { ThemeOptionsEnum } from './theme-options.enum'; import { findNodes, getDecoratorMetadata, getMetadataField } from '../../utils/angular/ast-utils'; +import { getMainFilePath } from '../../utils/angular/standalone/util'; export default function (_options: ChangeThemeOptions): Rule { return async () => { @@ -64,14 +64,12 @@ function updateProjectStyle( function updateAppModule(selectedProject: string, targetThemeName: ThemeOptionsEnum): Rule { return async (host: Tree) => { - const workspace = await getWorkspace(host); - const project = workspace.projects.get(selectedProject); - const sourceRoot = project?.sourceRoot || 'src'; - const isStandalone = isStandaloneApp(host, `${sourceRoot}/main.ts`); + const mainFilePath = await getMainFilePath(host, selectedProject); + console.log('main file path --->>>>>', mainFilePath); + const isStandalone = isStandaloneApp(host, mainFilePath); console.log('isStandalone --->>>>>', isStandalone); - const defaultPath = await createDefaultPath(host, selectedProject); - const appModulePath = - defaultPath + `${isStandalone ? `${sourceRoot}/main.ts` : '/app.module.ts'}`; + const appModulePath = isStandalone ? mainFilePath : getAppModulePath(host, mainFilePath); + console.log('app module path --->>>>>', appModulePath); return chain([ removeImportPath(appModulePath, targetThemeName),