commit-and-tag-version 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +9 -0
- package/.eslintrc +6 -0
- package/.github/ISSUE_TEMPLATE/ask-a-question.md +7 -0
- package/.github/ISSUE_TEMPLATE/bug-report.md +29 -0
- package/.github/workflows/ci.yaml +33 -0
- package/.github/workflows/release-please.yml +31 -0
- package/.versionrc +10 -0
- package/CHANGELOG.md +524 -0
- package/LICENSE.txt +16 -0
- package/README.md +480 -0
- package/bin/cli.js +14 -0
- package/command.js +145 -0
- package/defaults.js +40 -0
- package/index.js +92 -0
- package/lib/checkpoint.js +12 -0
- package/lib/configuration.js +41 -0
- package/lib/format-commit-message.js +4 -0
- package/lib/latest-semver-tag.js +17 -0
- package/lib/lifecycles/bump.js +172 -0
- package/lib/lifecycles/changelog.js +66 -0
- package/lib/lifecycles/commit.js +69 -0
- package/lib/lifecycles/tag.js +39 -0
- package/lib/preset-loader.js +17 -0
- package/lib/print-error.js +12 -0
- package/lib/run-exec.js +18 -0
- package/lib/run-execFile.js +18 -0
- package/lib/run-lifecycle-script.js +13 -0
- package/lib/updaters/index.js +85 -0
- package/lib/updaters/types/json.js +25 -0
- package/lib/updaters/types/plain-text.js +7 -0
- package/lib/write-file.js +6 -0
- package/package.json +69 -0
- package/renovate.json +9 -0
- package/test/config-files.spec.js +179 -0
- package/test/core.spec.js +850 -0
- package/test/git.spec.js +468 -0
- package/test/mocks/VERSION-1.0.0.txt +1 -0
- package/test/mocks/VERSION-6.3.1.txt +1 -0
- package/test/mocks/manifest-6.3.1.json +3 -0
- package/test/mocks/mix.exs +28 -0
- package/test/mocks/updater/customer-updater.js +12 -0
- package/test/mocks/version.txt +0 -0
- package/test/preset.spec.js +52 -0
package/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const bump = require('./lib/lifecycles/bump')
|
|
2
|
+
const changelog = require('./lib/lifecycles/changelog')
|
|
3
|
+
const commit = require('./lib/lifecycles/commit')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const latestSemverTag = require('./lib/latest-semver-tag')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const printError = require('./lib/print-error')
|
|
8
|
+
const tag = require('./lib/lifecycles/tag')
|
|
9
|
+
const { resolveUpdaterObjectFromArgument } = require('./lib/updaters')
|
|
10
|
+
|
|
11
|
+
module.exports = async function standardVersion (argv) {
|
|
12
|
+
const defaults = require('./defaults')
|
|
13
|
+
/**
|
|
14
|
+
* `--message` (`-m`) support will be removed in the next major version.
|
|
15
|
+
*/
|
|
16
|
+
const message = argv.m || argv.message
|
|
17
|
+
if (message) {
|
|
18
|
+
/**
|
|
19
|
+
* The `--message` flag uses `%s` for version substitutions, we swap this
|
|
20
|
+
* for the substitution defined in the config-spec for future-proofing upstream
|
|
21
|
+
* handling.
|
|
22
|
+
*/
|
|
23
|
+
argv.releaseCommitMessageFormat = message.replace(/%s/g, '{{currentTag}}')
|
|
24
|
+
if (!argv.silent) {
|
|
25
|
+
console.warn(
|
|
26
|
+
'[commit-and-tag-version]: --message (-m) will be removed in the next major release. Use --releaseCommitMessageFormat.'
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (argv.changelogHeader) {
|
|
32
|
+
argv.header = argv.changelogHeader
|
|
33
|
+
if (!argv.silent) {
|
|
34
|
+
console.warn(
|
|
35
|
+
'[commit-and-tag-version]: --changelogHeader will be removed in the next major release. Use --header.'
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
argv.header &&
|
|
42
|
+
argv.header.search(changelog.START_OF_LAST_RELEASE_PATTERN) !== -1
|
|
43
|
+
) {
|
|
44
|
+
throw Error(
|
|
45
|
+
`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* If an argument for `packageFiles` provided, we include it as a "default" `bumpFile`.
|
|
51
|
+
*/
|
|
52
|
+
if (argv.packageFiles) {
|
|
53
|
+
defaults.bumpFiles = defaults.bumpFiles.concat(argv.packageFiles)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const args = Object.assign({}, defaults, argv)
|
|
57
|
+
let pkg
|
|
58
|
+
for (const packageFile of args.packageFiles) {
|
|
59
|
+
const updater = resolveUpdaterObjectFromArgument(packageFile)
|
|
60
|
+
if (!updater) return
|
|
61
|
+
const pkgPath = path.resolve(process.cwd(), updater.filename)
|
|
62
|
+
try {
|
|
63
|
+
const contents = fs.readFileSync(pkgPath, 'utf8')
|
|
64
|
+
pkg = {
|
|
65
|
+
version: updater.updater.readVersion(contents),
|
|
66
|
+
private:
|
|
67
|
+
typeof updater.updater.isPrivate === 'function'
|
|
68
|
+
? updater.updater.isPrivate(contents)
|
|
69
|
+
: false
|
|
70
|
+
}
|
|
71
|
+
break
|
|
72
|
+
} catch (err) {}
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
let version
|
|
76
|
+
if (pkg) {
|
|
77
|
+
version = pkg.version
|
|
78
|
+
} else if (args.gitTagFallback) {
|
|
79
|
+
version = await latestSemverTag(args.tagPrefix)
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error('no package file found')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const newVersion = await bump(args, version)
|
|
85
|
+
await changelog(args, newVersion)
|
|
86
|
+
await commit(args, newVersion)
|
|
87
|
+
await tag(newVersion, pkg ? pkg.private : false, args)
|
|
88
|
+
} catch (err) {
|
|
89
|
+
printError(args, err.message)
|
|
90
|
+
throw err
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const figures = require('figures')
|
|
3
|
+
const util = require('util')
|
|
4
|
+
|
|
5
|
+
module.exports = function (argv, msg, args, figure) {
|
|
6
|
+
const defaultFigure = args.dryRun ? chalk.yellow(figures.tick) : chalk.green(figures.tick)
|
|
7
|
+
if (!argv.silent) {
|
|
8
|
+
console.info((figure || defaultFigure) + ' ' + util.format.apply(util, [msg].concat(args.map(function (arg) {
|
|
9
|
+
return chalk.bold(arg)
|
|
10
|
+
}))))
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const findUp = require('find-up')
|
|
3
|
+
const { readFileSync } = require('fs')
|
|
4
|
+
|
|
5
|
+
const CONFIGURATION_FILES = [
|
|
6
|
+
'.versionrc',
|
|
7
|
+
'.versionrc.cjs',
|
|
8
|
+
'.versionrc.json',
|
|
9
|
+
'.versionrc.js'
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
module.exports.getConfiguration = function () {
|
|
13
|
+
let config = {}
|
|
14
|
+
const configPath = findUp.sync(CONFIGURATION_FILES)
|
|
15
|
+
if (!configPath) {
|
|
16
|
+
return config
|
|
17
|
+
}
|
|
18
|
+
const ext = path.extname(configPath)
|
|
19
|
+
if (ext === '.js' || ext === '.cjs') {
|
|
20
|
+
const jsConfiguration = require(configPath)
|
|
21
|
+
if (typeof jsConfiguration === 'function') {
|
|
22
|
+
config = jsConfiguration()
|
|
23
|
+
} else {
|
|
24
|
+
config = jsConfiguration
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
config = JSON.parse(readFileSync(configPath))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @todo we could eventually have deeper validation of the configuration (using `ajv`) and
|
|
32
|
+
* provide a more helpful error.
|
|
33
|
+
*/
|
|
34
|
+
if (typeof config !== 'object') {
|
|
35
|
+
throw Error(
|
|
36
|
+
`[commit-and-tag-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return config
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const gitSemverTags = require('git-semver-tags')
|
|
2
|
+
const semver = require('semver')
|
|
3
|
+
|
|
4
|
+
module.exports = function (tagPrefix = undefined) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
gitSemverTags({ tagPrefix }, function (err, tags) {
|
|
7
|
+
if (err) return reject(err)
|
|
8
|
+
else if (!tags.length) return resolve('1.0.0')
|
|
9
|
+
// Respect tagPrefix
|
|
10
|
+
tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), ''))
|
|
11
|
+
// ensure that the largest semver tag is at the head.
|
|
12
|
+
tags = tags.map(tag => { return semver.clean(tag) })
|
|
13
|
+
tags.sort(semver.rcompare)
|
|
14
|
+
return resolve(tags[0])
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk')
|
|
4
|
+
const checkpoint = require('../checkpoint')
|
|
5
|
+
const conventionalRecommendedBump = require('conventional-recommended-bump')
|
|
6
|
+
const figures = require('figures')
|
|
7
|
+
const fs = require('fs')
|
|
8
|
+
const DotGitignore = require('dotgitignore')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
const presetLoader = require('../preset-loader')
|
|
11
|
+
const runLifecycleScript = require('../run-lifecycle-script')
|
|
12
|
+
const semver = require('semver')
|
|
13
|
+
const writeFile = require('../write-file')
|
|
14
|
+
const { resolveUpdaterObjectFromArgument } = require('../updaters')
|
|
15
|
+
let configsToUpdate = {}
|
|
16
|
+
|
|
17
|
+
async function Bump (args, version) {
|
|
18
|
+
// reset the cache of updated config files each
|
|
19
|
+
// time we perform the version bump step.
|
|
20
|
+
configsToUpdate = {}
|
|
21
|
+
|
|
22
|
+
if (args.skip.bump) return version
|
|
23
|
+
let newVersion = version
|
|
24
|
+
await runLifecycleScript(args, 'prerelease')
|
|
25
|
+
const stdout = await runLifecycleScript(args, 'prebump')
|
|
26
|
+
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
|
|
27
|
+
const release = await bumpVersion(args.releaseAs, version, args)
|
|
28
|
+
if (!args.firstRelease) {
|
|
29
|
+
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
|
|
30
|
+
newVersion = semver.valid(releaseType) || semver.inc(version, releaseType, args.prerelease)
|
|
31
|
+
updateConfigs(args, newVersion)
|
|
32
|
+
} else {
|
|
33
|
+
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
|
|
34
|
+
}
|
|
35
|
+
await runLifecycleScript(args, 'postbump')
|
|
36
|
+
return newVersion
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Bump.getUpdatedConfigs = function () {
|
|
40
|
+
return configsToUpdate
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
|
|
44
|
+
if (isString(prerelease)) {
|
|
45
|
+
if (isInPrerelease(currentVersion)) {
|
|
46
|
+
if (shouldContinuePrerelease(currentVersion, expectedReleaseType) ||
|
|
47
|
+
getTypePriority(getCurrentActiveType(currentVersion)) > getTypePriority(expectedReleaseType)
|
|
48
|
+
) {
|
|
49
|
+
return 'prerelease'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return 'pre' + expectedReleaseType
|
|
54
|
+
} else {
|
|
55
|
+
return expectedReleaseType
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isString (val) {
|
|
60
|
+
return typeof val === 'string'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* if a version is currently in pre-release state,
|
|
65
|
+
* and if it current in-pre-release type is same as expect type,
|
|
66
|
+
* it should continue the pre-release with the same type
|
|
67
|
+
*
|
|
68
|
+
* @param version
|
|
69
|
+
* @param expectType
|
|
70
|
+
* @return {boolean}
|
|
71
|
+
*/
|
|
72
|
+
function shouldContinuePrerelease (version, expectType) {
|
|
73
|
+
return getCurrentActiveType(version) === expectType
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isInPrerelease (version) {
|
|
77
|
+
return Array.isArray(semver.prerelease(version))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const TypeList = ['major', 'minor', 'patch'].reverse()
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* extract the in-pre-release type in target version
|
|
84
|
+
*
|
|
85
|
+
* @param version
|
|
86
|
+
* @return {string}
|
|
87
|
+
*/
|
|
88
|
+
function getCurrentActiveType (version) {
|
|
89
|
+
const typelist = TypeList
|
|
90
|
+
for (let i = 0; i < typelist.length; i++) {
|
|
91
|
+
if (semver[typelist[i]](version)) {
|
|
92
|
+
return typelist[i]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* calculate the priority of release type,
|
|
99
|
+
* major - 2, minor - 1, patch - 0
|
|
100
|
+
*
|
|
101
|
+
* @param type
|
|
102
|
+
* @return {number}
|
|
103
|
+
*/
|
|
104
|
+
function getTypePriority (type) {
|
|
105
|
+
return TypeList.indexOf(type)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function bumpVersion (releaseAs, currentVersion, args) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
if (releaseAs) {
|
|
111
|
+
return resolve({
|
|
112
|
+
releaseType: releaseAs
|
|
113
|
+
})
|
|
114
|
+
} else {
|
|
115
|
+
const presetOptions = presetLoader(args)
|
|
116
|
+
if (typeof presetOptions === 'object') {
|
|
117
|
+
if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true
|
|
118
|
+
}
|
|
119
|
+
conventionalRecommendedBump({
|
|
120
|
+
debug: args.verbose && console.info.bind(console, 'conventional-recommended-bump'),
|
|
121
|
+
preset: presetOptions,
|
|
122
|
+
path: args.path,
|
|
123
|
+
tagPrefix: args.tagPrefix,
|
|
124
|
+
lernaPackage: args.lernaPackage
|
|
125
|
+
}, function (err, release) {
|
|
126
|
+
if (err) return reject(err)
|
|
127
|
+
else return resolve(release)
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* attempt to update the version number in provided `bumpFiles`
|
|
135
|
+
* @param args config object
|
|
136
|
+
* @param newVersion version number to update to.
|
|
137
|
+
* @return void
|
|
138
|
+
*/
|
|
139
|
+
function updateConfigs (args, newVersion) {
|
|
140
|
+
const dotgit = DotGitignore()
|
|
141
|
+
args.bumpFiles.forEach(function (bumpFile) {
|
|
142
|
+
const updater = resolveUpdaterObjectFromArgument(bumpFile)
|
|
143
|
+
if (!updater) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
const configPath = path.resolve(process.cwd(), updater.filename)
|
|
147
|
+
try {
|
|
148
|
+
if (dotgit.ignore(configPath)) return
|
|
149
|
+
const stat = fs.lstatSync(configPath)
|
|
150
|
+
|
|
151
|
+
if (!stat.isFile()) return
|
|
152
|
+
const contents = fs.readFileSync(configPath, 'utf8')
|
|
153
|
+
checkpoint(
|
|
154
|
+
args,
|
|
155
|
+
'bumping version in ' + updater.filename + ' from %s to %s',
|
|
156
|
+
[updater.updater.readVersion(contents), newVersion]
|
|
157
|
+
)
|
|
158
|
+
writeFile(
|
|
159
|
+
args,
|
|
160
|
+
configPath,
|
|
161
|
+
updater.updater.writeVersion(contents, newVersion)
|
|
162
|
+
)
|
|
163
|
+
// flag any config files that we modify the version # for
|
|
164
|
+
// as having been updated.
|
|
165
|
+
configsToUpdate[updater.filename] = true
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (err.code !== 'ENOENT') console.warn(err.message)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = Bump
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const checkpoint = require('../checkpoint')
|
|
3
|
+
const conventionalChangelog = require('conventional-changelog')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const presetLoader = require('../preset-loader')
|
|
6
|
+
const runLifecycleScript = require('../run-lifecycle-script')
|
|
7
|
+
const writeFile = require('../write-file')
|
|
8
|
+
const START_OF_LAST_RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m
|
|
9
|
+
|
|
10
|
+
async function Changelog (args, newVersion) {
|
|
11
|
+
if (args.skip.changelog) return
|
|
12
|
+
await runLifecycleScript(args, 'prechangelog')
|
|
13
|
+
await outputChangelog(args, newVersion)
|
|
14
|
+
await runLifecycleScript(args, 'postchangelog')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN
|
|
18
|
+
|
|
19
|
+
module.exports = Changelog
|
|
20
|
+
|
|
21
|
+
function outputChangelog (args, newVersion) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
createIfMissing(args)
|
|
24
|
+
const header = args.header
|
|
25
|
+
|
|
26
|
+
let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')
|
|
27
|
+
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
|
|
28
|
+
// find the position of the last release and remove header:
|
|
29
|
+
if (oldContentStart !== -1) {
|
|
30
|
+
oldContent = oldContent.substring(oldContentStart)
|
|
31
|
+
}
|
|
32
|
+
let content = ''
|
|
33
|
+
const context = { version: newVersion }
|
|
34
|
+
const changelogStream = conventionalChangelog({
|
|
35
|
+
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
|
|
36
|
+
preset: presetLoader(args),
|
|
37
|
+
tagPrefix: args.tagPrefix
|
|
38
|
+
}, context, { merges: null, path: args.path })
|
|
39
|
+
.on('error', function (err) {
|
|
40
|
+
return reject(err)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
changelogStream.on('data', function (buffer) {
|
|
44
|
+
content += buffer.toString()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
changelogStream.on('end', function () {
|
|
48
|
+
checkpoint(args, 'outputting changes to %s', [args.infile])
|
|
49
|
+
if (args.dryRun) console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`)
|
|
50
|
+
else writeFile(args, args.infile, header + '\n' + (content + oldContent).replace(/\n+$/, '\n'))
|
|
51
|
+
return resolve()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createIfMissing (args) {
|
|
57
|
+
try {
|
|
58
|
+
fs.accessSync(args.infile, fs.F_OK)
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (err.code === 'ENOENT') {
|
|
61
|
+
checkpoint(args, 'created %s', [args.infile])
|
|
62
|
+
args.outputUnreleased = true
|
|
63
|
+
writeFile(args, args.infile, '\n')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const bump = require('../lifecycles/bump')
|
|
2
|
+
const checkpoint = require('../checkpoint')
|
|
3
|
+
const formatCommitMessage = require('../format-commit-message')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const runExecFile = require('../run-execFile')
|
|
6
|
+
const runLifecycleScript = require('../run-lifecycle-script')
|
|
7
|
+
|
|
8
|
+
module.exports = async function (args, newVersion) {
|
|
9
|
+
if (args.skip.commit) return
|
|
10
|
+
const message = await runLifecycleScript(args, 'precommit')
|
|
11
|
+
if (message && message.length) args.releaseCommitMessageFormat = message
|
|
12
|
+
await execCommit(args, newVersion)
|
|
13
|
+
await runLifecycleScript(args, 'postcommit')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function execCommit (args, newVersion) {
|
|
17
|
+
let msg = 'committing %s'
|
|
18
|
+
let paths = []
|
|
19
|
+
const verify = args.verify === false || args.n ? ['--no-verify'] : []
|
|
20
|
+
const sign = args.sign ? ['-S'] : []
|
|
21
|
+
const toAdd = []
|
|
22
|
+
|
|
23
|
+
// only start with a pre-populated paths list when CHANGELOG processing is not skipped
|
|
24
|
+
if (!args.skip.changelog) {
|
|
25
|
+
paths = [args.infile]
|
|
26
|
+
toAdd.push(args.infile)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// commit any of the config files that we've updated
|
|
30
|
+
// the version # for.
|
|
31
|
+
Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
|
|
32
|
+
paths.unshift(p)
|
|
33
|
+
toAdd.push(path.relative(process.cwd(), p))
|
|
34
|
+
|
|
35
|
+
// account for multiple files in the output message
|
|
36
|
+
if (paths.length > 1) {
|
|
37
|
+
msg += ' and %s'
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (args.commitAll) {
|
|
42
|
+
msg += ' and %s'
|
|
43
|
+
paths.push('all staged files')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
checkpoint(args, msg, paths)
|
|
47
|
+
|
|
48
|
+
// nothing to do, exit without commit anything
|
|
49
|
+
if (args.skip.changelog && args.skip.bump && toAdd.length === 0) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await runExecFile(args, 'git', ['add'].concat(toAdd))
|
|
54
|
+
await runExecFile(
|
|
55
|
+
args,
|
|
56
|
+
'git',
|
|
57
|
+
[
|
|
58
|
+
'commit'
|
|
59
|
+
].concat(
|
|
60
|
+
verify,
|
|
61
|
+
sign,
|
|
62
|
+
args.commitAll ? [] : toAdd,
|
|
63
|
+
[
|
|
64
|
+
'-m',
|
|
65
|
+
`${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`
|
|
66
|
+
]
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const bump = require('../lifecycles/bump')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
const checkpoint = require('../checkpoint')
|
|
4
|
+
const figures = require('figures')
|
|
5
|
+
const formatCommitMessage = require('../format-commit-message')
|
|
6
|
+
const runExecFile = require('../run-execFile')
|
|
7
|
+
const runLifecycleScript = require('../run-lifecycle-script')
|
|
8
|
+
|
|
9
|
+
module.exports = async function (newVersion, pkgPrivate, args) {
|
|
10
|
+
if (args.skip.tag) return
|
|
11
|
+
await runLifecycleScript(args, 'pretag')
|
|
12
|
+
await execTag(newVersion, pkgPrivate, args)
|
|
13
|
+
await runLifecycleScript(args, 'posttag')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function execTag (newVersion, pkgPrivate, args) {
|
|
17
|
+
let tagOption
|
|
18
|
+
if (args.sign) {
|
|
19
|
+
tagOption = '-s'
|
|
20
|
+
} else {
|
|
21
|
+
tagOption = '-a'
|
|
22
|
+
}
|
|
23
|
+
checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion])
|
|
24
|
+
await runExecFile(args, 'git', ['tag', tagOption, args.tagPrefix + newVersion, '-m', `${formatCommitMessage(args.releaseCommitMessageFormat, newVersion)}`])
|
|
25
|
+
const currentBranch = await runExecFile('', 'git', ['rev-parse', '--abbrev-ref', 'HEAD'])
|
|
26
|
+
let message = 'git push --follow-tags origin ' + currentBranch.trim()
|
|
27
|
+
if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) {
|
|
28
|
+
message += ' && npm publish'
|
|
29
|
+
if (args.prerelease !== undefined) {
|
|
30
|
+
if (args.prerelease === '') {
|
|
31
|
+
message += ' --tag prerelease'
|
|
32
|
+
} else {
|
|
33
|
+
message += ' --tag ' + args.prerelease
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info))
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// TODO: this should be replaced with an object we maintain and
|
|
2
|
+
// describe in: https://github.com/conventional-changelog/conventional-changelog-config-spec
|
|
3
|
+
const spec = require('conventional-changelog-config-spec')
|
|
4
|
+
|
|
5
|
+
module.exports = (args) => {
|
|
6
|
+
const defaultPreset = require.resolve('conventional-changelog-conventionalcommits')
|
|
7
|
+
let preset = args.preset || defaultPreset
|
|
8
|
+
if (preset === defaultPreset) {
|
|
9
|
+
preset = {
|
|
10
|
+
name: defaultPreset
|
|
11
|
+
}
|
|
12
|
+
Object.keys(spec.properties).forEach(key => {
|
|
13
|
+
if (args[key] !== undefined) preset[key] = args[key]
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
return preset
|
|
17
|
+
}
|
package/lib/run-exec.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { promisify } = require('util')
|
|
2
|
+
const printError = require('./print-error')
|
|
3
|
+
|
|
4
|
+
const exec = promisify(require('child_process').exec)
|
|
5
|
+
|
|
6
|
+
module.exports = async function (args, cmd) {
|
|
7
|
+
if (args.dryRun) return
|
|
8
|
+
try {
|
|
9
|
+
const { stderr, stdout } = await exec(cmd)
|
|
10
|
+
// If exec returns content in stderr, but no error, print it as a warning
|
|
11
|
+
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
|
|
12
|
+
return stdout
|
|
13
|
+
} catch (error) {
|
|
14
|
+
// If exec returns an error, print it and exit with return code 1
|
|
15
|
+
printError(args, error.stderr || error.message)
|
|
16
|
+
throw error
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { promisify } = require('util')
|
|
2
|
+
const printError = require('./print-error')
|
|
3
|
+
|
|
4
|
+
const execFile = promisify(require('child_process').execFile)
|
|
5
|
+
|
|
6
|
+
module.exports = async function (args, cmd, cmdArgs) {
|
|
7
|
+
if (args.dryRun) return
|
|
8
|
+
try {
|
|
9
|
+
const { stderr, stdout } = await execFile(cmd, cmdArgs)
|
|
10
|
+
// If execFile returns content in stderr, but no error, print it as a warning
|
|
11
|
+
if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
|
|
12
|
+
return stdout
|
|
13
|
+
} catch (error) {
|
|
14
|
+
// If execFile returns an error, print it and exit with return code 1
|
|
15
|
+
printError(args, error.stderr || error.message)
|
|
16
|
+
throw error
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const checkpoint = require('./checkpoint')
|
|
3
|
+
const figures = require('figures')
|
|
4
|
+
const runExec = require('./run-exec')
|
|
5
|
+
|
|
6
|
+
module.exports = function (args, hookName) {
|
|
7
|
+
const scripts = args.scripts
|
|
8
|
+
if (!scripts || !scripts[hookName]) return Promise.resolve()
|
|
9
|
+
const command = scripts[hookName]
|
|
10
|
+
checkpoint(args, 'Running lifecycle script "%s"', [hookName])
|
|
11
|
+
checkpoint(args, '- execute command: "%s"', [command], chalk.blue(figures.info))
|
|
12
|
+
return runExec(args, command)
|
|
13
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const JSON_BUMP_FILES = require('../../defaults').bumpFiles
|
|
3
|
+
const updatersByType = {
|
|
4
|
+
json: require('./types/json'),
|
|
5
|
+
'plain-text': require('./types/plain-text')
|
|
6
|
+
}
|
|
7
|
+
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']
|
|
8
|
+
|
|
9
|
+
function getUpdaterByType (type) {
|
|
10
|
+
const updater = updatersByType[type]
|
|
11
|
+
if (!updater) {
|
|
12
|
+
throw Error(`Unable to locate updater for provided type (${type}).`)
|
|
13
|
+
}
|
|
14
|
+
return updater
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getUpdaterByFilename (filename) {
|
|
18
|
+
if (JSON_BUMP_FILES.includes(path.basename(filename))) {
|
|
19
|
+
return getUpdaterByType('json')
|
|
20
|
+
}
|
|
21
|
+
if (PLAIN_TEXT_BUMP_FILES.includes(filename)) {
|
|
22
|
+
return getUpdaterByType('plain-text')
|
|
23
|
+
}
|
|
24
|
+
throw Error(
|
|
25
|
+
`Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getCustomUpdaterFromPath (updater) {
|
|
30
|
+
if (typeof updater === 'string') {
|
|
31
|
+
return require(path.resolve(process.cwd(), updater))
|
|
32
|
+
}
|
|
33
|
+
if (
|
|
34
|
+
typeof updater.readVersion === 'function' &&
|
|
35
|
+
typeof updater.writeVersion === 'function'
|
|
36
|
+
) {
|
|
37
|
+
return updater
|
|
38
|
+
}
|
|
39
|
+
throw new Error('Updater must be a string path or an object with readVersion and writeVersion methods')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Simple check to determine if the object provided is a compatible updater.
|
|
44
|
+
*/
|
|
45
|
+
function isValidUpdater (obj) {
|
|
46
|
+
return (
|
|
47
|
+
typeof obj.readVersion === 'function' &&
|
|
48
|
+
typeof obj.writeVersion === 'function'
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports.resolveUpdaterObjectFromArgument = function (arg) {
|
|
53
|
+
/**
|
|
54
|
+
* If an Object was not provided, we assume it's the path/filename
|
|
55
|
+
* of the updater.
|
|
56
|
+
*/
|
|
57
|
+
let updater = arg
|
|
58
|
+
if (isValidUpdater(updater)) {
|
|
59
|
+
return updater
|
|
60
|
+
}
|
|
61
|
+
if (typeof updater !== 'object') {
|
|
62
|
+
updater = {
|
|
63
|
+
filename: arg
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
if (typeof updater.updater === 'string') {
|
|
68
|
+
updater.updater = getCustomUpdaterFromPath(updater.updater)
|
|
69
|
+
} else if (updater.type) {
|
|
70
|
+
updater.updater = getUpdaterByType(updater.type)
|
|
71
|
+
} else {
|
|
72
|
+
updater.updater = getUpdaterByFilename(updater.filename)
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (err.code !== 'ENOENT') console.warn(`Unable to obtain updater for: ${JSON.stringify(arg)}\n - Error: ${err.message}\n - Skipping...`)
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* We weren't able to resolve an updater for the argument.
|
|
79
|
+
*/
|
|
80
|
+
if (!isValidUpdater(updater.updater)) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return updater
|
|
85
|
+
}
|