Browse Source

format file func added

pull/22645/head
erdemcaygor 1 year ago
parent
commit
331c2bec8e
  1. 15
      npm/ng-packs/packages/schematics/src/commands/change-theme/index.ts

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

@ -79,6 +79,7 @@ function updateAppModule(selectedProject: string, targetThemeName: ThemeOptionsE
: removeProviderFromNgModuleMetadata(appModulePath, targetThemeName),
insertImports(selectedProject, targetThemeName),
insertProviders(selectedProject, targetThemeName),
formatFile(appModulePath),
]);
};
}
@ -352,3 +353,17 @@ export const getAppConfigPath = (host: Tree, mainFilePath: string): string => {
const appConfig = findAppConfig(bootstrapCall, host, mainFilePath);
return appConfig?.filePath || '';
};
export const formatFile = (filePath: string): Rule => {
return (tree: Tree) => {
const buffer = tree.read(filePath);
if (!buffer) return tree;
const source = ts.createSourceFile(filePath, buffer.toString(), ts.ScriptTarget.Latest, true);
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
const formatted = printer.printFile(source);
tree.overwrite(filePath, formatted);
return tree;
};
};

Loading…
Cancel
Save