Last active
April 28, 2024 11:23
-
-
Save sketchbuch/7fb8d6ebfa7a2fce3920fadf61b6797c to your computer and use it in GitHub Desktop.
Update version in package.json and someother file via bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================= | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't usually create bash scripts, so let me know if anything could be improved.