Skip to content

Commit

Permalink
chore(release): use current date as release date
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Aug 19, 2022
1 parent 2eb58c0 commit 43a2225
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
61 changes: 60 additions & 1 deletion changelog.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@

import type { Config } from 'conventional-changelog-cli'
import type { Options } from 'conventional-changelog-core'
import type { CommitGroup } from 'conventional-changelog-writer'
import type {
CommitGroup,
GeneratedContext
} from 'conventional-changelog-writer'
import type { Commit, CommitRaw } from 'conventional-commits-parser'
import dateformat from 'dateformat'
import fs from 'node:fs'
import pkg from './package.json'

/**
* Changlog context.
*
* @extends {GeneratedContext}
*/
interface Context extends GeneratedContext {
currentTag: string
linkCompare: boolean
previousTag: string
}

/**
* Git tag prefix.
*
Expand Down Expand Up @@ -144,6 +158,51 @@ const config: Config = {
? a.header.localeCompare(b.header) || by_date
: by_date
},
/**
* Modifies `context` before the changelog is generated.
*
* This includes:
*
* - Setting the release date to the current date
* - Setting the current release tag
* - Setting the previous release tag
* - Setting compare link generation
*
* @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core#finalizecontext
* @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#finalizecontext
*
* @param {GeneratedContext} context - Generated changelog context
* @return {Context} Final changelog context
*/
finalizeContext(context: GeneratedContext): Context {
/**
* Use current date as release date instead of date of most recent commit.
*
* @see https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-writer/lib/util.js#L194-L196
*/
context.date = dateformat(new Date(), 'yyyy-mm-dd')

/**
* Release tag for upcoming version.
*
* @const {string} currentTag
*/
const currentTag: string = TAG_PREFIX + pkg.version

/**
* Release tag for previous version.
*
* @const {string} previousTag
*/
const previousTag: string = context.gitSemverTags[0]!

return {
...context,
currentTag,
linkCompare: currentTag !== previousTag,
previousTag
}
},
headerPartial: fs.readFileSync('templates/changelog/header.hbs', 'utf8'),
ignoreReverted: false
}
Expand Down
9 changes: 9 additions & 0 deletions typings/conventional-changelog-writer/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {} from 'conventional-changelog-writer'

declare module 'conventional-changelog-writer' {
namespace GeneratedContext {
interface ExtraContext {
gitSemverTags: string[]
}
}
}

0 comments on commit 43a2225

Please sign in to comment.