Skip to content

Commit dcb7152

Browse files
committed
added again
1 parent a36cc29 commit dcb7152

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

bin/has-commit-message.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
// exits with 0 if there is a commit JSON message
6+
// exits with 1 if there is NO commit JSON message
7+
8+
const allArgs = process.argv.slice(2)
9+
const args = require('minimist')(allArgs, {
10+
alias: {
11+
file: 'f',
12+
sha: 'commit'
13+
},
14+
string: ['file', 'sha']
15+
})
16+
17+
const api = require('..')
18+
const getMessage = api.getMessage
19+
const getJsonBlock = api.getJsonBlock
20+
21+
function onError (e) {
22+
console.error(e)
23+
process.exit(1)
24+
}
25+
26+
let start
27+
if (args.file) {
28+
console.log('loading message from file', args.file)
29+
const fs = require('fs')
30+
const message = fs.readFileSync(args.file, 'utf8')
31+
start = Promise.resolve(message)
32+
} else {
33+
start = getMessage(args.sha)
34+
}
35+
start
36+
.then(getJsonBlock)
37+
.then(json => {
38+
if (!json) {
39+
console.log('cannot find JSON install block')
40+
process.exit(1)
41+
}
42+
console.log('found JSON install block')
43+
process.exit(0)
44+
})
45+
.catch(onError)

0 commit comments

Comments
 (0)