Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preversion): generate preversion changelog #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ $ changelog -h
-p, --patch create a patch changelog
-m, --minor create a minor changelog
-M, --major create a major changelog
--prerelease create a prerelease changelog
--prepatch create a prepatch changelog
--preminor create a preminor changelog
--premajor create a premajor changelog
--preid used to prefix premajor, preminor, prepatch or prerelease version increments
-t, --tag <range> generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)
-x, --exclude <types> exclude selected commit types (comma separated)
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout
Expand Down Expand Up @@ -106,6 +111,10 @@ The way that I would recommend using this module would be the way it's being use
"release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
"release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags",
"release:premajor": "changelog --premajor && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version premajor && git push origin && git push origin --tags",
"release:preminor": "changelog --preminor && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version preminor && git push origin && git push origin --tags",
"release:prepatch": "changelog --prepatch && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version prepatch && git push origin && git push origin --tags",
"release:prerelease": "changelog --prerelease --preid alpha && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version prerelease --preid alpha && git push origin && git push origin --tags",
```

### GitHub Actions
Expand Down
5 changes: 5 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module.exports = CLI
.option('-p, --patch', 'create a patch changelog')
.option('-m, --minor', 'create a minor changelog')
.option('-M, --major', 'create a major changelog')
.option('--prerelease', 'create a prerelease changelog')
.option('--prepatch', 'create a prepatch changelog')
.option('--preminor', 'create a preminor changelog')
.option('--premajor', 'create a premajor changelog')
.option('--preid', 'used to prefix premajor, preminor, prepatch or prerelease version increments')
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)')
.option('-x, --exclude <types>', 'exclude selected commit types (comma separated)', list)
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md')
Expand Down
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ var Writer = require('./writer');
* @param {Boolean} options.patch - whether it should be a patch changelog
* @param {Boolean} options.minor - whether it should be a minor changelog
* @param {Boolean} options.major - whether it should be a major changelog
* @param {Boolean} options.major - whether it should be a major changelog
* @param {Boolean} options.prerelease - whether it should be a prerelease changelog
* @param {Boolean} options.prepatch - whether it should be a prepatch changelog
* @param {Boolean} options.preminor - whether it should be a preminor changelog
* @param {Boolean} options.premajor - whether it should be a premajor changelog
* @param {String} options.preid - used to prefix premajor, preminor, prepatch or prerelease version increments
* @param {String} options.repoUrl - repo URL that will be used when linking commits
* @param {Array} options.exclude - exclude listed commit types (e.g. ['chore', 'style', 'refactor'])
* @returns {Promise<String>} the \n separated changelog string
Expand Down
16 changes: 3 additions & 13 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var File = require('./file');
var ParseGitHubUrl = require('github-url-from-git');
var semverInc = require('semver/functions/inc');

/**
* Get the package.json object located in the current directory.
Expand Down Expand Up @@ -56,19 +57,8 @@ exports.calculateNewVersion = function (options) {
return null;
}

var split = userPackage.version.split('.');
var releaseType = options.major ? 'major' : options.minor ? 'minor' : options.patch ? 'patch' : options.premajor ? 'premajor' : options.preminor ? 'preminor' : options.prepatch ? 'prepatch' : options.prerelease ? 'prerelease' : '';

if (options.major) {
split[0] = (parseInt(split[0]) + 1).toString();
split[1] = '0';
split[2] = '0';
} else if (options.minor) {
split[1] = (parseInt(split[1]) + 1).toString();
split[2] = '0';
} else if (options.patch) {
split[2] = (parseInt(split[2]) + 1).toString();
}

return split.join('.');
return releaseType ? semverInc(userPackage.version, releaseType, options.preid) : userPackage.version;
});
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"dependencies": {
"bluebird": "^3.0.6",
"commander": "^2.9.0",
"github-url-from-git": "^1.4.0"
"github-url-from-git": "^1.4.0",
"semver": "^7.3.5"
},
"devDependencies": {
"chai": "^3.4.1",
Expand Down
36 changes: 36 additions & 0 deletions test/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,42 @@ describe('package', function () {
});
});

it('bumps the premajor version if premajor is true', function () {
var options = { premajor: true };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('2.0.0-0');
});
});

it('bumps the preminor version if preminor is true', function () {
var options = { preminor: true };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('1.3.0-0');
});
});

it('bumps the prepatch version if prepatch is true', function () {
var options = { prepatch: true };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('1.2.4-0');
});
});

it('bumps the prerelease version if prerelease is true and the preid is a string', function () {
var options = { prerelease: true, preid: 'alpha' };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('1.2.4-alpha.0');
});
});

it('leaves the version untouched if none of three options is true', function () {
return Package.calculateNewVersion()
.then(function (version) {
Expand Down