Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
fix(prettier): overwrite existing .prettierrc
Browse files Browse the repository at this point in the history
- workaorund introduce due angular/angular-cli#11337
  • Loading branch information
GregOnNet committed Mar 17, 2019
1 parent 7fc468d commit 9910d76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/prettier/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ describe('When prettier is already configured', () => {
project.create('package.json', JSON.stringify(packageBeforeInstall));
});

it(' should warn if configuration is detected in package.json', () => {
it('should warn if configuration is detected in package.json', () => {
runner.runSchematic('prettier', {}, project);
expect(warn).toHaveBeenCalledWith(
'Found competing prettier configuration in package.json.'
);
});

it.each([
['.prettierrc.yaml'],
['.prettierrc.yml'],
Expand Down
25 changes: 19 additions & 6 deletions src/prettier/rules/prettier/configure-prettier.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import {
apply,
chain,
forEach,
MergeStrategy,
mergeWith,
Rule,
Tree,
url
} from '@angular-devkit/schematics';
import { installDependencies } from '../../../lib';

export function configurePrettier(): Rule {
return chain([
installDependencies({
devDependencies: ['prettier', 'tslint-config-prettier']
}),
mergeWith(apply(url('./templates/prettier'), []), MergeStrategy.Overwrite)
]);
return (tree: Tree) =>
chain([
installDependencies({
devDependencies: ['prettier', 'tslint-config-prettier']
}),
mergeWith(
apply(url('./templates/prettier'), [
forEach(template => {
tree.exists(template.path)
? tree.overwrite(template.path, template.content)
: tree.create(template.path, template.content);
return null;
})
]),
MergeStrategy.Overwrite
)
]);
}

0 comments on commit 9910d76

Please sign in to comment.