Skip to content

Commit

Permalink
✨ order releases by reverse semver versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Oct 7, 2018
1 parent 90903c6 commit 2df2bbf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/gitmoji-changelog-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lodash": "^4.17.11",
"normalize-package-data": "^2.4.0",
"read-pkg-up": "^4.0.0",
"semver-compare": "^1.0.0",
"signale": "^1.3.0",
"split-lines": "^2.0.0",
"through2": "^2.0.3"
Expand Down
5 changes: 4 additions & 1 deletion packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const gitRawCommits = require('git-raw-commits')
const gitSemverTags = require('git-semver-tags')
const semverCompare = require('semver-compare')
const through = require('through2')
const concat = require('concat-stream')
const { head, isEmpty } = require('lodash')
Expand Down Expand Up @@ -65,7 +66,9 @@ async function generateTagsChanges(tags) {
const changes = await generateChanges(previousTag, tag)
previousTag = tag
return changes
}))
})).then((changes) => {
return changes.sort((c1, c2) => semverCompare(c1.version, c2.version)).reverse()
})
}

async function generateChangelog(options = {}) {
Expand Down
1 change: 0 additions & 1 deletion packages/gitmoji-changelog-markdown/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function toMarkdown({ meta, changes }) {
message: autolink(commit.message, meta.repository),
body: autolink(commit.body, meta.repository),
}))
.sort((r1, r2) => r1.version < r2.version) // TODO sort must be done in core

return compileTemplate({ changelog })
}
Expand Down
30 changes: 15 additions & 15 deletions packages/gitmoji-changelog-markdown/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ describe('Markdown converter', () => {
},
changes: [
{
version: '1.0.0',
date: '2018-08-28',
version: 'next',
groups: [
{
group: 'added',
label: 'Added',
group: 'changed',
label: 'Changed',
commits: [
{
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
date: '2018-08-28T10:06:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 2',
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
subject: ':recycle: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
},
],
},
],
},
{
version: 'next',
version: '1.0.0',
date: '2018-08-28',
groups: [
{
group: 'changed',
label: 'Changed',
group: 'added',
label: 'Added',
commits: [
{
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
subject: ':recycle: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
date: '2018-08-28T10:06:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 2',
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,10 @@ sax@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"

"semver@2 || 3 || 4 || 5", semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"
Expand Down

0 comments on commit 2df2bbf

Please sign in to comment.