Last active
January 16, 2024 13:23
-
-
Save alvincrespo/dda534d3500c336bfff4f871b1a034a9 to your computer and use it in GitHub Desktop.
Updates your node version across files (package.json, .node-version and circleci/config.yml)
This file contains hidden or 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
#!/bin/bash | |
# Load NODE_VERSION from .env file | |
export $(grep NODE_VERSION .env | xargs) | |
# Check if NODE_VERSION is set | |
if [ -z "$NODE_VERSION" ]; then | |
echo "NODE_VERSION is not set in .env file." | |
exit 1 | |
fi | |
# Update .node-version | |
echo $NODE_VERSION > .node-version | |
# Update package.json | |
# Assuming you want to change the "engines" field | |
jq --arg ver "$NODE_VERSION" '.engines.node = $ver' package.json > tmp.json && mv tmp.json package.json | |
# Update circleci/config.yml | |
# Replace the existing node version with the new one | |
sed -i.bak "s/node-version: \".*\"/node-version: \"$NODE_VERSION\"/" .circleci/config.yml && rm .circleci/config.yml.bak | |
echo "Files updated successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment