function
For some items that need to manually input update logs, this tool can automatically output update logs and format the content of update logs for later maintenance. At present, it mainly has the following function modules.
- Cz — Customize git commit
- Log: Automatically generates the Changelog. MD log file
- Lint — Verifies commit information
Installing dependency packages
npm install jimi-web-changelog --save
// or
yarn add jimi-web-changelog --save-dev
Copy the code
I. CZ module
1. Install the Commitizen dependency package
cnpm i commitizen –save-dev
2. Add the following content to package.json
{... "config": { "commitizen": { "path": "./node_modules/jimi-web-changelog/lib/cz" } }, }Copy the code
3. Create the following script command in package.json
{
"cz": "git add . && git cz"
}
Copy the code
Output the commit information as prompted, as shown in the following example:
2. Log module
1. Install the Conventional – Changelog – CLI dependency package
cnpm i conventional-changelog-cli --save-dev
Copy the code
2. Create the following command
{... "script": { "log": "Xconvention-changelog --config node_modules/jimi-web-changelog/lib/log -i changelog. md-s -r 0",}} > If the number at the end is 1, Generate current version changes, if 0, generate all log files.Copy the code
Example 3.
Lint module
1. Install the Husky CommitLint dependency
cnpm i husky commitlint --save-dev
Copy the code
2. Import the following configuration in package.json.
{... "husky": { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, }Copy the code
3. Create.commitlint.js or commitlint.config.js in the root directory of the project
For details, refer to the CommitLint official, for example:
module.exports = Object.assign({}, require('jimi-web-changelog/lib/lint'), {
rules: {
'subject-empty': [2.'never'].'type-empty': [2.'never'].'type-enum': [2.'always'['New features'.'repair'. ] ]}}Copy the code
advice
Can be used with Husky and Lint-stage for better effect. It validates your formatting and fixes bad formatting every time you submit your code. For details, see package.json and.eslintrc in your current root directory.
Q&A
1. No files added to staging! Did you forget to run git add?
There should be no git add. commit caused by file changes. Try making changes to the project and save again.
2. Run the log update command.CHANGELOG.MDContent not updated?
The log information is updated only during each iteration. You can try to label the most sealed version.
3. MAC cannot run git command.
Try installing Xcode.
xcode-select –install
4. Does the printed log have no version number?
The version number is currently supported in the format of vx.x and 👀, right?
5. How does JS read the MD file?
If the project uses Webpack, use markdown-loader.
Write tool library for the first time, inevitably have flaws, welcome everyone PR, but also please mouth mercy 😄 like words to a star barCopy the code