Browse Source

refactoring

pull/22645/head
erdemcaygor 1 year ago
parent
commit
9e36de5aec
  1. 16
      npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts

16
npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts

@ -7,8 +7,7 @@ import { ChangeThemeOptions } from './model';
import { import {
addRootImport, addRootImport,
addRootProvider, addRootProvider,
createDefaultPath, getAppModulePath,
getWorkspace,
isLibrary, isLibrary,
isStandaloneApp, isStandaloneApp,
updateWorkspace, updateWorkspace,
@ -16,6 +15,7 @@ import {
} from '../../utils'; } from '../../utils';
import { ThemeOptionsEnum } from './theme-options.enum'; import { ThemeOptionsEnum } from './theme-options.enum';
import { findNodes, getDecoratorMetadata, getMetadataField } from '../../utils/angular/ast-utils'; import { findNodes, getDecoratorMetadata, getMetadataField } from '../../utils/angular/ast-utils';
import { getMainFilePath } from '../../utils/angular/standalone/util';
export default function (_options: ChangeThemeOptions): Rule { export default function (_options: ChangeThemeOptions): Rule {
return async () => { return async () => {
@ -64,14 +64,12 @@ function updateProjectStyle(
function updateAppModule(selectedProject: string, targetThemeName: ThemeOptionsEnum): Rule { function updateAppModule(selectedProject: string, targetThemeName: ThemeOptionsEnum): Rule {
return async (host: Tree) => { return async (host: Tree) => {
const workspace = await getWorkspace(host); const mainFilePath = await getMainFilePath(host, selectedProject);
const project = workspace.projects.get(selectedProject); console.log('main file path --->>>>>', mainFilePath);
const sourceRoot = project?.sourceRoot || 'src'; const isStandalone = isStandaloneApp(host, mainFilePath);
const isStandalone = isStandaloneApp(host, `${sourceRoot}/main.ts`);
console.log('isStandalone --->>>>>', isStandalone); console.log('isStandalone --->>>>>', isStandalone);
const defaultPath = await createDefaultPath(host, selectedProject); const appModulePath = isStandalone ? mainFilePath : getAppModulePath(host, mainFilePath);
const appModulePath = console.log('app module path --->>>>>', appModulePath);
defaultPath + `${isStandalone ? `${sourceRoot}/main.ts` : '/app.module.ts'}`;
return chain([ return chain([
removeImportPath(appModulePath, targetThemeName), removeImportPath(appModulePath, targetThemeName),

Loading…
Cancel
Save