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 18, 2022
1 parent 7949f6f commit 9c867a1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
81 changes: 78 additions & 3 deletions changelog.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@

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 pkg from './package.json'

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

/**
* Git tag prefix.
*
* @const {string} TAG_PREFIX
*/
const TAG_PREFIX: string = ''

/**
* Changelog configuration options.
*
Expand Down Expand Up @@ -57,9 +78,18 @@ const config: Config = {
commit.committerDate = dateformat(commit.committerDate, 'yyyy-mm-dd')

if (commit.gitTags) {
/**
* Regex expression used to check {@link commit.gitTags} for the release
* {@link commit} belongs to.
*
* @const {RegExp} vgx
*/
const vgx: RegExp = TAG_PREFIX
? new RegExp(`tag:\\s*[=]?${TAG_PREFIX}(.+?)[,)]`, 'gi')
: /tag:\s*[=v]?(.+?)[),]/gi

commit = Object.assign({}, commit, {
version:
/tag:\s*[=v]?(.+?)[),]/g.exec(commit.gitTags)?.[1] ?? undefined
version: vgx.exec(commit.gitTags)?.[1] ?? undefined
})
}

Expand Down Expand Up @@ -126,6 +156,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
}
},
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 9c867a1

Please sign in to comment.