-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.09 KB
/
index.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
'use strict'
const { accessSync, F_OK, writeFileSync } = require('fs')
const chalk = require('chalk')
const core = require('conventional-changelog-core')
const strat = require('strat')
const config = require('./config')
const isWin = process.platform === 'win32'
const tick = isWin ? '√' : '✔'
const cross = isWin ? '×' : '✖'
let lines = 0
const notify = (msg, args) =>
++lines && console.info(
`${lines ? '' : '\n'}${chalk.green(tick)} ` +
strat(msg, args.map(arg => chalk.bold(arg))) + '\n'
)
const fail = msg =>
console.error(`${lines ? '' : '\n'}${chalk.red(cross)} ${msg}\n`) ||
process.exit(1)
const ensureExists = atPath => {
try {
accessSync(atPath, F_OK)
} catch (e) {
if (e.code === 'ENOENT') {
notify('created {}', [atPath])
writeFileSync(atPath, '\n', 'utf-8')
}
}
}
const generate = (options, context, gitRawCommitsOpts, parserOpts, writerOpts) => {
options = options || {}
options.config = config
return core(options, context, gitRawCommitsOpts, parserOpts, writerOpts)
}
module.exports = {
ensureExists,
fail,
generate,
notify
}