@awesome-tools/commitizen
v1.5.1
Published
Commitizen for multi or mono repo projects π₯
Maintainers
Readme
Commitizen for multi or mono repo projects π₯
Table of Contents
Installation
This module is distributed via npm which is bundled with node and
should be installed as one of your project's devDependencies. Add commitizen and cz-git by running:
npm install --save-dev @awesome-tools/commitizen cz-gitUsage
Then add a script to your package.json:
{
scripts: {
cm: 'commitizen'
}
}You can now use this script with yarn or npm
yarn cmOR
yarn commitizencz.config.ts
You can optionally create a cz.config.ts file in the root of your project to customize the behavior of commitizen. Here is the configuration used in this monorepo as an example:
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { definePrompt } from 'cz-git'
function addSignedOffByTrailer(commitMessage: string) {
try {
const authorIdentity = execSync('git var GIT_AUTHOR_IDENT', {
encoding: 'utf-8'
}).trim()
const sobLine = authorIdentity.replace(/^(.*>).*$/, 'Signed-off-by: $1')
const modifiedMessage = execSync(
`git interpret-trailers --if-missing add --trailer "${sobLine}"`,
{ input: commitMessage, encoding: 'utf-8' }
)
return modifiedMessage.trim()
} catch (error) {
if (error instanceof Error) {
console.error('Failed to add Signed-off-by trailer:', error.message)
} else {
console.error('Error', error)
}
return commitMessage
}
}
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const packages = fs.readdirSync(path.resolve(__dirname, 'packages'))
const tools = fs.readdirSync(path.resolve(__dirname, 'tools'))
export const scopes = [
{
name: 'release'
},
{
name: 'ci'
},
{
name: 'test'
},
{
name: 'core'
},
{
name: 'tool'
},
{
name: 'backend'
},
...[...packages, ...tools].map(name => ({ name }))
]
export const types = [
{
value: 'feat',
name: 'π feat:\tAdding a new feature',
emoji: 'π'
},
{
value: 'fix',
name: 'π fix:\tFixing a bug',
emoji: 'π'
},
{
value: 'hotfix',
name: 'π hotfix:\tCritical hotfix',
emoji: 'π'
},
{
value: 'docs',
name: 'ποΈ docs:\tAdd or update documentation',
emoji: 'ποΈ'
},
{
value: 'style',
name: 'π style:\tAdd or update styles, ui or ux',
emoji: 'π'
},
{
value: 'refactor',
name: 'β»οΈ refactor:\tCode change that neither fixes a bug nor adds a feature',
emoji: 'β»οΈ'
},
{
value: 'perf',
name: 'β‘οΈperf:\tCode change that improves performance',
emoji: 'β‘οΈ'
},
{
value: 'test',
name: 'π§ͺ test:\tAdding tests cases',
emoji: 'π§ͺ'
},
{
value: 'chore',
name: 'π chore:\tChanges to the build process or auxiliary tools\n\t\tand libraries such as documentation generation',
emoji: 'π'
},
{
value: 'revert',
name: 'π« revert:\tRevert to a commit',
emoji: 'π«'
},
{
value: 'wip',
name: 'π§ wip:\tWork in progress',
emoji: 'π§'
},
{
value: 'build',
name: 'π¦ build:\tAdd or update regards to build process',
emoji: 'π¦'
},
{
value: 'ci',
name: 'π ci:\tFixing CI build',
emoji: 'π'
},
{
value: 'security',
name: 'π¨ security:\tFixing security issues',
emoji: 'π¨'
},
{
value: 'init',
name: 'β¨ init:\tInitial commit',
emoji: 'β¨'
}
]
export default definePrompt({
allowCustomScopes: false,
allowEmptyScopes: false,
allowBreakingChanges: ['feat', 'fix'],
markBreakingChangeMode: true,
minSubjectLength: 10,
maxSubjectLength: 200,
maxHeaderLength: 200,
useEmoji: true,
emojiAlign: 'left',
enableMultipleScopes: true,
useCommitSignGPG: true,
scopeEnumSeparator: ',',
formatMessageCB: ({ defaultMessage }) => {
return addSignedOffByTrailer(defaultMessage)
},
types,
scopes
})Things to know
This project is a wrapper around https://github.com/commitizen/cz-cli for multi/mono repo projects and it uses the cz-git adapter.
Issues
Looking to contribute? Look for the Good First Issue label. π
π Bugs
Please file an issue for bugs, missing documentation, or unexpected behavior.
π‘ Feature Requests
Please file an issue to suggest new features. Vote on feature requests by adding a π. This helps maintainers prioritize what to work on.
NX
This library was generated with Nx.
Building
Run nx build commitizen to build the library.
Credits
This project wouldn't have been possible without the amazing work done by
