-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 77c1eb9
Showing
9 changed files
with
1,298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git | ||
node_modules | ||
*.lock |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# @dewebsitejongens/cz-customizable | ||
|
||
The customizable Commitizen plugin (or standalone utility) to help achieve consistent commit messages like | ||
the [AngularJS team](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines). | ||
|
||
## Installation | ||
|
||
Install the module | ||
|
||
```bash | ||
yarn add @dewebsitejongens/cz-customizable --dev | ||
``` | ||
|
||
## Usage | ||
|
||
Before you can commit with consistent commit message like the AngularJS team add the following in your `package.json` file: | ||
|
||
``` | ||
"scripts": { | ||
... | ||
"commit": "git add . && cz-customizable && git push", | ||
} | ||
``` | ||
|
||
To configure cz-customizable you could use our default configuration, put the code in `.cz-config.js` file: | ||
|
||
```js | ||
/* | ||
* Copyright (c) 2021 De Website Jongens. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
module.exports = { | ||
scopes: [ | ||
{ | ||
name: "mobile" | ||
}, | ||
{ | ||
name: "web" | ||
}, | ||
{ | ||
name: "shared" | ||
} | ||
], | ||
messages: { | ||
type: "What type of changes are you committing:", | ||
scope: "\nEnlighten us with the scope (optional):", | ||
customScope: "Add the scope of your liking:", | ||
subject: "Write a short and simple description of the change:\n", | ||
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n', | ||
breaking: "List any BREAKING CHANGES (optional):\n", | ||
footer: "List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n", | ||
confirmCommit: "Are you sure you the above looks right?" | ||
}, | ||
types: [ | ||
{ | ||
emoji: "🐛", | ||
value: "fix", | ||
name: "🐛 fix: Changes that fix a bug" | ||
}, | ||
{ | ||
emoji: "🚀", | ||
value: "feat", | ||
name: "🚀 feat: Changes that introduce a new feature" | ||
}, | ||
{ | ||
emoji: "🔍", | ||
value: "refactor", | ||
name: "🔍 refactor: Changes that neither fixes a bug nor adds a feature" | ||
}, | ||
{ | ||
emoji: "💡", | ||
value: "test", | ||
name: "💡 test: Adding missing tests" | ||
}, | ||
{ | ||
emoji: "💅", | ||
value: "style", | ||
name: "💅 style: Changes that do not impact the code base \n (white-space, formatting, missing semi-colons, etc)" | ||
}, | ||
{ | ||
emoji: "📝", | ||
value: "docs", | ||
name: "📝 docs: Changes to the docs" | ||
}, | ||
{ | ||
emoji: "🤖", | ||
value: "chore", | ||
name: "🤖 chore: Changes to the build process or auxiliary tools\n and or libraries such as auto doc generation" | ||
}, | ||
{ | ||
emoji: "⏪", | ||
value: 'revert', | ||
name: '⏪ revert: Revert to a commit' | ||
} | ||
], | ||
allowTicketNumber: true, | ||
isTicketNumberRequired: false, | ||
ticketNumberPrefix: "#", | ||
ticketNumberRegExp: "\\d{1,5}", | ||
allowCustomScopes: true, | ||
allowBreakingChanges: [ | ||
"feat", | ||
"fix", | ||
"chore" | ||
], | ||
breakingPrefix: "🚧 BREAKING CHANGES 🚧", | ||
footerPrefix: "CLOSES ISSUE:", | ||
subjectLimit: 100 | ||
}; | ||
``` | ||
|
||
## Options | ||
|
||
Here are the options you can set in your `.cz-config.js`: | ||
|
||
* **subjectLimit**: {number, default 100}: This is the commit first line. Example: `feat: this is a new feature` or `feat(scopePayments): this is a new feature` | ||
* **subjectSeparator**: {string, default ': '}: This is the subject separator. Example: `feat: this is a new feature` | ||
* **typePrefix**: {string, default ''}: This is the commit type prefix. Example: config: `{ typePrefix: '[' }`, result: `[feat: this is a new feature` | ||
* **typeSuffix**: {string, default ''}: This is the commit type suffix. Example: config: `{ typePrefix: '[', typeSuffix: ']', subjectSeparator: ' ' }`, result: `[feat] this is a new feature` | ||
|
||
* **scopes**: {Array of Strings}: Specify the scopes for your particular project. Eg.: for some banking system: ["acccounts", "payments"]. For another travelling application: ["bookings", "search", "profile"] | ||
* **scopeOverrides**: {Object where key contains a Array of String}: Use this when you want to override scopes for a specific commit type. Example bellow specify scopes when type is `fix`: | ||
``` | ||
scopeOverrides: { | ||
fix: [ | ||
{name: 'merge'}, | ||
{name: 'style'}, | ||
{name: 'e2eTest'}, | ||
{name: 'unitTest'} | ||
] | ||
} | ||
``` | ||
* **allowCustomScopes**: {boolean, default false}: adds the option `custom` to scope selection so you can still type a scope if you need. | ||
* **allowBreakingChanges**: {Array of Strings: default none}. List of commit types you would like to the question `breaking change` prompted. Eg.: ['feat', 'fix']. | ||
* **skipQuestions**: {Array of Strings: default none}. List of questions you want to skip. Eg.: ['body', 'footer']. | ||
* **appendBranchNameToCommitMessage**: If you use `cz-customizable` with `cz-customizable-ghooks`, you can get the branch name automatically appended to the commit message. This is done by a commit hook on `cz-customizable-ghooks`. This option has been added on `cz-customizable-ghooks`, v1.3.0. Default value is `true`. | ||
* **ticketNumberPrefix**: {string, default 'ISSUES CLOSED:'}: Set custom prefix for footer ticker number. | ||
* **breakingPrefix**: {string, default 'BREAKING CHANGE:'}: Set a custom prefix for the breaking change block in commit messages. | ||
* **footerPrefix**: {string, default 'ISSUES CLOSED:'}: Set a custom prefix for the footer block in commit messages. Set to empty string to remove prefix. | ||
* **breaklineChar**: {string, default '|'}: It gets replaced with \n to create the breakline in your commit message. This is supported for fields `body` and `footer` at the moment. | ||
* **upperCaseSubject**: { boolean, default false }: Capitalizes first subject letter if set to `true` | ||
* **askForBreakingChangeFirst**: { boolean, default false }: It asks for breaking change as first question when set to `true` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* Copyright (c) 2021 De Website Jongens. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
const { execSync } = require('child_process'); | ||
const inquirer = require('inquirer'); | ||
|
||
const app = require('../src/index'); | ||
|
||
console.info('cz-customizable standalone version'); | ||
|
||
const commit = (commitMessage) => { | ||
try { | ||
execSync(`git commit -m "${commitMessage}"`, { stdio: [0, 1, 2] }); | ||
} catch (error) { | ||
console.error('>>> ERROR', error.error); | ||
} | ||
}; | ||
|
||
app.prompter(inquirer, commit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@dewebsitejongens/cz-customizable", | ||
"version": "0.1.0", | ||
"description": "Commitizen customizable adapter following the conventional-changelog format.", | ||
"authors": [ | ||
{ | ||
"name": "Nick Vlug", | ||
"email": "nick@dewebsitejongens.nl" | ||
} | ||
], | ||
"license": "GPL-3.0", | ||
"keywords": [ | ||
"websitejongens", | ||
"dewebsitejongens", | ||
"commitizen", | ||
"cz-customizable" | ||
], | ||
"homepage": "https://github.com/dewebsitejongens/cz-customizable/tree/main/README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dewebsitejongens/cz-customizable.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dewebsitejongens/cz-customizable/issues" | ||
}, | ||
"dependencies": { | ||
"editor": "^1.0.0", | ||
"find-config": "^1.0.0", | ||
"inquirer": "^8.1.2", | ||
"lodash.concat": "^4.5.0", | ||
"lodash.filter": "^4.6.0", | ||
"lodash.find": "^4.6.0", | ||
"lodash.get": "^4.4.2", | ||
"lodash.reject": "^4.6.0", | ||
"lodash.trim": "^4.5.1", | ||
"temp": "^0.9.4", | ||
"word-wrap": "^1.2.3" | ||
}, | ||
"bin": { | ||
"cz-customizable": "./bin/customizable.js" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"src", | ||
"types", | ||
"bin/customizable.js" | ||
], | ||
"types": "./types/index.d.ts", | ||
"main": "./src/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright (c) 2021 De Website Jongens. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
const get = require('lodash.get'); | ||
const trim = require('lodash.trim'); | ||
const find = require('lodash.find'); | ||
|
||
const wrap = require('word-wrap'); | ||
|
||
const defaultSubjectSeparator = ': '; | ||
const defaultMaxLineWidth = 100; | ||
const defaultBreaklineChar = '|'; | ||
|
||
const addTicketNumber = (ticketNumber, config) => { | ||
if (!ticketNumber) { | ||
return ''; | ||
} | ||
if (config.ticketNumberPrefix) { | ||
return `${config.ticketNumberPrefix + ticketNumber.trim()} `; | ||
} | ||
return `${ticketNumber.trim()} `; | ||
}; | ||
|
||
const addScope = (scope, config) => { | ||
const separator = get(config, 'subjectSeparator', defaultSubjectSeparator); | ||
|
||
if (!scope) return separator; // it could be type === WIP. So there is no scope | ||
|
||
return `(${scope.trim()})${separator}`; | ||
}; | ||
|
||
const addSubject = (subject) => trim(subject); | ||
|
||
const addType = (type, config) => { | ||
const prefix = get(config, 'typePrefix', ''); | ||
const suffix = get(config, 'typeSuffix', ''); | ||
|
||
return trim(`${prefix}${type}${suffix}`); | ||
}; | ||
|
||
const addEmoji = (type, config) => { | ||
const types = get(config, 'types', []); | ||
const emoji = get( | ||
find(types, (t) => t.value === type), | ||
'emoji', | ||
'❓', | ||
); | ||
|
||
return `${emoji} `; | ||
}; | ||
|
||
const addBreaklinesIfNeeded = (value, breaklineChar = defaultBreaklineChar) => value | ||
.split(breaklineChar) | ||
.join('\n') | ||
.valueOf(); | ||
|
||
const addFooter = (footer, config) => { | ||
if (config && config.footerPrefix === '') return `\n\n${footer}`; | ||
|
||
const footerPrefix = config && config.footerPrefix ? config.footerPrefix : 'ISSUES CLOSED:'; | ||
|
||
return `\n\n${footerPrefix} ${addBreaklinesIfNeeded(footer, config.breaklineChar)}`; | ||
}; | ||
|
||
const escapeSpecialChars = (result) => { | ||
// eslint-disable-next-line no-useless-escape | ||
const specialChars = ['`']; | ||
|
||
let newResult = result; | ||
// eslint-disable-next-line array-callback-return | ||
specialChars.map((item) => { | ||
// If user types "feat: `string`", the commit preview should show "feat: `\string\`". | ||
// Don't worry. The git log will be "feat: `string`" | ||
newResult = result.replace(new RegExp(item, 'g'), '\\`'); | ||
}); | ||
return newResult; | ||
}; | ||
|
||
module.exports = (answers, config) => { | ||
const wrapOptions = { | ||
trim: true, | ||
newline: '\n', | ||
indent: '', | ||
width: defaultMaxLineWidth, | ||
}; | ||
|
||
// Hard limit this line | ||
// eslint-disable-next-line max-len | ||
const head = ( | ||
addType(answers.type, config) | ||
+ addScope(answers.scope, config) | ||
+ addEmoji(answers.type, config) | ||
+ addTicketNumber(answers.ticketNumber, config) | ||
+ addSubject(answers.subject) | ||
).slice(0, defaultMaxLineWidth); | ||
|
||
// Wrap these lines at 100 characters | ||
let body = wrap(answers.body, wrapOptions) || ''; | ||
body = addBreaklinesIfNeeded(body, config.breaklineChar); | ||
|
||
const breaking = wrap(answers.breaking, wrapOptions); | ||
const footer = wrap(answers.footer, wrapOptions); | ||
|
||
let result = head; | ||
if (body) { | ||
result += `\n\n${body}`; | ||
} | ||
if (breaking) { | ||
const breakingPrefix = config && config.breakingPrefix ? config.breakingPrefix : 'BREAKING CHANGE:'; | ||
result += `\n\n${breakingPrefix}\n${breaking}`; | ||
} | ||
if (footer) { | ||
result += addFooter(footer, config); | ||
} | ||
|
||
return escapeSpecialChars(result); | ||
}; |
Oops, something went wrong.