Skip to content

Commit

Permalink
fix(module:code-style): upgrade husky (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Oct 11, 2018
1 parent ad43622 commit 61c6214
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/schematics/plugin/plugin.code-style.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('NgAlainSchematic: plugin: codeStyle', () => {
describe('when add', () => {
it(`should add precommit`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.scripts.precommit).not.toBeUndefined();
expect(json.husky).not.toBeUndefined();
});
});

Expand All @@ -27,7 +27,7 @@ describe('NgAlainSchematic: plugin: codeStyle', () => {

it(`should remove precommit`, () => {
const json = JSON.parse(tree.readContent('package.json'));
expect(json.scripts.precommit).toBeUndefined();
expect(json.husky).toBeUndefined();
});
});
});
24 changes: 16 additions & 8 deletions packages/schematics/plugin/plugin.code-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ import { PluginOptions } from './interface';
import {
addPackageToPackageJson,
removePackageFromPackageJson,
getJSON,
overwritePackage,
} from '../utils/json';

export function pluginCodeStyle(options: PluginOptions): any {
return (host: Tree, context: SchematicContext) => {
// package
(options.type === 'add'
? addPackageToPackageJson
: removePackageFromPackageJson)(
host,
['precommit@npm run lint-staged'],
'scripts',
);
const json = getJSON(host, 'package.json');
if (json == null) return;

if (options.type === 'add') {
json.husky = {
hooks: {
'pre-commit': 'npm run lint-staged',
},
};
} else {
delete json.husky;
}

overwritePackage(host, json);
};
}

0 comments on commit 61c6214

Please sign in to comment.