commit-and-tag-version 12.0.0 → 12.2.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/.eslintrc +43 -8
- package/.gitattributes +2 -0
- package/.github/workflows/ci.yaml +10 -3
- package/.prettierrc +3 -0
- package/CHANGELOG.md +14 -0
- package/README.md +17 -4
- package/bin/cli.js +6 -6
- package/command.js +43 -37
- package/defaults.js +12 -11
- package/index.js +44 -42
- package/jest.config.js +28 -0
- package/lib/checkpoint.js +19 -8
- package/lib/configuration.js +17 -17
- package/lib/detect-package-manager.js +20 -20
- package/lib/format-commit-message.js +3 -3
- package/lib/latest-semver-tag.js +13 -11
- package/lib/lifecycles/bump.js +136 -105
- package/lib/lifecycles/changelog.js +70 -51
- package/lib/lifecycles/commit.js +41 -42
- package/lib/lifecycles/tag.js +41 -31
- package/lib/preset-loader.js +12 -10
- package/lib/print-error.js +10 -7
- package/lib/run-exec.js +10 -10
- package/lib/run-execFile.js +10 -10
- package/lib/run-lifecycle-script.js +16 -11
- package/lib/stringify-package.js +10 -10
- package/lib/updaters/index.js +44 -33
- package/lib/updaters/types/csproj.js +9 -7
- package/lib/updaters/types/gradle.js +10 -8
- package/lib/updaters/types/json.js +14 -14
- package/lib/updaters/types/maven.js +44 -0
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/write-file.js +4 -4
- package/package.json +16 -21
- package/test/commit-message-config.integration-test.js +106 -0
- package/test/config-files.integration-test.js +114 -0
- package/test/config-keys.integration-test.js +83 -0
- package/test/core.spec.js +1438 -705
- package/test/git.integration-test.js +363 -0
- package/test/invalid-config.integration-test.js +73 -0
- package/test/mocks/jest-mocks.js +48 -0
- package/test/mocks/pom-6.3.1-crlf.xml +30 -0
- package/test/mocks/pom-6.3.1-lf.xml +30 -0
- package/test/mocks/pom-6.4.0-crlf.xml +30 -0
- package/test/mocks/pom-6.4.0-lf.xml +30 -0
- package/test/mocks/updater/customer-updater.js +5 -8
- package/test/mocks/updater/increment-updater.js +5 -5
- package/test/pre-commit-hook.integration-test.js +192 -0
- package/test/preset.integration-test.js +56 -0
- package/test/stringify-package.spec.js +18 -22
- package/test/utils.spec.js +25 -41
- package/test/config-files.spec.js +0 -176
- package/test/git.spec.js +0 -480
- package/test/preset.spec.js +0 -52
package/lib/configuration.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const findUp = require('find-up')
|
|
3
|
-
const { readFileSync } = require('fs')
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const findUp = require('find-up');
|
|
3
|
+
const { readFileSync } = require('fs');
|
|
4
4
|
|
|
5
5
|
const CONFIGURATION_FILES = [
|
|
6
6
|
'.versionrc',
|
|
7
7
|
'.versionrc.cjs',
|
|
8
8
|
'.versionrc.json',
|
|
9
|
-
'.versionrc.js'
|
|
10
|
-
]
|
|
9
|
+
'.versionrc.js',
|
|
10
|
+
];
|
|
11
11
|
|
|
12
12
|
module.exports.getConfiguration = function () {
|
|
13
|
-
let config = {}
|
|
14
|
-
const configPath = findUp.sync(CONFIGURATION_FILES)
|
|
13
|
+
let config = {};
|
|
14
|
+
const configPath = findUp.sync(CONFIGURATION_FILES);
|
|
15
15
|
if (!configPath) {
|
|
16
|
-
return config
|
|
16
|
+
return config;
|
|
17
17
|
}
|
|
18
|
-
const ext = path.extname(configPath)
|
|
18
|
+
const ext = path.extname(configPath);
|
|
19
19
|
if (ext === '.js' || ext === '.cjs') {
|
|
20
|
-
const jsConfiguration = require(configPath)
|
|
20
|
+
const jsConfiguration = require(configPath);
|
|
21
21
|
if (typeof jsConfiguration === 'function') {
|
|
22
|
-
config = jsConfiguration()
|
|
22
|
+
config = jsConfiguration();
|
|
23
23
|
} else {
|
|
24
|
-
config = jsConfiguration
|
|
24
|
+
config = jsConfiguration;
|
|
25
25
|
}
|
|
26
26
|
} else {
|
|
27
|
-
config = JSON.parse(readFileSync(configPath))
|
|
27
|
+
config = JSON.parse(readFileSync(configPath));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -33,9 +33,9 @@ module.exports.getConfiguration = function () {
|
|
|
33
33
|
*/
|
|
34
34
|
if (typeof config !== 'object') {
|
|
35
35
|
throw Error(
|
|
36
|
-
`[commit-and-tag-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}
|
|
37
|
-
)
|
|
36
|
+
`[commit-and-tag-version] Invalid configuration in ${configPath} provided. Expected an object but found ${typeof config}.`,
|
|
37
|
+
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return config
|
|
41
|
-
}
|
|
40
|
+
return config;
|
|
41
|
+
};
|
|
@@ -4,50 +4,50 @@
|
|
|
4
4
|
* modified to support only detecting lock file and not detecting global package manager
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { promises: fs } = require('fs')
|
|
8
|
-
const { resolve } = require('path')
|
|
7
|
+
const { promises: fs } = require('fs');
|
|
8
|
+
const { resolve } = require('path');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Check if a path exists
|
|
12
12
|
*/
|
|
13
|
-
async function pathExists
|
|
13
|
+
async function pathExists(p) {
|
|
14
14
|
try {
|
|
15
|
-
await fs.access(p)
|
|
16
|
-
return true
|
|
15
|
+
await fs.access(p);
|
|
16
|
+
return true;
|
|
17
17
|
} catch {
|
|
18
|
-
return false
|
|
18
|
+
return false;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function getTypeofLockFile
|
|
22
|
+
function getTypeofLockFile(cwd = '.') {
|
|
23
23
|
return Promise.all([
|
|
24
24
|
pathExists(resolve(cwd, 'yarn.lock')),
|
|
25
25
|
pathExists(resolve(cwd, 'package-lock.json')),
|
|
26
|
-
pathExists(resolve(cwd, 'pnpm-lock.yaml'))
|
|
26
|
+
pathExists(resolve(cwd, 'pnpm-lock.yaml')),
|
|
27
27
|
]).then(([isYarn, isNpm, isPnpm]) => {
|
|
28
|
-
let value = null
|
|
28
|
+
let value = null;
|
|
29
29
|
|
|
30
30
|
if (isYarn) {
|
|
31
|
-
value = 'yarn'
|
|
31
|
+
value = 'yarn';
|
|
32
32
|
} else if (isPnpm) {
|
|
33
|
-
value = 'pnpm'
|
|
33
|
+
value = 'pnpm';
|
|
34
34
|
} else if (isNpm) {
|
|
35
|
-
value = 'npm'
|
|
35
|
+
value = 'npm';
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return value
|
|
39
|
-
})
|
|
38
|
+
return value;
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const detectPMByLockFile = async (cwd) => {
|
|
43
|
-
const type = await getTypeofLockFile(cwd)
|
|
43
|
+
const type = await getTypeofLockFile(cwd);
|
|
44
44
|
if (type) {
|
|
45
|
-
return type
|
|
45
|
+
return type;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return 'npm'
|
|
49
|
-
}
|
|
48
|
+
return 'npm';
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
module.exports = {
|
|
52
|
-
detectPMByLockFile
|
|
53
|
-
}
|
|
52
|
+
detectPMByLockFile,
|
|
53
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
module.exports = function (rawMsg, newVersion) {
|
|
2
|
-
const message = String(rawMsg)
|
|
3
|
-
return message.replace(/{{currentTag}}/g, newVersion)
|
|
4
|
-
}
|
|
2
|
+
const message = String(rawMsg);
|
|
3
|
+
return message.replace(/{{currentTag}}/g, newVersion);
|
|
4
|
+
};
|
package/lib/latest-semver-tag.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
const gitSemverTags = require('git-semver-tags')
|
|
2
|
-
const semver = require('semver')
|
|
1
|
+
const gitSemverTags = require('git-semver-tags');
|
|
2
|
+
const semver = require('semver');
|
|
3
3
|
|
|
4
4
|
module.exports = function (tagPrefix = undefined) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
gitSemverTags({ tagPrefix }, function (err, tags) {
|
|
7
|
-
if (err) return reject(err)
|
|
8
|
-
else if (!tags.length) return resolve('1.0.0')
|
|
7
|
+
if (err) return reject(err);
|
|
8
|
+
else if (!tags.length) return resolve('1.0.0');
|
|
9
9
|
// Respect tagPrefix
|
|
10
|
-
tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), ''))
|
|
10
|
+
tags = tags.map((tag) => tag.replace(new RegExp('^' + tagPrefix), ''));
|
|
11
11
|
// ensure that the largest semver tag is at the head.
|
|
12
|
-
tags = tags.map(tag => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
12
|
+
tags = tags.map((tag) => {
|
|
13
|
+
return semver.clean(tag);
|
|
14
|
+
});
|
|
15
|
+
tags.sort(semver.rcompare);
|
|
16
|
+
return resolve(tags[0]);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
package/lib/lifecycles/bump.js
CHANGED
|
@@ -1,76 +1,103 @@
|
|
|
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
|
|
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
18
|
// reset the cache of updated config files each
|
|
19
19
|
// time we perform the version bump step.
|
|
20
|
-
configsToUpdate = {}
|
|
21
|
-
|
|
22
|
-
if (args.skip.bump) return version
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
20
|
+
configsToUpdate = {};
|
|
21
|
+
|
|
22
|
+
if (args.skip.bump) return version;
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
args.releaseAs &&
|
|
26
|
+
!(
|
|
27
|
+
['major', 'minor', 'patch'].includes(args.releaseAs.toLowerCase()) ||
|
|
28
|
+
semver.valid(args.releaseAs)
|
|
29
|
+
)
|
|
30
|
+
) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"releaseAs must be one of 'major', 'minor' or 'patch', or a valid semvar version.",
|
|
33
|
+
);
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
let newVersion = version
|
|
29
|
-
await runLifecycleScript(args, 'prerelease')
|
|
30
|
-
const stdout = await runLifecycleScript(args, 'prebump')
|
|
36
|
+
let newVersion = version;
|
|
37
|
+
await runLifecycleScript(args, 'prerelease');
|
|
38
|
+
const stdout = await runLifecycleScript(args, 'prebump');
|
|
31
39
|
if (stdout?.trim().length) {
|
|
32
|
-
const prebumpString = stdout.trim()
|
|
33
|
-
if (semver.valid(prebumpString)) args.releaseAs = prebumpString
|
|
40
|
+
const prebumpString = stdout.trim();
|
|
41
|
+
if (semver.valid(prebumpString)) args.releaseAs = prebumpString;
|
|
34
42
|
}
|
|
35
43
|
if (!args.firstRelease) {
|
|
36
44
|
if (semver.valid(args.releaseAs)) {
|
|
37
|
-
const releaseAs = new semver.SemVer(args.releaseAs)
|
|
38
|
-
if (
|
|
45
|
+
const releaseAs = new semver.SemVer(args.releaseAs);
|
|
46
|
+
if (
|
|
47
|
+
isString(args.prerelease) &&
|
|
48
|
+
releaseAs.prerelease.length &&
|
|
49
|
+
releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease
|
|
50
|
+
) {
|
|
39
51
|
// If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
|
|
40
52
|
// for a mismatch is undefined, so error out instead.
|
|
41
|
-
throw new Error(
|
|
53
|
+
throw new Error(
|
|
54
|
+
'releaseAs and prerelease have conflicting prerelease identifiers',
|
|
55
|
+
);
|
|
42
56
|
} else if (isString(args.prerelease) && releaseAs.prerelease.length) {
|
|
43
|
-
newVersion = releaseAs.version
|
|
57
|
+
newVersion = releaseAs.version;
|
|
44
58
|
} else if (isString(args.prerelease)) {
|
|
45
|
-
newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0
|
|
59
|
+
newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`;
|
|
46
60
|
} else {
|
|
47
|
-
newVersion = releaseAs.version
|
|
61
|
+
newVersion = releaseAs.version;
|
|
48
62
|
}
|
|
49
63
|
|
|
50
64
|
// Check if the previous version is the same version and prerelease, and increment if so
|
|
51
|
-
if (
|
|
52
|
-
|
|
65
|
+
if (
|
|
66
|
+
isString(args.prerelease) &&
|
|
67
|
+
['prerelease', null].includes(semver.diff(version, newVersion)) &&
|
|
68
|
+
semver.lte(newVersion, version)
|
|
69
|
+
) {
|
|
70
|
+
newVersion = semver.inc(version, 'prerelease', args.prerelease);
|
|
53
71
|
}
|
|
54
72
|
|
|
55
73
|
// Append any build info from releaseAs
|
|
56
|
-
newVersion = semvarToVersionStr(newVersion, releaseAs.build)
|
|
74
|
+
newVersion = semvarToVersionStr(newVersion, releaseAs.build);
|
|
57
75
|
} else {
|
|
58
|
-
const release = await bumpVersion(args.releaseAs, version, args)
|
|
59
|
-
const releaseType = getReleaseType(
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
const release = await bumpVersion(args.releaseAs, version, args);
|
|
77
|
+
const releaseType = getReleaseType(
|
|
78
|
+
args.prerelease,
|
|
79
|
+
release.releaseType,
|
|
80
|
+
version,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
newVersion = semver.inc(version, releaseType, args.prerelease);
|
|
62
84
|
}
|
|
63
|
-
updateConfigs(args, newVersion)
|
|
85
|
+
updateConfigs(args, newVersion);
|
|
64
86
|
} else {
|
|
65
|
-
checkpoint(
|
|
87
|
+
checkpoint(
|
|
88
|
+
args,
|
|
89
|
+
'skip version bump on first release',
|
|
90
|
+
[],
|
|
91
|
+
chalk.red(figures.cross),
|
|
92
|
+
);
|
|
66
93
|
}
|
|
67
|
-
await runLifecycleScript(args, 'postbump')
|
|
68
|
-
return newVersion
|
|
94
|
+
await runLifecycleScript(args, 'postbump');
|
|
95
|
+
return newVersion;
|
|
69
96
|
}
|
|
70
97
|
|
|
71
98
|
Bump.getUpdatedConfigs = function () {
|
|
72
|
-
return configsToUpdate
|
|
73
|
-
}
|
|
99
|
+
return configsToUpdate;
|
|
100
|
+
};
|
|
74
101
|
|
|
75
102
|
/**
|
|
76
103
|
* Convert a semver object to a full version string including build metadata
|
|
@@ -78,28 +105,30 @@ Bump.getUpdatedConfigs = function () {
|
|
|
78
105
|
* @param {string[]} semverBuild An array of the build metadata elements, to be joined with '.'
|
|
79
106
|
* @returns {string}
|
|
80
107
|
*/
|
|
81
|
-
function semvarToVersionStr
|
|
82
|
-
return [semverVersion, semverBuild.join('.')].filter(Boolean).join('+')
|
|
108
|
+
function semvarToVersionStr(semverVersion, semverBuild) {
|
|
109
|
+
return [semverVersion, semverBuild.join('.')].filter(Boolean).join('+');
|
|
83
110
|
}
|
|
84
111
|
|
|
85
|
-
function getReleaseType
|
|
112
|
+
function getReleaseType(prerelease, expectedReleaseType, currentVersion) {
|
|
86
113
|
if (isString(prerelease)) {
|
|
87
114
|
if (isInPrerelease(currentVersion)) {
|
|
88
|
-
if (
|
|
89
|
-
|
|
115
|
+
if (
|
|
116
|
+
shouldContinuePrerelease(currentVersion, expectedReleaseType) ||
|
|
117
|
+
getTypePriority(getCurrentActiveType(currentVersion)) >
|
|
118
|
+
getTypePriority(expectedReleaseType)
|
|
90
119
|
) {
|
|
91
|
-
return 'prerelease'
|
|
120
|
+
return 'prerelease';
|
|
92
121
|
}
|
|
93
122
|
}
|
|
94
123
|
|
|
95
|
-
return 'pre' + expectedReleaseType
|
|
124
|
+
return 'pre' + expectedReleaseType;
|
|
96
125
|
} else {
|
|
97
|
-
return expectedReleaseType
|
|
126
|
+
return expectedReleaseType;
|
|
98
127
|
}
|
|
99
128
|
}
|
|
100
129
|
|
|
101
|
-
function isString
|
|
102
|
-
return typeof val === 'string'
|
|
130
|
+
function isString(val) {
|
|
131
|
+
return typeof val === 'string';
|
|
103
132
|
}
|
|
104
133
|
|
|
105
134
|
/**
|
|
@@ -111,15 +140,15 @@ function isString (val) {
|
|
|
111
140
|
* @param expectType
|
|
112
141
|
* @return {boolean}
|
|
113
142
|
*/
|
|
114
|
-
function shouldContinuePrerelease
|
|
115
|
-
return getCurrentActiveType(version) === expectType
|
|
143
|
+
function shouldContinuePrerelease(version, expectType) {
|
|
144
|
+
return getCurrentActiveType(version) === expectType;
|
|
116
145
|
}
|
|
117
146
|
|
|
118
|
-
function isInPrerelease
|
|
119
|
-
return Array.isArray(semver.prerelease(version))
|
|
147
|
+
function isInPrerelease(version) {
|
|
148
|
+
return Array.isArray(semver.prerelease(version));
|
|
120
149
|
}
|
|
121
150
|
|
|
122
|
-
const TypeList = ['major', 'minor', 'patch'].reverse()
|
|
151
|
+
const TypeList = ['major', 'minor', 'patch'].reverse();
|
|
123
152
|
|
|
124
153
|
/**
|
|
125
154
|
* extract the in-pre-release type in target version
|
|
@@ -127,11 +156,11 @@ const TypeList = ['major', 'minor', 'patch'].reverse()
|
|
|
127
156
|
* @param version
|
|
128
157
|
* @return {string}
|
|
129
158
|
*/
|
|
130
|
-
function getCurrentActiveType
|
|
131
|
-
const typelist = TypeList
|
|
159
|
+
function getCurrentActiveType(version) {
|
|
160
|
+
const typelist = TypeList;
|
|
132
161
|
for (let i = 0; i < typelist.length; i++) {
|
|
133
162
|
if (semver[typelist[i]](version)) {
|
|
134
|
-
return typelist[i]
|
|
163
|
+
return typelist[i];
|
|
135
164
|
}
|
|
136
165
|
}
|
|
137
166
|
}
|
|
@@ -143,33 +172,39 @@ function getCurrentActiveType (version) {
|
|
|
143
172
|
* @param type
|
|
144
173
|
* @return {number}
|
|
145
174
|
*/
|
|
146
|
-
function getTypePriority
|
|
147
|
-
return TypeList.indexOf(type)
|
|
175
|
+
function getTypePriority(type) {
|
|
176
|
+
return TypeList.indexOf(type);
|
|
148
177
|
}
|
|
149
178
|
|
|
150
|
-
function bumpVersion
|
|
179
|
+
function bumpVersion(releaseAs, currentVersion, args) {
|
|
151
180
|
return new Promise((resolve, reject) => {
|
|
152
181
|
if (releaseAs) {
|
|
153
182
|
return resolve({
|
|
154
|
-
releaseType: releaseAs
|
|
155
|
-
})
|
|
183
|
+
releaseType: releaseAs,
|
|
184
|
+
});
|
|
156
185
|
} else {
|
|
157
|
-
const presetOptions = presetLoader(args)
|
|
186
|
+
const presetOptions = presetLoader(args);
|
|
158
187
|
if (typeof presetOptions === 'object') {
|
|
159
|
-
if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true
|
|
188
|
+
if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true;
|
|
160
189
|
}
|
|
161
|
-
conventionalRecommendedBump(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
190
|
+
conventionalRecommendedBump(
|
|
191
|
+
{
|
|
192
|
+
debug:
|
|
193
|
+
args.verbose &&
|
|
194
|
+
console.info.bind(console, 'conventional-recommended-bump'),
|
|
195
|
+
preset: presetOptions,
|
|
196
|
+
path: args.path,
|
|
197
|
+
tagPrefix: args.tagPrefix,
|
|
198
|
+
lernaPackage: args.lernaPackage,
|
|
199
|
+
},
|
|
200
|
+
args.parserOpts,
|
|
201
|
+
function (err, release) {
|
|
202
|
+
if (err) return reject(err);
|
|
203
|
+
else return resolve(release);
|
|
204
|
+
},
|
|
205
|
+
);
|
|
171
206
|
}
|
|
172
|
-
})
|
|
207
|
+
});
|
|
173
208
|
}
|
|
174
209
|
|
|
175
210
|
/**
|
|
@@ -178,39 +213,35 @@ function bumpVersion (releaseAs, currentVersion, args) {
|
|
|
178
213
|
* @param newVersion version number to update to.
|
|
179
214
|
* @return void
|
|
180
215
|
*/
|
|
181
|
-
function updateConfigs
|
|
182
|
-
const dotgit = DotGitignore()
|
|
216
|
+
function updateConfigs(args, newVersion) {
|
|
217
|
+
const dotgit = DotGitignore();
|
|
183
218
|
args.bumpFiles.forEach(function (bumpFile) {
|
|
184
|
-
const updater = resolveUpdaterObjectFromArgument(bumpFile)
|
|
219
|
+
const updater = resolveUpdaterObjectFromArgument(bumpFile);
|
|
185
220
|
if (!updater) {
|
|
186
|
-
return
|
|
221
|
+
return;
|
|
187
222
|
}
|
|
188
|
-
const configPath = path.resolve(process.cwd(), updater.filename)
|
|
223
|
+
const configPath = path.resolve(process.cwd(), updater.filename);
|
|
189
224
|
try {
|
|
190
|
-
if (dotgit.ignore(updater.filename)) return
|
|
191
|
-
const stat = fs.lstatSync(configPath)
|
|
225
|
+
if (dotgit.ignore(updater.filename)) return;
|
|
226
|
+
const stat = fs.lstatSync(configPath);
|
|
192
227
|
|
|
193
|
-
if (!stat.isFile()) return
|
|
194
|
-
const contents = fs.readFileSync(configPath, 'utf8')
|
|
195
|
-
const newContents = updater.updater.writeVersion(contents, newVersion)
|
|
196
|
-
const realNewVersion = updater.updater.readVersion(newContents)
|
|
228
|
+
if (!stat.isFile()) return;
|
|
229
|
+
const contents = fs.readFileSync(configPath, 'utf8');
|
|
230
|
+
const newContents = updater.updater.writeVersion(contents, newVersion);
|
|
231
|
+
const realNewVersion = updater.updater.readVersion(newContents);
|
|
197
232
|
checkpoint(
|
|
198
233
|
args,
|
|
199
234
|
'bumping version in ' + updater.filename + ' from %s to %s',
|
|
200
|
-
[updater.updater.readVersion(contents), realNewVersion]
|
|
201
|
-
)
|
|
202
|
-
writeFile(
|
|
203
|
-
args,
|
|
204
|
-
configPath,
|
|
205
|
-
newContents
|
|
206
|
-
)
|
|
235
|
+
[updater.updater.readVersion(contents), realNewVersion],
|
|
236
|
+
);
|
|
237
|
+
writeFile(args, configPath, newContents);
|
|
207
238
|
// flag any config files that we modify the version # for
|
|
208
239
|
// as having been updated.
|
|
209
|
-
configsToUpdate[updater.filename] = true
|
|
240
|
+
configsToUpdate[updater.filename] = true;
|
|
210
241
|
} catch (err) {
|
|
211
|
-
if (err.code !== 'ENOENT') console.warn(err.message)
|
|
242
|
+
if (err.code !== 'ENOENT') console.warn(err.message);
|
|
212
243
|
}
|
|
213
|
-
})
|
|
244
|
+
});
|
|
214
245
|
}
|
|
215
246
|
|
|
216
|
-
module.exports = Bump
|
|
247
|
+
module.exports = Bump;
|
|
@@ -1,88 +1,107 @@
|
|
|
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 =
|
|
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 =
|
|
9
|
+
/(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
|
|
9
10
|
|
|
10
|
-
async function Changelog
|
|
11
|
-
if (args.skip.changelog) return
|
|
12
|
-
await runLifecycleScript(args, 'prechangelog')
|
|
13
|
-
await outputChangelog(args, newVersion)
|
|
14
|
-
await runLifecycleScript(args, 'postchangelog')
|
|
11
|
+
async function Changelog(args, newVersion) {
|
|
12
|
+
if (args.skip.changelog) return;
|
|
13
|
+
await runLifecycleScript(args, 'prechangelog');
|
|
14
|
+
await outputChangelog(args, newVersion);
|
|
15
|
+
await runLifecycleScript(args, 'postchangelog');
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN
|
|
18
|
+
Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN;
|
|
18
19
|
|
|
19
|
-
module.exports = Changelog
|
|
20
|
+
module.exports = Changelog;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Front matter is only extracted and therefore retained in final output where Changelog "header" begins with #Changelog,
|
|
23
24
|
* e.g. meets Standard-Version (last release) or commit-and-tag-version(current) format
|
|
24
25
|
*/
|
|
25
|
-
function extractFrontMatter
|
|
26
|
-
const headerStart = oldContent.indexOf('# Changelog')
|
|
26
|
+
function extractFrontMatter(oldContent) {
|
|
27
|
+
const headerStart = oldContent.indexOf('# Changelog');
|
|
27
28
|
return headerStart !== -1 || headerStart !== 0
|
|
28
29
|
? oldContent.substring(0, headerStart)
|
|
29
|
-
: ''
|
|
30
|
+
: '';
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* find the position of the last release and remove header
|
|
34
35
|
*/
|
|
35
|
-
function extractChangelogBody
|
|
36
|
-
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
|
|
36
|
+
function extractChangelogBody(oldContent) {
|
|
37
|
+
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN);
|
|
37
38
|
return oldContentStart !== -1
|
|
38
39
|
? oldContent.substring(oldContentStart)
|
|
39
|
-
: oldContent
|
|
40
|
+
: oldContent;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
function outputChangelog
|
|
43
|
+
function outputChangelog(args, newVersion) {
|
|
43
44
|
return new Promise((resolve, reject) => {
|
|
44
|
-
createIfMissing(args)
|
|
45
|
-
const header = args.header
|
|
45
|
+
createIfMissing(args);
|
|
46
|
+
const header = args.header;
|
|
46
47
|
|
|
47
|
-
const oldContent =
|
|
48
|
+
const oldContent =
|
|
49
|
+
args.dryRun || args.releaseCount === 0
|
|
50
|
+
? ''
|
|
51
|
+
: fs.readFileSync(args.infile, 'utf-8');
|
|
48
52
|
|
|
49
|
-
const oldContentBody = extractChangelogBody(oldContent)
|
|
53
|
+
const oldContentBody = extractChangelogBody(oldContent);
|
|
50
54
|
|
|
51
|
-
const changelogFrontMatter = extractFrontMatter(oldContent)
|
|
55
|
+
const changelogFrontMatter = extractFrontMatter(oldContent);
|
|
52
56
|
|
|
53
|
-
let content = ''
|
|
54
|
-
const context = { version: newVersion }
|
|
55
|
-
const changelogStream = conventionalChangelog(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
let content = '';
|
|
58
|
+
const context = { version: newVersion };
|
|
59
|
+
const changelogStream = conventionalChangelog(
|
|
60
|
+
{
|
|
61
|
+
debug:
|
|
62
|
+
args.verbose && console.info.bind(console, 'conventional-changelog'),
|
|
63
|
+
preset: presetLoader(args),
|
|
64
|
+
tagPrefix: args.tagPrefix,
|
|
65
|
+
releaseCount: args.releaseCount,
|
|
66
|
+
},
|
|
67
|
+
context,
|
|
68
|
+
{ merges: null, path: args.path, showSignature: false },
|
|
69
|
+
args.parserOpts,
|
|
70
|
+
args.writerOpts,
|
|
71
|
+
).on('error', function (err) {
|
|
72
|
+
return reject(err);
|
|
73
|
+
});
|
|
64
74
|
|
|
65
75
|
changelogStream.on('data', function (buffer) {
|
|
66
|
-
content += buffer.toString()
|
|
67
|
-
})
|
|
76
|
+
content += buffer.toString();
|
|
77
|
+
});
|
|
68
78
|
|
|
69
79
|
changelogStream.on('end', function () {
|
|
70
|
-
checkpoint(args, 'outputting changes to %s', [args.infile])
|
|
71
|
-
if (args.dryRun)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
checkpoint(args, 'outputting changes to %s', [args.infile]);
|
|
81
|
+
if (args.dryRun)
|
|
82
|
+
console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`);
|
|
83
|
+
else
|
|
84
|
+
writeFile(
|
|
85
|
+
args,
|
|
86
|
+
args.infile,
|
|
87
|
+
changelogFrontMatter +
|
|
88
|
+
header +
|
|
89
|
+
'\n' +
|
|
90
|
+
(content + oldContentBody).replace(/\n+$/, '\n'),
|
|
91
|
+
);
|
|
92
|
+
return resolve();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
76
95
|
}
|
|
77
96
|
|
|
78
|
-
function createIfMissing
|
|
97
|
+
function createIfMissing(args) {
|
|
79
98
|
try {
|
|
80
|
-
fs.accessSync(args.infile, fs.F_OK)
|
|
99
|
+
fs.accessSync(args.infile, fs.F_OK);
|
|
81
100
|
} catch (err) {
|
|
82
101
|
if (err.code === 'ENOENT') {
|
|
83
|
-
checkpoint(args, 'created %s', [args.infile])
|
|
84
|
-
args.outputUnreleased = true
|
|
85
|
-
writeFile(args, args.infile, '\n')
|
|
102
|
+
checkpoint(args, 'created %s', [args.infile]);
|
|
103
|
+
args.outputUnreleased = true;
|
|
104
|
+
writeFile(args, args.infile, '\n');
|
|
86
105
|
}
|
|
87
106
|
}
|
|
88
107
|
}
|