Skip to content

Commit b7d53cb

Browse files
committed
feat(config): config
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 0bb540d commit b7d53cb

File tree

10 files changed

+143
-118
lines changed

10 files changed

+143
-118
lines changed

.commitlintrc.json

+1-59
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,3 @@
11
{
2-
"defaultIgnores": true,
3-
"extends": ["@commitlint/config-conventional"],
4-
"formatter": "@commitlint/format",
5-
"ignores": [],
6-
"rules": {
7-
"body-max-line-length": [2, "always", 5000],
8-
"scope-case": [2, "always", ["kebab-case", "lower-case"]],
9-
"scope-enum": [
10-
2,
11-
"always",
12-
[
13-
"build",
14-
"cjs",
15-
"config",
16-
"deps",
17-
"deps-bundle",
18-
"deps-dev",
19-
"deps-opt",
20-
"deps-peer",
21-
"esm",
22-
"exports",
23-
"github",
24-
"install",
25-
"internal",
26-
"loader",
27-
"nvm",
28-
"pkg",
29-
"release",
30-
"rules",
31-
"scripts",
32-
"spelling",
33-
"tests",
34-
"ts",
35-
"types",
36-
"vscode",
37-
"workflows",
38-
"yarn"
39-
]
40-
],
41-
"subject-case": [1, "always", "lower-case"],
42-
"type-enum": [
43-
2,
44-
"always",
45-
[
46-
"build",
47-
"chore",
48-
"ci",
49-
"docs",
50-
"feat",
51-
"fix",
52-
"perf",
53-
"refactor",
54-
"revert",
55-
"style",
56-
"test",
57-
"wip"
58-
]
59-
]
60-
}
2+
"extends": "@flex-development"
613
}

__tests__/ts/v4/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"#fixtures/*": ["__fixtures__/*"],
3333
"#src": ["src/index"],
3434
"#src/*": ["src/*"],
35-
"#tests/*": ["__tests__/*"]
35+
"#tests/*": ["__tests__/*"],
36+
"@flex-development/commitlint-config": ["src/index"]
3637
},
3738
"preserveConstEnums": true,
3839
"preserveSymlinks": false,

config/changelog.config.ts

+30-27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
* @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits
99
*/
1010

11+
import {
12+
Type,
13+
parserPreset,
14+
type Commit
15+
} from '@flex-development/commitlint-config'
1116
import pathe from '@flex-development/pathe'
1217
import { CompareResult, isNIL } from '@flex-development/tutils'
1318
import addStream from 'add-stream'
@@ -17,7 +22,7 @@ import type {
1722
CommitGroup,
1823
GeneratedContext
1924
} from 'conventional-changelog-writer'
20-
import type { Commit, ICommit } from 'conventional-commits-parser'
25+
import type { ICommit } from 'conventional-commits-parser'
2126
import dateformat from 'dateformat'
2227
import type mri from 'mri'
2328
import {
@@ -136,7 +141,8 @@ sade('changelog', true)
136141
*
137142
* @const {Readable} changelog
138143
*/
139-
const changelog: Readable = conventionalChangelog(
144+
// @ts-expect-error type definitions are incorrect
145+
const changelog: Readable = conventionalChangelog<Commit>(
140146
{
141147
append: false,
142148
debug: debug ? console.debug.bind(console) : undefined,
@@ -147,24 +153,23 @@ sade('changelog', true)
147153
? !!outputUnreleased.trim()
148154
: false,
149155
pkg: { path: pathe.resolve('package.json') },
150-
// @ts-expect-error ts(2322)
151156
preset: {
152157
header: '',
153-
name: 'conventionalcommits',
158+
name: parserPreset.name,
154159
releaseCommitMessageFormat: 'release: {{currentTag}}',
155160
types: [
156-
{ section: ':package: Build', type: 'build' },
157-
{ section: ':house_with_garden: Housekeeping', type: 'chore' },
158-
{ section: ':robot: Continuous Integration', type: 'ci' },
159-
{ section: ':pencil: Documentation', type: 'docs' },
160-
{ section: ':sparkles: Features', type: 'feat' },
161-
{ section: ':bug: Fixes', type: 'fix' },
162-
{ section: ':fire: Performance Improvements', type: 'perf' },
163-
{ section: ':zap: Refactors', type: 'refactor' },
164-
{ section: ':rewind: Reverts', type: 'revert' },
165-
{ hidden: true, type: 'style' },
166-
{ section: ':white_check_mark: Testing', type: 'test' },
167-
{ hidden: true, type: 'wip' }
161+
{ section: ':package: Build', type: Type.BUILD },
162+
{ section: ':house_with_garden: Housekeeping', type: Type.CHORE },
163+
{ section: ':robot: Continuous Integration', type: Type.CI },
164+
{ section: ':pencil: Documentation', type: Type.DOCS },
165+
{ section: ':sparkles: Features', type: Type.FEAT },
166+
{ section: ':bug: Fixes', type: Type.FIX },
167+
{ section: ':fire: Performance Improvements', type: Type.PERF },
168+
{ section: ':mechanical_arm: Refactors', type: Type.REFACTOR },
169+
{ section: ':wastebasket: Reverts', type: Type.REVERT },
170+
{ hidden: true, type: Type.STYLE },
171+
{ section: ':white_check_mark: Testing', type: Type.TEST },
172+
{ hidden: true, type: Type.WIP }
168173
]
169174
},
170175
releaseCount,
@@ -183,25 +188,23 @@ sade('changelog', true)
183188
transform(commit: Commit, apply: Options.Transform.Callback): void {
184189
return void apply(null, {
185190
...commit,
186-
committerDate: dateformat(
187-
commit.committerDate!,
188-
'yyyy-mm-dd',
189-
true
190-
),
191+
committerDate: dateformat(commit.committerDate, 'yyyy-mm-dd', true),
191192
mentions: commit.mentions.filter(m => m !== 'flexdevelopment'),
192193
// @ts-expect-error ts(2322)
193194
raw: commit,
194195
references: commit.references.filter(ref => ref.action !== null),
195-
shortHash: commit.hash!.slice(0, 7),
196196
version: commit.gitTags ? vgx.exec(commit.gitTags)?.[1] : undefined
197197
})
198-
}
198+
},
199+
warn: parserPreset.parserOpts.warn
199200
},
200201
{},
201-
{},
202202
{
203-
issuePrefixesCaseSensitive: true
203+
debug: debug ? parserPreset.parserOpts.warn : undefined,
204+
format:
205+
'%B%n-hash-%n%H%n-shortHash-%n%h%n-gitTags-%n%d%n-committerDate-%n%ci%n'
204206
},
207+
parserPreset.parserOpts,
205208
{
206209
/**
207210
* Sorts commit groups in descending order by group title.
@@ -299,8 +302,8 @@ sade('changelog', true)
299302

300303
// try setting previous tag based on current tag
301304
if (gitSemverTags.includes(currentTag ?? '')) {
302-
const { version } = key
303-
previousTag = gitSemverTags[gitSemverTags.indexOf(version!) + 1]
305+
const { version = '' } = key
306+
previousTag = gitSemverTags[gitSemverTags.indexOf(version) + 1]
304307
if (!previousTag) previousTag = last_commit?.hash ?? undefined
305308
}
306309
} else {

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"import": "./dist/index.mjs",
3131
"require": "./dist/index.cjs"
3232
},
33+
"./config": {
34+
"import": "./dist/config/index.mjs",
35+
"require": "./dist/config/index.cjs"
36+
},
3337
"./package.json": "./package.json"
3438
},
3539
"main": "./dist/index.cjs",
@@ -72,7 +76,6 @@
7276
"typecheck:watch": "vitest typecheck"
7377
},
7478
"dependencies": {
75-
"@commitlint/config-conventional": "17.4.4",
7679
"@commitlint/types": "17.4.4",
7780
"@flex-development/tutils": "6.0.0-alpha.10",
7881
"@types/conventional-commits-parser": "3.0.3",

src/config/__tests__/config.spec.ts

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @file Unit Tests - config
3+
* @module commitlint-config/config/tests/unit/config
4+
*/
5+
6+
import TEST_SUBJECT from '../config'
7+
import parserPreset from '../parser-preset'
8+
import prompt from '../prompt'
9+
import rules from '../rules'
10+
11+
describe('unit:config/config', () => {
12+
describe('defaultIgnores', () => {
13+
it('should set default ignore rules', () => {
14+
expect(TEST_SUBJECT.defaultIgnores).to.be.true
15+
})
16+
})
17+
18+
describe('formatter', () => {
19+
it('should be default report formatter', () => {
20+
expect(TEST_SUBJECT.formatter).to.equal('@commitlint/format')
21+
})
22+
})
23+
24+
describe('helpUrl', () => {
25+
it('should be default help URL', () => {
26+
// Arrange
27+
const expected: string =
28+
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
29+
30+
// Act + Expect
31+
expect(TEST_SUBJECT.helpUrl).to.equal(expected)
32+
})
33+
})
34+
35+
describe('ignores', () => {
36+
it('should not set additional ignore rules', () => {
37+
expect(TEST_SUBJECT.ignores).to.be.an('array').of.length(0)
38+
})
39+
})
40+
41+
describe('parserPreset', () => {
42+
it('should set commit parser preset', () => {
43+
expect(TEST_SUBJECT)
44+
.to.have.property('parserPreset')
45+
.deep.equal(parserPreset)
46+
})
47+
})
48+
49+
describe('plugins', () => {
50+
it('should not push additional plugins', () => {
51+
expect(TEST_SUBJECT.plugins).to.be.an('array').of.length(0)
52+
})
53+
})
54+
55+
describe('prompt', () => {
56+
it('should set prompt configuration', () => {
57+
expect(TEST_SUBJECT).to.have.property('prompt').deep.equal(prompt)
58+
})
59+
})
60+
61+
describe('rules', () => {
62+
it('should set commit rules', () => {
63+
expect(TEST_SUBJECT).to.have.property('rules').deep.equal(rules)
64+
})
65+
})
66+
})

src/config/config.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @file Config - config
3+
* @module commitlint-config/config/config
4+
*/
5+
6+
import type { Config } from '#src/interfaces'
7+
import defaultIgnores from './default-ignores'
8+
import formatter from './formatter'
9+
import helpUrl from './help-url'
10+
import ignores from './ignores'
11+
import parserPreset from './parser-preset'
12+
import plugins from './plugins'
13+
import prompt from './prompt'
14+
import rules from './rules'
15+
16+
/**
17+
* `commitlint` configuration object.
18+
*
19+
* @see https://commitlint.js.org/#/reference-configuration
20+
*
21+
* @const {Config} config
22+
*/
23+
const config: Config = {
24+
defaultIgnores,
25+
formatter,
26+
helpUrl,
27+
ignores,
28+
parserPreset,
29+
plugins,
30+
prompt,
31+
rules
32+
}
33+
34+
export default config

src/config/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @module commitlint-config/config
44
*/
55

6+
export { default as config, default } from './config'
67
export { default as defaultIgnores } from './default-ignores'
78
export { default as formatter } from './formatter'
89
export { default as helpUrl } from './help-url'

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"#fixtures/*": ["__fixtures__/*"],
3232
"#src": ["src/index"],
3333
"#src/*": ["src/*"],
34-
"#tests/*": ["__tests__/*"]
34+
"#tests/*": ["__tests__/*"],
35+
"@flex-development/commitlint-config": ["src/index"]
3536
},
3637
"preserveConstEnums": true,
3738
"preserveSymlinks": false,
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
1-
import type { Nilable, Nullable } from '@flex-development/tutils'
1+
import type { Commit } from '@flex-development/commitlint-config'
22
import {} from 'conventional-commits-parser'
33

44
declare module 'conventional-commits-parser' {
5-
export interface CommitBase {
6-
body: Nullable<string>
7-
committerDate: string
8-
footer: Nullable<string>
9-
gitTags?: Nilable<string>
10-
hash: string
11-
header: Nullable<string>
12-
mentions: string[]
13-
merge: Nullable<string>
14-
notes: import('conventional-commits-parser').Commit.Note[]
15-
references: import('conventional-commits-parser').Commit.Reference[]
16-
revert: Nullable<import('conventional-commits-parser').Commit.Revert>
17-
scope?: Nilable<string>
18-
subject?: Nilable<string>
19-
type?: Nilable<string>
20-
}
5+
export interface CommitBase extends Commit {}
216

227
export interface ICommit extends CommitBase {
238
raw: CommitBase
24-
shortHash: string
259
version?: string | undefined
2610
}
2711
}

yarn.lock

+1-11
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,6 @@ __metadata:
190190
languageName: node
191191
linkType: hard
192192

193-
"@commitlint/config-conventional@npm:17.4.4":
194-
version: 17.4.4
195-
resolution: "@commitlint/config-conventional@npm:17.4.4"
196-
dependencies:
197-
conventional-changelog-conventionalcommits: "npm:^5.0.0"
198-
checksum: 1dce765072a61354a1e17078441c2422b0166bc0c974d082835e76b0117e787b426063e5c978c68a59c8ebf46de9f499157902de18122538432a12efcc7dcce2
199-
languageName: node
200-
linkType: hard
201-
202193
"@commitlint/config-validator@npm:^17.4.4":
203194
version: 17.4.4
204195
resolution: "@commitlint/config-validator@npm:17.4.4"
@@ -1155,7 +1146,6 @@ __metadata:
11551146
resolution: "@flex-development/commitlint-config@workspace:."
11561147
dependencies:
11571148
"@commitlint/cli": "npm:17.4.4"
1158-
"@commitlint/config-conventional": "npm:17.4.4"
11591149
"@commitlint/lint": "npm:17.4.4"
11601150
"@commitlint/types": "npm:17.4.4"
11611151
"@flex-development/mkbuild": "npm:1.0.0-alpha.14"
@@ -3441,7 +3431,7 @@ __metadata:
34413431
languageName: node
34423432
linkType: hard
34433433

3444-
"conventional-changelog-conventionalcommits@npm:5.0.0, conventional-changelog-conventionalcommits@npm:^5.0.0":
3434+
"conventional-changelog-conventionalcommits@npm:5.0.0":
34453435
version: 5.0.0
34463436
resolution: "conventional-changelog-conventionalcommits@npm:5.0.0"
34473437
dependencies:

0 commit comments

Comments
 (0)