nx/scripts/commit-lint.js
ben f93d8e3d36 fix(command-line): add ng command test on affected parallel
When running the affected command with the `--parallel` option, `npm-run-all` is used to achieve the parallel execution of the desired tasks. Because of the use of `npm-run-all`, the `ng` command should be visible and declared as script command in the `package.json` of your project.

This adds a verification before runing the command with the `--parallel` option to make sure the `package.json` has the `ng: "ng"` command in the `scripts` section.

close #700
2018-08-23 11:24:55 -04:00

29 lines
876 B
JavaScript
Executable File

#!/usr/bin/env node
console.log('🐟🐟🐟 Validating git commit message 🐟🐟🐟');
const gitMessage = require('child_process')
.execSync('git log -1 --no-merges')
.toString()
.trim();
const matchTest = /([a-z]){0,8}\([a-z.0-9\-]+\):\s(([a-z0-9:\-\s])+)/g.test(
gitMessage
);
const exitCode = +!matchTest;
if (exitCode === 0) {
console.log('Commit ACCEPTED 👌');
} else {
console.log(
'[Error]: Ho no! 😦 Your commit message: \n' +
gitMessage +
'\ndoes not follow the commit message convention specified in the CONTRIBUTING.MD file.'
);
console.log('\ntype(scope): subject \n BLANK LINE \n body');
console.log(
'\nExample: \n ' +
'feat(schematics): add an option to generate lazy-loadable modules\n' +
'\n`ng generate lib mylib --lazy` provisions the mylib project in tslint.json'
);
}
process.exit(exitCode);