Skip to content

Instantly share code, notes, and snippets.

@sketchbuch
Last active April 28, 2024 11:23
Show Gist options
  • Save sketchbuch/7fb8d6ebfa7a2fce3920fadf61b6797c to your computer and use it in GitHub Desktop.
Save sketchbuch/7fb8d6ebfa7a2fce3920fadf61b6797c to your computer and use it in GitHub Desktop.
Update version in package.json and someother file via bash
# =========================================================
# Increase version in both package.json and some other file
# =========================================================
# I needed to update the version in package.json and in a typescript class.
# Version in class is used to check if caches need dropping
# Didn't want to include package.json in the typescript class as this would have added the whole package.json to the dist bundle
# So I created this script to update both.
# Will exit if no version provided, but no check is made if the format of the version is correct.
if [ -z $1 ]
then
echo "Unable to continue, no version provided."
echo "Please provide a version number when running."
exit 1
fi
FILE_PATH=./src/some/other/file.ts
FILE_PATH_PKGJSON=./package.json
echo "Changing version to: '$1'"
# Assumes line in FILE_PATH starts with " private readonly _version: string", change to suit your usecase.
sed -i "s% private readonly _version: string.*% private readonly _version: string = '$1'%" "$FILE_PATH"
sed -i "s% \"version\":.*% \"version\": \"$1\"\,%" "$FILE_PATH_PKGJSON"
@sketchbuch
Copy link
Author

I don't usually create bash scripts, so let me know if anything could be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment