Skip to content

Commit

Permalink
chore: move changelog config to config directory
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Feb 18, 2023
1 parent ae90004 commit 1b54c70
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"fldv",
"flexdevelopmentllc",
"mlly",
"pathe",
"usefseventsonparentdirectory"
]
}
29 changes: 10 additions & 19 deletions changelog.config.ts → config/changelog.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits
*/

import pathe from '@flex-development/pathe'
import { CompareResult, isNIL } from '@flex-development/tutils'
import addStream from 'add-stream'
import conventionalChangelog from 'conventional-changelog'
Expand All @@ -26,12 +27,11 @@ import {
type ReadStream,
type WriteStream
} from 'node:fs'
import path from 'node:path'
import type { Readable } from 'node:stream'
import sade from 'sade'
import semver from 'semver'
import tempfile from 'tempfile'
import pkg from './package.json' assert { type: 'json' }
import pkg from '../package.json' assert { type: 'json' }

/**
* CLI flags.
Expand Down Expand Up @@ -146,7 +146,7 @@ sade('changelog', true)
: typeof outputUnreleased === 'string'
? !!outputUnreleased.trim()
: false,
pkg: { path: path.resolve('package.json') },
pkg: { path: pathe.resolve('package.json') },
// @ts-expect-error ts(2322)
preset: {
header: '',
Expand Down Expand Up @@ -276,8 +276,8 @@ sade('changelog', true)
commits: ICommit[],
key: ICommit | undefined
): GeneratedContext {
const { gitSemverTags = [], isPatch, linkCompare } = context
let { currentTag, previousTag, version = '' } = context
const { gitSemverTags = [], isPatch, linkCompare, version } = context
let { currentTag, previousTag } = context

/**
* First commit in release.
Expand All @@ -293,18 +293,6 @@ sade('changelog', true)
*/
const last_commit: ICommit | undefined = commits.at(-1)

// set version
if ([version, pkg.tagPrefix + version].includes(gitSemverTags[0]!)) {
switch (true) {
case typeof outputUnreleased === 'boolean' && outputUnreleased:
case (outputUnreleased as string).trim().length > 0:
version = 'unreleased'
break
default:
break
}
}

// set current and previous tags
if (key && (!currentTag || !previousTag)) {
currentTag = key.version ?? undefined
Expand All @@ -316,7 +304,7 @@ sade('changelog', true)
if (!previousTag) previousTag = last_commit?.hash ?? undefined
}
} else {
currentTag = /^unreleased$/i.test(version)
currentTag = /^unreleased$/i.test(version ?? '')
? currentTag ??
(typeof outputUnreleased === 'string' && outputUnreleased
? outputUnreleased
Expand Down Expand Up @@ -346,7 +334,10 @@ sade('changelog', true)
repoUrl: pkg.repository.slice(0, -4)
}
},
headerPartial: readFileSync('templates/changelog/header.hbs', 'utf8'),
headerPartial: readFileSync(
'config/templates/changelog/header.hbs',
'utf8'
),
ignoreReverted: false
}
).on('error', err => console.error(err.stack))
Expand Down
7 changes: 7 additions & 0 deletions config/templates/changelog/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## {{#if @root.linkCompare~}}
[{{currentTag}}]({{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}})
{{~else}}
{{~currentTag}}
{{~/if}}
{{~#if title}} "{{title}}"{{~/if}}
{{~#if date}} ({{date}}){{/if}}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"types": "./dist/index.d.mts",
"scripts": {
"build": "mkbuild",
"changelog": "node --loader=./loader.mjs ./changelog.config.ts",
"changelog": "node --loader=./loader.mjs ./config/changelog.config",
"check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn typecheck && NODE_ENV=production yarn pack -o %s-%v.tgz && yarn clean:pack && yarn check:types:build",
"check:format": "prettier --check .",
"check:lint": "eslint --exit-on-fatal-error --ext cjs,gql,json,jsonc,md,mjs,ts,yml --max-warnings 0 .",
Expand Down Expand Up @@ -69,6 +69,7 @@
"@commitlint/config-conventional": "17.4.2",
"@flex-development/mkbuild": "1.0.0-alpha.9",
"@flex-development/mlly": "1.0.0-alpha.9",
"@flex-development/pathe": "1.0.3",
"@graphql-eslint/eslint-plugin": "3.15.0",
"@types/chai": "4.3.4",
"@types/conventional-changelog": "3.1.1",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ __metadata:
"@commitlint/config-conventional": "npm:17.4.2"
"@flex-development/mkbuild": "npm:1.0.0-alpha.9"
"@flex-development/mlly": "npm:1.0.0-alpha.9"
"@flex-development/pathe": "npm:1.0.3"
"@flex-development/pkg-types": "npm:2.0.0"
"@flex-development/tutils": "npm:6.0.0-alpha.10"
"@graphql-eslint/eslint-plugin": "npm:3.15.0"
Expand Down

0 comments on commit 1b54c70

Please sign in to comment.