forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·72 lines (69 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const bump = require('./lib/lifecycles/bump')
const changelog = require('./lib/lifecycles/changelog')
const commit = require('./lib/lifecycles/commit')
const fs = require('fs')
const latestSemverTag = require('./lib/latest-semver-tag')
const path = require('path')
const printError = require('./lib/print-error')
const tag = require('./lib/lifecycles/tag')
module.exports = function standardVersion (argv) {
/**
* `--message` (`-m`) support will be removed in the next major version.
*/
const message = argv.m || argv.message
if (message) {
/**
* The `--message` flag uses `%s` for version substitutions, we swap this
* for the substitution defined in the config-spec for future-proofing upstream
* handling.
*/
argv.releaseCommitMessageFormat = message.replace(/%s/g, '{{currentTag}}')
if (!argv.silent) {
console.warn('[standard-version]: --message (-m) will be removed in the next major release. Use --releaseCommitMessageFormat.')
}
}
let pkg
bump.pkgFiles.forEach((filename) => {
if (pkg) return
const pkgPath = path.resolve(process.cwd(), filename)
try {
const data = fs.readFileSync(pkgPath, 'utf8')
pkg = JSON.parse(data)
} catch (err) {}
})
let newVersion
const defaults = require('./defaults')
const args = Object.assign({}, defaults, argv)
return Promise.resolve()
.then(() => {
if (!pkg && args.gitTagFallback) {
return latestSemverTag()
} else if (!pkg) {
throw new Error('no package file found')
} else {
return pkg.version
}
})
.then(version => {
newVersion = version
})
.then(() => {
return bump(args, newVersion)
})
.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 ? pkg.private : false, args)
})
.catch((err) => {
printError(args, err.message)
throw err
})
}