Skip to content

Commit

Permalink
🐛 Fix bug preventing generating changelog when previous version doesn…
Browse files Browse the repository at this point in the history
…'t exist (#145)
  • Loading branch information
frinyvonnick authored Nov 18, 2019
1 parent 84ab6f1 commit 4f04f45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/gitmoji-changelog-cli/src/cli.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ describe('generate changelog', () => {
})

describe('update', () => {
it("should get a 1.0.0 version while initializing changelog by calling cli without arguments two times and having package.json's version set to 1.0.0", async () => {
await bumpVersion('1.0.0')
await makeChanges('file1')
await commit(':sparkles: Add some file')
gitmojiChangelog()
await makeChanges('file2')
await commit(':sparkles: Add a second file')
gitmojiChangelog()

expect(getChangelog()).includes(['second file'])
})

it("should get two versions 1.0.0 and next while updating changelog by calling cli without arguments and having package.json's version set to 1.0.0", async () => {
await makeChanges('file1')
await commit(':sparkles: Add some file')
Expand Down
9 changes: 7 additions & 2 deletions packages/gitmoji-changelog-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ async function main(options = {}) {
const lastVersion = await getLatestVersion(options.output)
const newOptions = set(options, 'meta.lastVersion', lastVersion)

// Handle the case where changelog file exist but there isn't a previous version
if (options.mode === 'update' && !lastVersion) {
newOptions.mode = 'init'

fs.unlinkSync(options.output)
}

const changelog = await getChangelog(newOptions, projectInfo)

logMetaData(changelog)

await buildMarkdownFile(changelog, newOptions)
}
}
Expand All @@ -100,7 +106,6 @@ async function getChangelog(options, projectInfo) {
release,
}

// let changelog = await generateChangelog(enhancedOptions)
let changelog
if (options.mode === 'init') {
changelog = await generateChangelog('', release, enhancedOptions)
Expand Down
2 changes: 2 additions & 0 deletions packages/gitmoji-changelog-markdown/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ async function getLatestVersion(markdownFile) {
const isNext = result[1] === 'next' || !tags.some(tag => semver.eq(tag, result[1]))
if (!isNext) return result[1]

if (!previousVersion) return null

const previousResult = previousVersion.match(/<a name="([\w.-]+?)"><\/a>/)
return previousResult[1]
}
Expand Down

0 comments on commit 4f04f45

Please sign in to comment.