forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·45 lines (42 loc) · 1.2 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
const path = require('path')
const printError = require('./lib/print-error')
const bump = require('./lib/lifecycles/bump')
const changelog = require('./lib/lifecycles/changelog')
const commit = require('./lib/lifecycles/commit')
const tag = require('./lib/lifecycles/tag')
module.exports = function standardVersion (argv) {
var pkg
bump.pkgFiles.forEach((filename) => {
if (pkg) return
var pkgPath = path.resolve(process.cwd(), filename)
try {
pkg = require(pkgPath)
} catch (err) {}
})
if (!pkg) {
return Promise.reject(new Error('no package file found'))
}
var newVersion = pkg.version
var defaults = require('./defaults')
var args = Object.assign({}, defaults, argv)
return Promise.resolve()
.then(() => {
return bump(args, pkg)
})
.then((_newVersion) => {
// if bump runs, it calculaes the new version that we
// should release at.
if (_newVersion) newVersion = _newVersion
return changelog(args, newVersion)
})
.then(() => {
return commit(args, newVersion)
})
.then(() => {
return tag(newVersion, pkg.private, args)
})
.catch((err) => {
printError(args, err.message)
throw err
})
}