Browse Source

refactoring

pull/22645/head
erdemcaygor 1 year ago
parent
commit
b8df00add6
  1. 10
      npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts
  2. 7
      npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts

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

@ -12,11 +12,11 @@ import {
isStandaloneApp,
updateWorkspace,
WorkspaceDefinition,
getAppConfigPath,
} from '../../utils';
import { ThemeOptionsEnum } from './theme-options.enum';
import { findNodes, getDecoratorMetadata, getMetadataField } from '../../utils/angular/ast-utils';
import { findBootstrapApplicationCall, getMainFilePath } from '../../utils/angular/standalone/util';
import { findAppConfig } from '../../utils/angular/standalone/app_config';
import { getMainFilePath } from '../../utils/angular/standalone/util';
export default function (_options: ChangeThemeOptions): Rule {
return async () => {
@ -348,12 +348,6 @@ export const styleCompareFn = (item1: string | object, item2: string | object) =
return o1.bundleName && o2.bundleName && o1.bundleName == o2.bundleName;
};
export const getAppConfigPath = (host: Tree, mainFilePath: string): string => {
const bootstrapCall = findBootstrapApplicationCall(host, mainFilePath);
const appConfig = findAppConfig(bootstrapCall, host, mainFilePath);
return appConfig?.filePath || '';
};
export const formatFile = (filePath: string): Rule => {
return (tree: Tree) => {
const buffer = tree.read(filePath);

7
npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts

@ -16,6 +16,7 @@ import {
addRootProvider,
addRouteDeclarationToModule,
applyWithOverwrite,
findAppRoutesPath,
getFirstApplication,
getWorkspace,
InsertChange,
@ -255,18 +256,16 @@ export function addRoutingToAppRoutingModule(
return async (tree: Tree) => {
const projectName = getFirstApplication(tree).name!;
const project = workspace.projects.get(projectName);
console.log('project --->>>', project);
const mainFilePath = await getMainFilePath(tree, projectName);
console.log('main file path ---->>>>', mainFilePath);
const isSourceStandalone = isStandaloneApp(tree, mainFilePath);
console.log('isSourceStandalone ---->>>>', isSourceStandalone);
const pascalName = pascal(packageName);
const routePath = `${kebab(packageName)}`;
const moduleName = `${pascalName}Module`;
if (isSourceStandalone) {
const appRoutesPath = `${project?.sourceRoot}/app/app.routes.ts`;
const appRoutesPath =
findAppRoutesPath(tree, mainFilePath) || `${project?.sourceRoot}/app/app.routes.ts`;
const buffer = tree.read(appRoutesPath);
if (!buffer) {
throw new SchematicsException(`Cannot find routes file: ${appRoutesPath}`);

Loading…
Cancel
Save