English
defaultSubject
Suitable for
defaultBody, defaultFooterPrefix, defaultIssues
- Initialize the complation template, you can use Tab or → to quickly complete; you can also use the Enter output template directly.
(detailed categories, provides prefix template, and directly output template...)- E.g Element-Plus,which is a Vue3 component library,The Commit of the component modified is strict
sh# https://element-plus.org/en-US/guide/commit-examples.html [type](scope): [messages] # e.g: feat(components): [button] I did something with button
# https://element-plus.org/en-US/guide/commit-examples.html [type](scope): [messages] # e.g: feat(components): [button] I did something with button
- We can get the component name through
git status
information - Then pass it to defaultSubject, so that you can quickly use template.
Reducing duplicate input and spelling errors
js
// commitlint.config.js
const { execSync } = require('child_process')
const gitStatus = execSync('git status --porcelain || true')
.toString()
.trim()
.split('\n')
const subjectComplete = gitStatus
.find((r) => ~r.indexOf('M packages/components'))
?.replace(/\//g, '%%')
?.match(/packages%%components%%((\w|-)*)/)?.[1]
/** @type {import('cz-git').UserConfig} */
module.exports = {
prompt: {
defaultSubject: subjectComplete && `[${subjectComplete}] `,
},
};
// commitlint.config.js
const { execSync } = require('child_process')
const gitStatus = execSync('git status --porcelain || true')
.toString()
.trim()
.split('\n')
const subjectComplete = gitStatus
.find((r) => ~r.indexOf('M packages/components'))
?.replace(/\//g, '%%')
?.match(/packages%%components%%((\w|-)*)/)?.[1]
/** @type {import('cz-git').UserConfig} */
module.exports = {
prompt: {
defaultSubject: subjectComplete && `[${subjectComplete}] `,
},
};
Using highly customizable
cz-git
makes committing more convenient and more customary. Welcome to share.