forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.js
executable file
·55 lines (45 loc) · 1.2 KB
/
cmd.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
'use strict'
const exec = require('child_process').exec
const chalk = require('chalk')
const args = process.argv.splice(2)
const help = require('help')()
const Commit = require('../commit')
const format = require('../format')
if (!args.length) return help()
for (const arg of args) {
if (arg === 'help' || arg === '--help' || arg === '-h') {
return help()
}
if (arg === 'version' || arg === '--version' || arg === '-v') {
console.log('core-validate-commit', 'v' + require('../package').version)
return
}
}
function getCommitCommand(sha) {
return `git show --quiet ${sha}`
}
;(function run() {
if (!args.length) return
const sha = args.shift()
exec(getCommitCommand(sha), (err, stdout, stderr) => {
if (err) throw err
const c = new Commit(stdout)
if (c.errors.length) {
console.log()
console.log(format.header(c))
}
c.errors.forEach((m) => {
if (format[m.code]) {
console.error(format[m.code](m, c))
} else {
console.error(format.default(m, c))
}
process.exitCode = 1
})
c.warnings.forEach((m) => {
console.error(' ', chalk.yellow(m.code), chalk.grey(m.str))
})
run()
})
})()