update package.json version automatically

后端 未结 12 2063
长发绾君心
长发绾君心 2020-12-02 04:37

Before I do a small release and tag it, I\'d like to update the package.json to reflect the new version of the program.

Is there a way to edit the file package

12条回答
  •  春和景丽
    2020-12-02 04:55

    First, you need to understand the rules for upgrading the versioning number. You can read more about the semantic version here.

    Each version will have x.y.z version where it defines for different purpose as shown below.

    1. x - major, up this when you have major changes and it is huge discrepancy of changes occurred.
    2. y - minor, up this when you have new functionality or enhancement occurred.
    3. z - patch, up this when you have bugs fixed or revert changes on earlier version.

    To run the scripts, you can define it in your package.json.

    "script": {
        "buildmajor": "npm version major && ng build --prod",
        "buildminor": "npm version minor && ng build --prod",
        "buildpatch": "npm version patch && ng build --prod"
    }
    

    In your terminal, you just need to npm run accordingly to your needs like

    npm run buildpatch
    

    If run it in git repo, the default git-tag-version is true and if you do not wish to do so, you can add below command into your scripts:

    --no-git-tag-version
    

    for eg: "npm --no-git-tag-version version major && ng build --prod"

提交回复
热议问题