Skip to content

Commit

Permalink
Improve progress output
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Apr 10, 2020
1 parent 4aead76 commit a2ba4ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

0 comments on commit a2ba4ac

Please sign in to comment.