diff --git a/src/releases.js b/src/releases.js index f30680ee..496ece93 100644 --- a/src/releases.js +++ b/src/releases.js @@ -5,7 +5,7 @@ import { niceDate } from './utils' const MERGE_COMMIT_PATTERN = /^Merge (remote-tracking )?branch '.+'/ const COMMIT_MESSAGE_PATTERN = /\n+([\S\s]+)/ -async function createRelease (tag, previousTag, diff, remote, options) { +async function createRelease (tag, previousTag, diff, remote, options, onParsed) { const commits = await fetchCommits(diff, remote, options) const merges = commits.filter(commit => commit.merge).map(commit => commit.merge) const fixes = commits.filter(commit => commit.fixes).map(commit => ({ fixes: commit.fixes, commit })) @@ -16,7 +16,7 @@ async function createRelease (tag, previousTag, diff, remote, options) { .filter(commit => filterCommit(commit, options, merges)) .sort(commitSorter(options)) .slice(0, getCommitLimit(options, emptyRelease, breakingCount)) - return { + const release = { tag, title: tag || 'Unreleased', date, @@ -29,19 +29,23 @@ async function createRelease (tag, previousTag, diff, remote, options) { major: Boolean(!options.tagPattern && tag && previousTag && semver.diff(tag, previousTag) === 'major'), href: getCompareLink(previousTag, tag, remote, options) } + if (onParsed) { + onParsed(release) + } + return release } -export function parseReleases (tags, remote, latestVersion, options) { +export function parseReleases (tags, remote, latestVersion, options, onParsed) { const releases = tags.map((tag, index, tags) => { const previousTag = tags[index + 1] const diff = previousTag ? `${previousTag}..${tag}` : tag - return createRelease(tag, previousTag, diff, remote, options) + return createRelease(tag, previousTag, diff, remote, options, onParsed) }) if (latestVersion || options.unreleased) { const tag = latestVersion || null const previousTag = tags[0] const diff = `${previousTag}..` - releases.unshift(createRelease(tag, previousTag, diff, remote, options)) + releases.unshift(createRelease(tag, previousTag, diff, remote, options, onParsed)) } return Promise.all(releases) } diff --git a/src/run.js b/src/run.js index d5e2a34c..342b3298 100644 --- a/src/run.js +++ b/src/run.js @@ -88,18 +88,18 @@ export default async function run (argv) { const log = string => options.stdout ? null : updateLog(string) log('Fetching remote…') const remote = await fetchRemote(options) - // const commitProgress = bytes => log(`Fetching commits… ${formatBytes(bytes)} loaded`) - // const commits = await fetchCommits(remote, options, null, commitProgress) - log('Generating changelog…') + log('Fetching tags…') const tags = await fetchTags(options) + log(`${tags.length} version tags found…`) const latestVersion = await getLatestVersion(options, tags) - const releases = await parseReleases(tags, remote, latestVersion, options) + const onParsed = ({ title }) => log(`Fetched ${title}…`) + const releases = await parseReleases(tags, remote, latestVersion, options, onParsed) const changelog = await compileTemplate(options, { releases }) if (options.stdout) { process.stdout.write(changelog) - } else { - await writeFile(options.output, changelog) + process.exit(0) } + await writeFile(options.output, changelog) const bytes = Buffer.byteLength(changelog, 'utf8') log(`${formatBytes(bytes)} written to ${options.output}\n`) }