Skip to content

Commit

Permalink
Allow to override recommended bump (closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 24, 2019
1 parent 12a0c9d commit 1c90f2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ class ConventionalChangelog extends Plugin {
return 'version';
}

getIncrementedVersion() {
const { latestVersion, isPreRelease, preReleaseId } = this.config.getContext();
getIncrementedVersion({ increment, latestVersion, isPreRelease, preReleaseId }) {
this.debug({ increment, latestVersion, isPreRelease, preReleaseId });
return new Promise((resolve, reject) =>
conventionalRecommendedBump(this.options, (err, result) => {
this.debug({ err, result });
if (err) return reject(err);
const { releaseType } = result;
if (releaseType) {
const type = isPreRelease ? `pre${result.releaseType}` : result.releaseType;
let { releaseType } = result;
if(increment) {
this.log.warn(`Recommended bump is "${releaseType}", but is overridden with "${increment}".`)
releaseType = increment;
}
if(increment && semver.valid(increment)) {
resolve(increment);
} else if (releaseType) {
const type = isPreRelease ? `pre${releaseType}` : releaseType;
resolve(semver.inc(latestVersion, type, preReleaseId));
} else {
resolve(null);
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ test('should set changelog', async t => {
t.is(changelog, 'The changelog');
});

test('should use recommended bump', async t => {
const options = { [namespace]: { preset } };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
t.is(version, '1.1.0');
});

test('should use provided increment', async t => {
const options = { increment: 'major', [namespace]: { preset } };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
t.is(version, '2.0.0');
});

test('should use provided version', async t => {
const options = { increment: '1.2.3', [namespace]: { preset } };
const plugin = factory(Plugin, { namespace, options });
await runTasks(plugin);
const { version } = plugin.config.getContext();
t.is(version, '1.2.3');
});

test(`should write and update infile (${infile})`, async t => {
const options = { [namespace]: { preset, infile } };
const plugin = factory(Plugin, { namespace, options });
Expand Down

0 comments on commit 1c90f2d

Please sign in to comment.