Skip to content

Commit 1559fc8

Browse files
committed
feat: change cli config commits structure
1 parent 51477b7 commit 1559fc8

4 files changed

Lines changed: 49 additions & 16 deletions

File tree

lib/commands/git/commit-msg.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,25 @@ git commit -m"feat(core)!: commit description"
7979
return this.#throwError( `Commit message subject should not ends with ".".` );
8080
}
8181

82-
const type = pkg.cliConfig?.commits.types[ commit.type ],
83-
scopes = new Set( pkg.cliConfig?.commits[ type?.primaryChange
82+
const type = pkg.cliConfig?.commits.types[ commit.type ] || null,
83+
scopes = new Set( Object.entries( pkg.cliConfig?.commits[ type?.primaryChange
8484
? "primaryScopes"
85-
: "secondaryScopes" ] || [] );
85+
: "secondaryScopes" ] || {} )
86+
.map( ( [ key, value ] ) => ( value
87+
? key
88+
: null ) )
89+
.filter( item => item ) );
8690

8791
// check strict type
8892
if ( pkg.cliConfig?.commits.strictType ) {
8993

9094
// commit type is not valid
9195
if ( !type ) {
92-
return this.#throwError( `Commit type is not valid. Allowed types: ${ Object.keys( pkg.cliConfig.commits.types )
96+
return this.#throwError( `Commit type is not valid. Allowed types: ${ Object.entries( pkg.cliConfig.commits.types )
97+
.map( ( key, value ) => ( value
98+
? key
99+
: null ) )
100+
.filter( item => item )
93101
.sort()
94102
.map( item => `"${ item }"` )
95103
.join( ", " ) }.` );

lib/git/changelog.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ export default class GitChangelog {
164164
#indexChanges ( commitTypes ) {
165165
this.#changesGroups = [];
166166

167+
// remove disabled commit types
168+
commitTypes = Object.entries( commitTypes ).reduce( ( commitTypes, [ key, value ] ) => {
169+
if ( value ) commitTypes[ key ] = value;
170+
171+
return commitTypes;
172+
}, {} );
173+
167174
// index primary types
168175
const primaryTypes = new Map();
169176

resources/cli.config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ commits:
8383

8484
primaryScopes: ~
8585

86-
secondaryScopes: [build, deps, docs, metadata, release, style]
86+
secondaryScopes:
87+
build: Package build related changes
88+
deps: Package dependencies updates
89+
docs: Documentation changes
90+
metadata: Package metadata changes
91+
release: Package release
92+
style: Code stylistic changes
8793

8894
docs: ~

resources/schemas/cli.config.schema.yaml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,37 @@ properties:
151151
type: object
152152
propertyNames: { type: string, format: kebab-case }
153153
additionalProperties:
154-
type: object
155-
properties:
156-
title: { type: string }
157-
primaryChange: { type: boolean }
158-
notableChange: { type: boolean }
159-
requireScope: { type: boolean }
160-
strictScope: { type: boolean }
161-
additionalProperties: false
162-
required: [primaryChange, notableChange, requireScope, strictScope]
154+
anyOf:
155+
- const: false
156+
- type: object
157+
properties:
158+
title: { type: string }
159+
primaryChange: { type: boolean }
160+
notableChange: { type: boolean }
161+
requireScope: { type: boolean }
162+
strictScope: { type: boolean }
163+
additionalProperties: false
164+
required: [primaryChange, notableChange, requireScope, strictScope]
163165

164166
primaryScopes:
165167
anyOf:
166168
- type: "null"
167-
- { type: array, items: { type: string, format: kebab-case }, minItems: 1, uniqueItems: true }
169+
- type: object
170+
propertyNames: { type: string, format: kebab-case }
171+
additionalProperties:
172+
anyOf:
173+
- const: false
174+
- type: string
168175

169176
secondaryScopes:
170177
anyOf:
171178
- type: "null"
172-
- { type: array, items: { type: string, format: kebab-case }, minItems: 1, uniqueItems: true }
179+
- type: object
180+
propertyNames: { type: string, format: kebab-case }
181+
additionalProperties:
182+
anyOf:
183+
- const: false
184+
- type: string
173185

174186
additionalProperties: false
175187
required: [requireType, strictType, types, primaryScopes, secondaryScopes]

0 commit comments

Comments
 (0)