Skip to content

Commit c77381d

Browse files
authored
Feature/cz commitlint (conventional-changelog#2547)
* feat(cz-commitlint): finish basic features inspired by cz-conventional-changelog * test(cz-commitlint): Add Util Function Tests * feat(cz-commitlint): add prompt field to commitlint config file, add tests for cz-commitlint prompt field is working for prompt config, settled in commitlint config file, can be defined by shared configurations. * test(cli): update 'should print config' test for add 'prompt' field * fix(cz-commitlint): fix question input start with new line, fix footer config apply * docs(cz-commitlint): update commitlint doc "Guide: Use prompt" * docs(cz-commitlint): add Prompt Configuration introdution * fix(config-conventional): update to pass ci modify format * chore: update registry to default npm * fix(cz-commitlint): compatible old version @commitlint/load, remove no longer used dependencies * fix(cz-commitlint): fix load prompt config from commitlint config file * test(cz-commitlint): move the test files flat with source code files to keep consistency
1 parent af5b72f commit c77381d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3340
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ lib/
1111
package.json.lerna_backup
1212
/*.iml
1313
tsconfig.tsbuildinfo
14+
coverage

@commitlint/cli/src/cli.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import path from 'path';
21
import {fix, git} from '@commitlint/test';
32
import execa from 'execa';
4-
import merge from 'lodash/merge';
53
import fs from 'fs-extra';
4+
import merge from 'lodash/merge';
5+
import path from 'path';
66

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

@@ -494,7 +494,8 @@ test('should print config', async () => {
494494
defaultIgnores: undefined,
495495
plugins: {},
496496
rules: { 'type-enum': [ 2, 'never', [ 'foo' ] ] },
497-
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
497+
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
498+
prompt: {}
498499
}"
499500
`);
500501
});

@commitlint/config-conventional/index.js

+99
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,103 @@ module.exports = {
3333
],
3434
],
3535
},
36+
prompt: {
37+
questions: {
38+
type: {
39+
description: "Select the type of change that you're committing:",
40+
enum: {
41+
feat: {
42+
description: 'A new feature',
43+
title: 'Features',
44+
emoji: '✨',
45+
},
46+
fix: {
47+
description: 'A bug fix',
48+
title: 'Bug Fixes',
49+
emoji: '🐛',
50+
},
51+
docs: {
52+
description: 'Documentation only changes',
53+
title: 'Documentation',
54+
emoji: '📚',
55+
},
56+
style: {
57+
description:
58+
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
59+
title: 'Styles',
60+
emoji: '💎',
61+
},
62+
refactor: {
63+
description:
64+
'A code change that neither fixes a bug nor adds a feature',
65+
title: 'Code Refactoring',
66+
emoji: '📦',
67+
},
68+
perf: {
69+
description: 'A code change that improves performance',
70+
title: 'Performance Improvements',
71+
emoji: '🚀',
72+
},
73+
test: {
74+
description: 'Adding missing tests or correcting existing tests',
75+
title: 'Tests',
76+
emoji: '🚨',
77+
},
78+
build: {
79+
description:
80+
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
81+
title: 'Builds',
82+
emoji: '🛠',
83+
},
84+
ci: {
85+
description:
86+
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
87+
title: 'Continuous Integrations',
88+
emoji: '⚙️',
89+
},
90+
chore: {
91+
description: "Other changes that don't modify src or test files",
92+
title: 'Chores',
93+
emoji: '♻️',
94+
},
95+
revert: {
96+
description: 'Reverts a previous commit',
97+
title: 'Reverts',
98+
emoji: '🗑',
99+
},
100+
},
101+
},
102+
scope: {
103+
description:
104+
'What is the scope of this change (e.g. component or file name)',
105+
},
106+
subject: {
107+
description:
108+
'Write a short, imperative tense description of the change',
109+
},
110+
body: {
111+
description: 'Provide a longer description of the change',
112+
},
113+
isBreaking: {
114+
description: 'Are there any breaking changes?',
115+
},
116+
breakingBody: {
117+
description:
118+
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
119+
},
120+
breaking: {
121+
description: 'Describe the breaking changes',
122+
},
123+
isIssueAffected: {
124+
description: 'Does this change affect any open issues?',
125+
},
126+
issuesBody: {
127+
description:
128+
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
129+
},
130+
issues: {
131+
description: 'Add issue references (e.g. "fix #123", "re #123".)',
132+
},
133+
},
134+
},
36135
};

@commitlint/cz-commitlint/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode

@commitlint/cz-commitlint/README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
> Commitizen adapter using the commitlint.config.js
2+
3+
# @commitlint/cz-commitlint
4+
5+
This is a commitizen adapter, using this adapter, commitizen works based on commitlint.config.js.
6+
7+
Submit by commitizen, lint by commitlint, just need maintain one configuration file, Consistent and Scalable.
8+
9+
The interactive process is inspired by [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog).
10+
11+
## Getting started
12+
13+
### Using commitizen adapter
14+
15+
```bash
16+
npm install --save-dev @commitlint/cz-commitlint commitizen
17+
```
18+
19+
In package.json
20+
21+
```
22+
{
23+
"scripts": {
24+
"commit": "git-cz"
25+
},
26+
"config": {
27+
"commitizen": {
28+
"path": "@commitlint/cz-commitlint"
29+
}
30+
}
31+
}
32+
```
33+
34+
### Configure commitlint
35+
36+
```bash
37+
# Install commitlint cli and conventional config
38+
npm install --save-dev @commitlint/config-conventional @commitlint/cli
39+
40+
# Simple: config with conventional
41+
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
42+
43+
# commitlint configuration is shareable,
44+
# Install lerna-scopes
45+
npm install --save-dev @commitlint/config-lerna-scopes
46+
# Scalable: config with lerna-scopes in monorepo mode
47+
echo "module.exports = {extends: ['@commitlint/config-conventional', '@commitlint/config-lerna-scopes']};" > commitlint.config.js
48+
```
49+
50+
### Set Git Hooks by husky
51+
52+
```base
53+
54+
# ------- using npm ----------
55+
# Install Husky
56+
npm install husky --save-dev
57+
# Active hooks
58+
npx husky install
59+
# Add commitlint hook
60+
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
61+
# Add commitizen hook
62+
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'
63+
64+
65+
# ------- using yarn ----------
66+
# Install Husky
67+
yarn add husky --dev
68+
# Active hooks
69+
yarn husky install
70+
# Add commitlint hook
71+
yarn husky add .husky/commit-msg 'yarn --no-install commitlint --edit $1'
72+
# Add commitizen hook
73+
yarn husky add .husky/prepare-commit-msg 'exec < /dev/tty && node_modules/.bin/cz --hook || true'
74+
75+
```
76+
77+
### Try it out
78+
79+
```bash
80+
git add .
81+
npm run commit
82+
# or
83+
yarn run commit
84+
```
85+
86+
## Related
87+
88+
- [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

@commitlint/cz-commitlint/TODO

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[x] jest Test
2+
[x] insert prompt settings to commitlint.config.js
3+
[] support multi line
4+
[] support emoji and title
5+
[] recognize "signed-off-by" and "references-empty" rules

@commitlint/cz-commitlint/license.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "cz-commitlint",
3+
"version": "1.0.0",
4+
"description": "Commitizen adapter using the commitlint.config.js",
5+
"main": "./lib/index.js",
6+
"files": [
7+
"lib"
8+
],
9+
"scripts": {
10+
"commit": "git-cz"
11+
},
12+
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/conventional-changelog/commitlint.git"
16+
},
17+
"engineStrict": true,
18+
"engines": {
19+
"node": ">= 10"
20+
},
21+
"author": "Curly Brackets <[email protected]>",
22+
"license": "MIT",
23+
"config": {
24+
"commitizen": {
25+
"path": "./@commitlint/cz-commitlint"
26+
}
27+
},
28+
"dependencies": {
29+
"@commitlint/load": "^12.1.1",
30+
"@commitlint/types": "^12.1.1",
31+
"chalk": "^4.1.0",
32+
"lodash": "^4.17.21",
33+
"word-wrap": "^1.2.3"
34+
},
35+
"peerDependencies": {
36+
"commitizen": "^4.0.3",
37+
"inquirer": "^8.0.0"
38+
},
39+
"devDependencies": {
40+
"@types/inquirer": "^7.3.1"
41+
}
42+
}

0 commit comments

Comments
 (0)