generated from voxpelli/node-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
26 lines (20 loc) · 691 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env node
/* eslint-disable no-console */
let commitMessage = '';
if (process.stdin.isTTY) {
console.error('No input was sent to commit message validator');
process.exit(1);
}
for await (const item of process.stdin) {
commitMessage += item;
}
if (commitMessage.trim() === '') {
console.error('Empty commit message');
process.exit(1);
}
// eslint-disable-next-line regexp/no-unused-capturing-group
const conventionalCommitMessage = /^(?<type>\w+)(?:\((?<scope>\w+)\))?(?<breaking>!?): (?<description>[^\n]+)/;
if (!conventionalCommitMessage.test(commitMessage)) {
console.error('Invalid commit message, does not follow conventional commits');
process.exit(1);
}