UNPKG

1.52 kBJavaScriptView Raw
1const bump = require('../lifecycles/bump')
2const checkpoint = require('../checkpoint')
3const formatCommitMessage = require('../format-commit-message')
4const path = require('path')
5const runExec = require('../run-exec')
6const runLifecycleScript = require('../run-lifecycle-script')
7
8module.exports = function (args, newVersion) {
9 if (args.skip.commit) return Promise.resolve()
10 return runLifecycleScript(args, 'precommit')
11 .then((message) => {
12 if (message && message.length) args.message = message
13 return execCommit(args, newVersion)
14 })
15 .then(() => {
16 return runLifecycleScript(args, 'postcommit')
17 })
18}
19
20function execCommit (args, newVersion) {
21 let msg = 'committing %s'
22 let paths = [args.infile]
23 let verify = args.verify === false || args.n ? '--no-verify ' : ''
24 let toAdd = ''
25 // commit any of the config files that we've updated
26 // the version # for.
27 Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
28 if (bump.getUpdatedConfigs()[p]) {
29 msg += ' and %s'
30 paths.unshift(path.basename(p))
31 toAdd += ' ' + path.relative(process.cwd(), p)
32 }
33 })
34
35 if (args.commitAll) {
36 msg += ' and %s'
37 paths.push('all staged files')
38 }
39
40 checkpoint(args, msg, paths)
41 return runExec(args, 'git add' + toAdd + ' ' + args.infile)
42 .then(() => {
43 return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (args.infile + toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"')
44 })
45}