Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cz commitlint #2547

Merged
merged 17 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5bf9830
Merge pull request #1 from conventional-changelog/master
curly210102 Mar 14, 2021
b188de3
Merge branch 'master' of https://github.com/conventional-changelog/co…
curly210102 Mar 25, 2021
c4b0bac
Merge branch 'master' of https://github.com/conventional-changelog/co…
curly210102 Mar 28, 2021
5b60836
feat(cz-commitlint): finish basic features inspired by cz-conventiona…
curly210102 Apr 1, 2021
1d27083
test(cz-commitlint): Add Util Function Tests
curly210102 Apr 1, 2021
56f3074
Merge branch 'master' of https://github.com/conventional-changelog/co…
curly210102 Apr 7, 2021
12a596f
Merge branch 'master' into feature/cz-commitlint
curly210102 Apr 7, 2021
56a4d8b
feat(cz-commitlint): add prompt field to commitlint config file, add …
curly210102 Apr 12, 2021
6a989ff
test(cli): update 'should print config' test for add 'prompt' field
curly210102 Apr 12, 2021
20c3598
fix(cz-commitlint): fix question input start with new line, fix foote…
curly210102 Apr 12, 2021
efa47f9
docs(cz-commitlint): update commitlint doc "Guide: Use prompt"
curly210102 Apr 12, 2021
69cab32
docs(cz-commitlint): add Prompt Configuration introdution
curly210102 Apr 13, 2021
0396ab1
fix(config-conventional): update to pass ci
curly210102 Apr 13, 2021
e08e3ef
chore: update registry to default npm
curly210102 Apr 14, 2021
a53f814
fix(cz-commitlint): compatible old version @commitlint/load, remove n…
curly210102 Apr 14, 2021
e44b9e1
fix(cz-commitlint): fix load prompt config from commitlint config file
curly210102 Apr 15, 2021
db6a7b1
test(cz-commitlint): move the test files flat with source code files …
curly210102 Apr 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ lib/
package.json.lerna_backup
/*.iml
tsconfig.tsbuildinfo
coverage
7 changes: 4 additions & 3 deletions @commitlint/cli/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import {fix, git} from '@commitlint/test';
import execa from 'execa';
import merge from 'lodash/merge';
import fs from 'fs-extra';
import merge from 'lodash/merge';
import path from 'path';

const bin = require.resolve('../cli.js');

Expand Down Expand Up @@ -494,7 +494,8 @@ test('should print config', async () => {
defaultIgnores: undefined,
plugins: {},
rules: { 'type-enum': [ 2, 'never', [ 'foo' ] ] },
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
prompt: {}
}"
`);
});
Expand Down
99 changes: 99 additions & 0 deletions @commitlint/config-conventional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,103 @@ module.exports = {
],
],
},
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing:",
enum: {
feat: {
description: 'A new feature',
title: 'Features',
emoji: '✨',
},
fix: {
description: 'A bug fix',
title: 'Bug Fixes',
emoji: '🐛',
},
docs: {
description: 'Documentation only changes',
title: 'Documentation',
emoji: '📚',
},
style: {
description:
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
title: 'Styles',
emoji: '💎',
},
refactor: {
description:
'A code change that neither fixes a bug nor adds a feature',
title: 'Code Refactoring',
emoji: '📦',
},
perf: {
description: 'A code change that improves performance',
title: 'Performance Improvements',
emoji: '🚀',
},
test: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨',
},
build: {
description:
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
title: 'Builds',
emoji: '🛠',
},
ci: {
description:
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
title: 'Continuous Integrations',
emoji: '⚙️',
},
chore: {
description: "Other changes that don't modify src or test files",
title: 'Chores',
emoji: '♻️',
},
revert: {
description: 'Reverts a previous commit',
title: 'Reverts',
emoji: '🗑',
},
},
},
scope: {
description:
'What is the scope of this change (e.g. component or file name)',
},
subject: {
description:
'Write a short, imperative tense description of the change',
},
body: {
description: 'Provide a longer description of the change',
},
isBreaking: {
description: 'Are there any breaking changes?',
},
breakingBody: {
description:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
},
breaking: {
description: 'Describe the breaking changes',
},
isIssueAffected: {
description: 'Does this change affect any open issues?',
},
issuesBody: {
description:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)',
},
},
},
};
1 change: 1 addition & 0 deletions @commitlint/cz-commitlint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
88 changes: 88 additions & 0 deletions @commitlint/cz-commitlint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
> Commitizen adapter using the commitlint.config.js

# @commitlint/cz-commitlint

This is a commitizen adapter, using this adapter, commitizen works based on commitlint.config.js.

Submit by commitizen, lint by commitlint, just need maintain one configuration file, Consistent and Scalable.

The interactive process is inspired by [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog).

## Getting started

### Using commitizen adapter

```bash
npm install --save-dev @commitlint/cz-commitlint commitizen
```

In package.json

```
{
"scripts": {
"commit": "git-cz"
},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
}
}
```

### Configure commitlint

```bash
# Install commitlint cli and conventional config
npm install --save-dev @commitlint/config-conventional @commitlint/cli

# Simple: config with conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

# commitlint configuration is shareable,
# Install lerna-scopes
npm install --save-dev @commitlint/config-lerna-scopes
# Scalable: config with lerna-scopes in monorepo mode
echo "module.exports = {extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes']};" > commitlint.config.js
```

### Set Git Hooks by husky

```base

# ------- using npm ----------
# Install Husky
npm install husky --save-dev
# Active hooks
npx husky install
# Add commitlint hook
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
# Add commitizen hook
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'


# ------- using yarn ----------
# Install Husky
yarn add husky --dev
# Active hooks
yarn husky install
# Add commitlint hook
yarn husky add .husky/commit-msg 'yarn --no-install commitlint --edit $1'
# Add commitizen hook
yarn husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'

```

### Try it out

```bash
git add .
npm run commit
# or
yarn run commit
```

## Related

- [Commitlint Shared Configuration](https://github.com/conventional-changelog/commitlint#shared-configuration) - You can find more shared configurations are available to install and use with commitlint
5 changes: 5 additions & 0 deletions @commitlint/cz-commitlint/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[x] jest Test
[x] insert prompt settings to commitlint.config.js
[] support multi line
[] support emoji and title
[] recognize "signed-off-by" and "references-empty" rules
19 changes: 19 additions & 0 deletions @commitlint/cz-commitlint/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions @commitlint/cz-commitlint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "cz-commitlint",
"version": "1.0.0",
"description": "Commitizen adapter using the commitlint.config.js",
"main": "./lib/index.js",
"files": [
"lib"
],
"scripts": {
"commit": "git-cz"
},
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/commitlint.git"
},
"engineStrict": true,
"engines": {
"node": ">= 10"
},
"author": "Curly Brackets <[email protected]>",
"license": "MIT",
"config": {
"commitizen": {
"path": "./@commitlint/cz-commitlint"
}
},
"dependencies": {
"@commitlint/load": "^12.1.1",
"@commitlint/types": "^12.1.1",
"chalk": "^4.1.0",
"lodash": "^4.17.21",
"word-wrap": "^1.2.3"
},
"peerDependencies": {
"commitizen": "^4.0.3",
"inquirer": "^8.0.0"
},
"devDependencies": {
"@types/inquirer": "^7.3.1"
}
}
Loading