forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·33 lines (29 loc) · 716 Bytes
/
cli.js
File metadata and controls
executable file
·33 lines (29 loc) · 716 Bytes
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
27
28
29
30
31
32
33
#!/usr/bin/env node
const execa = require('execa');
const inquirer = require('inquirer');
const {prompter} = require('@commitlint/prompt');
main().catch((err) => {
setTimeout(() => {
throw err;
});
});
function main() {
return isStageEmpty()
.then((empty) => {
if (empty) {
console.log(
`Nothing to commit. Stage your changes via "git add" execute "commit" again`
);
process.exit(1);
}
})
.then(() => prompter(inquirer, commit));
}
function isStageEmpty() {
return execa('git', ['diff', '--cached']).then((r) => r.stdout === '');
}
function commit(message) {
const c = execa('git', ['commit', '-m', message]);
c.stdout.pipe(process.stdout);
c.stderr.pipe(process.stderr);
}