Skip to content
Merged
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
12 changes: 8 additions & 4 deletions bin/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ if (nodeVersion.major < 6) {
process.exit(1);
}

args
.option('pre', 'Mark the release as prerelease')
args.option('pre', 'Mark the release as prerelease')
.option('overwrite', 'If the release already exists, replace it')
.option('publish', 'Instead of creating a draft, publish the release')
.option(['H', 'hook'], 'Specify a custom file to pipe releases through')
.option('show-url', 'Show the release URL instead of opening it in the browser');
.option('strict', 'Search previous release only in current branch', false)
.option(['t', 'previous-tag'], 'Specify previous release', '')
.option(['u', 'show-url'], 'Show the release URL instead of opening it in the browser');

const flags = args.parse(process.argv);

Expand Down Expand Up @@ -293,7 +294,10 @@ const checkReleaseStatus = async () => {
let tags;

try {
const unordered = await getTags();
const unordered = await getTags({
strict: flags.strict,
previousTag: flags.previousTag
});
tags = unordered.sort((a, b) => new Date(b.date) - new Date(a.date));
} catch (err) {
fail('Directory is not a Git repository.');
Expand Down
19 changes: 16 additions & 3 deletions lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ const taggedVersions = require('tagged-versions');

const defaultRev = 'HEAD --first-parent `git rev-parse --abbrev-ref HEAD`';

module.exports = async (rev = defaultRev) => {
const defaultOptions = {
rev: defaultRev,
strict: false,
previousTag: ''
};

module.exports = async (options = {}) => {
const {rev, strict, previousTag} = {...defaultOptions, ...options};

const [tags, latest] = await Promise.all([
taggedVersions.getList(),
taggedVersions.getList(strict ? {rev} : {}),
taggedVersions.getLastVersion({rev})
]);

if (!latest) {
return [];
}

const isPreviousTag =
previousTag && previousTag.length > 0
? commitVersion => commitVersion === previousTag
: semVer.lt;

for (const commit of tags) {
if (semVer.lt(commit.version, latest.version)) {
if (isPreviousTag(commit.version, latest.version)) {
return [latest, commit];
}
}
Expand Down