Version management

1. Version Category Introduction

Each NPM package has a package.json file. If you want to send a package, the version in package.json is the version number.

Version field structure: ‘0.0.0-0’

They stand for: large. Medium Minor – Pre-release number, corresponding to majon.minor.patch-prerelease

Let’s look at the version category and description in NPM.

  • major

    • If there is no pre-release number, the pre-release number is directly upgraded to a large number and all other bits are set to 0
    • Pre-release number if available:
      1. If both medium and small are 0, the pre-release number is deleted instead of upgrading the large one. That is, 2.0.0-1 becomes 2.0.0, which is what pre-publishing is for
      1. If either medium or small is not 0, there will be an upgrade of large, other bits are set to 0, clear the pre-release number. So 2.0.1-0 becomes 3.0.0
  • minor

    • If there is no pre-release number, upgrade a medium number, leave the large number untouched, and leave the small number blank
    • Pre-release number if available:
      1. If the minor is 0, do not upgrade the medium number and delete the pre-release number
      1. If the minor is not 0, there is no pre-release number
  • patch

    • If there is no pre-release number: Directly upgrade the trumpet and remove the pre-release number
    • If there is a pre-release number: Remove the pre-release number and leave the rest untouched
  • premajor

    • Directly upgrade large, medium and small set to 0, add pre-release number to 0
  • preminor

    • Directly upgrade the medium number, set the small number to 0, and add the pre-release number to 0
  • prepatch

    • Upgrade the trumpet directly and add the pre-release number to 0
  • prerelease

    • If no pre-release number is available: Add the minor number and set the pre-release number to 0
    • If there is a pre-release number, the pre-release number is upgraded

2. Use the version

Run the NPM version command to automatically change the version number in package.json.

For example, if version is 1.1.1 in package.json, then run the following command:

NPM version prerelease -m "Where you can add a description of the prerelease version number"Copy the code

The package.json version number will change to 1.1-0 and git will add a commit log.

It is important to note that NPM version execution must ensure that the working directory is clean and free of any uncommitted documents, otherwise an error will be reported.

Git submission specification

A project is a collaboration of many people, but everyone’s development habits and submission formats are not uniform, which makes it difficult to count bugs and requirements.

Therefore, the Commit Message specification is particularly important.

Benefits of formatting commit

1. Provide more historical information for quick browsing.

2. Certain documents can be filtered for quick search

3. You can directly generate change log from commit.

Format of a Commit message

What did you do brief description what did you do detailed description what did you doCopy the code
  • Category type:

    • Feat: new features
    • Fix: fix
    • Docs: document
    • Style: format
    • Refactor: Refactoring (neither a new addition nor a code change)
    • Test: Adds a test
    • Chore: Changes in the build process or in ancillary tools.
For example: fix: bug(123) fixed ………… Modify the... Feat: demand (123) Added a certain function to describe a certain function in detail (omitted)Copy the code

Automatically generate the change log

If all the commits are formatted, the change log can be automatically generated by the script when a new version is released.

Conventional – Changelog is a tool for generating Change log.

First command global installation:

$ npm install -g conventional-changelog-cli
Copy the code

Then enter the project and execute the command:

$ cd my-project
$ conventional-changelog -p angular -i CHANGELOG.md -s
Copy the code

Conventional -changelog -p angular-i changelog. md -w Generates logs on the COMMAND line, but not files

The above command will not overwrite the Changelog. md file, but will be added at the front of the file. If you want to generate all published Change logs, run the following command instead:

$ conventional-changelog -p angular -i CHANGELOG.md -s -r 0
Copy the code

If you do not need to manually modify the Changelog. md file, you can automatically submit the Changelog. md file:

conventional-changelog -p angular -i CHANGELOG.md -s && git commit -m "Docs: change the CHANGELOG. Md"
Copy the code

It is difficult to execute such a long command every time, we can configure it in NPM

{
  "scripts": {
    "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"}}Copy the code

Run the NPM run Changelog command next time.

At this point, you can see that there is a changelog.md file in the project. If your submission does not meet the specification, there may be nothing in this file at the beginning of use.

Also, it is important to note that NPM version must be used before each changelog upgrade, otherwise, commit will always have the previous record.