scopes
scopes, usually to define the scope of this commit, there are generally two types: according to the project code distinction such as monorepo , the other is project business distinction
Scopes for project code
If you need to manage multiple packages for a better experience, for example use: pnpm | lerna.js to manage monorepo you can Use the path and fs modules to dynamically define the scopes (scopes) display in the commit message.
// .commitlintrc.js
const fs = require('node:fs')
const path = require('node:path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
prompt: {
scopes: [...packages]
}
}// .commitlintrc.js
const fs = require('node:fs')
const path = require('node:path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
prompt: {
scopes: [...packages]
}
}If you define a scope-enum using the commitlint rule, it will be imported automatically.
// .commitlintrc.js
const fs = require('node:fs')
const path = require('node:path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
rules: {
'scope-enum': [2, 'always', [...packages]]
}
}// .commitlintrc.js
const fs = require('node:fs')
const path = require('node:path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
rules: {
'scope-enum': [2, 'always', [...packages]]
}
}
Scopes for business system
// .commitlintrc.js
module.exports = {
prompt: {
scopes: ['app', 'home', 'account', 'comment']
}
}// .commitlintrc.js
module.exports = {
prompt: {
scopes: ['app', 'home', 'account', 'comment']
}
}Of course, if you want to add description information to the module-wide customization to display on the command line, you can use name and value to define.
// .commitlintrc.js
module.exports = {
prompt: {
scopes: [
{ value: 'app', name: 'app: System business' },
{ value: 'home', name: 'home: Homepage' },
{ value: 'account', name: 'account: Account related' },
{ value: 'comment', name: 'comment: Comment related' },
]
}
}// .commitlintrc.js
module.exports = {
prompt: {
scopes: [
{ value: 'app', name: 'app: System business' },
{ value: 'home', name: 'home: Homepage' },
{ value: 'account', name: 'account: Account related' },
{ value: 'comment', name: 'comment: Comment related' },
]
}
}
Checkbox mode
- use → or Space to choice
- use Enter to submit
// .commitlintrc.js
const fs = require('fs')
const path = require('path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
prompt: {
scopes: [...packages],
enableMultipleScopes: true,
scopeEnumSeparator: ","
}
}// .commitlintrc.js
const fs = require('fs')
const path = require('path')
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
module.exports = {
prompt: {
scopes: [...packages],
enableMultipleScopes: true,
scopeEnumSeparator: ","
}
}
TIP
In checkbox mode, if defaultScope is passed as a string[], it will default-select and pin top the options whose values match those within the scopes range list.
Input mode
If you don't want to use selection mode, you want to use input mode.
Can use the custom scope input instead
module.exports = {
messages: { customScope: 'What is the scope of this change:' },
skipQuestions: ['scope'],
defaultScope: '___CUSTOM___:'
}module.exports = {
messages: { customScope: 'What is the scope of this change:' },
skipQuestions: ['scope'],
defaultScope: '___CUSTOM___:'
}TIP
If you want to get the completion effect in input mode, Same you can add ___CUSTOM___: to the prefix of content
module.exports = {
messages: { customScope: 'What is the scope of this change:' },
skipQuestions: ['scope'],
defaultScope: '___CUSTOM___:Hello World'
}module.exports = {
messages: { customScope: 'What is the scope of this change:' },
skipQuestions: ['scope'],
defaultScope: '___CUSTOM___:Hello World'
}[Advanced] cache your custom scope
- Cache your custom inputs scope and can be displayed next time and shown in the scope list
- Discussion and demo video: Zhengqbbb/cz-git#104
- Playground and source code: Zhengqbbb/czgit-playground/cache-scope
TIP
If cz-git detects that allowEmptyScopes and allowCustomScopes have very strict rules (both set to false) and the scopes selection list has only one item, it will automatically skip question and output
TIP
The following code can get the HOME directory at runtime,
you can use it with fs and path for default global custom configuration.
const USER_HOME = process.env.HOME || process.env.USERPROFILE
// console.log(USER_HOME) === echo "$HOME"const USER_HOME = process.env.HOME || process.env.USERPROFILE
// console.log(USER_HOME) === echo "$HOME"Using highly customizable
cz-gitmakes committing more convenient and more customary. Welcome to share.
cz-git