Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Rule, Tree } from '@angular-devkit/schematics';
- import * as prettier from 'prettier';
- import { Observable } from 'rxjs';
- export default function(): Rule {
- return (tree: Tree) =>
- new Observable<Tree>(o => {
- prettier.resolveConfig(process.cwd()).then(prettierConfig => {
- if (!prettierConfig) {
- o.error(new Error('Could not resolve prettier configuration'));
- return;
- }
- tree.visit(path => {
- if (path.endsWith('.tsx') || path.endsWith('.ts') || path.endsWith('.jsx') || path.endsWith('.js')) {
- const content = tree.read(path);
- if (content) {
- const formatted = prettier.format(content.toString(), prettierConfig);
- tree.overwrite(path, formatted);
- }
- }
- return false;
- });
- o.next(tree);
- o.complete();
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement