Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I put expression inside package.json string?

Question:
How to increment version in script message? Because my release message should be always bigger to one version.

Goal: If I have already** 0.1.2 version**, I want to increment my commit message to 0.1.3 and then release.
Of course I can always update it manually, but maybe some advices how to automate this process?

{
  "version": "0.1.2",
  "scripts": {
    "release": "git commit --allow-empty  -m \\\"chore: release 0.1.2\\\"",
  

So I need to take my current version, increment it and pass into release script, what I need to use to receive this result as I expect?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"scripts": {
    "release": "git commit --allow-empty  -m {expression}",

>Solution :

You can use semver in combination with a shell script to achieve your goal.

npm install -g semver

Create a shell script that will handle version incrementation and the Git commit.

you can try below Example script for testing (release.sh):

#!/bin/bash

current_version=$(cat package.json | grep -o '"version": "[0-9.]\+"' | grep -o '[0-9.]\+')

new_version=$(semver bump patch $current_version)

git commit --allow-empty -m "chore: release $new_version"

Make sure the script is executable:

chmod +x release.sh

Update your "release" script in your package.json to call this shell script:

"scripts": {
  "release": "./release.sh"
}

Hope this helps and customize as needed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading