Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import { Rule, Tree } from '@angular-devkit/schematics';
  2. import * as prettier from 'prettier';
  3. import { Observable } from 'rxjs';
  4.  
  5. export default function(): Rule {
  6. return (tree: Tree) =>
  7. new Observable<Tree>(o => {
  8. prettier.resolveConfig(process.cwd()).then(prettierConfig => {
  9. if (!prettierConfig) {
  10. o.error(new Error('Could not resolve prettier configuration'));
  11. return;
  12. }
  13.  
  14. tree.visit(path => {
  15. if (path.endsWith('.tsx') || path.endsWith('.ts') || path.endsWith('.jsx') || path.endsWith('.js')) {
  16. const content = tree.read(path);
  17. if (content) {
  18. const formatted = prettier.format(content.toString(), prettierConfig);
  19. tree.overwrite(path, formatted);
  20. }
  21. }
  22.  
  23. return false;
  24. });
  25. o.next(tree);
  26. o.complete();
  27. });
  28. });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement