Skip to content

Instantly share code, notes, and snippets.

@victorocna
Last active April 15, 2023 09:16
Show Gist options
  • Save victorocna/00772af37d5c2695acdd5befb271db43 to your computer and use it in GitHub Desktop.
Save victorocna/00772af37d5c2695acdd5befb271db43 to your computer and use it in GitHub Desktop.
Jump start local node projects
#!/bin/bash
if [ $# -eq 0 ]; then
echo "no arguments"
exit 1
fi
react_repo=$1
react_branch=$2
api_repo=$3
api_branch=$4
# Step 1: React repo
cd ~/Code/$react_repo
echo "On $react_repo"
# Make sure local files are up to date
git pull
git checkout $react_branch
git pull
# Check if temporary file exists and add it when necessary
if [ ! -e ~/Code/$react_repo/package.log ]; then
touch ~/Code/$react_repo/package.log
fi
# Check if we need to install NPM dependencies
now_checksum=$(md5sum ~/Code/$react_repo/package.json | awk '{ print $1 }')
last_checksum=$(while IFS='' read -r line || [[ -n "$line" ]]; do echo "$line"; done < ~/Code/$react_repo/package.log)
# If checksums are different, save the latest checksum and install NPM dependencies
if [[ ! "$now_checksum" == "$last_checksum" ]]; then
echo $now_checksum > ~/Code/$react_repo/package.log
echo "Installing NPM dependencies"
npm ci --silent
else
echo "Checksums match, skipping NPM dependencies"
fi
# Run the local environment
gnome-terminal --tab --title=$react_repo -- npm run dev
# Step 2: API repo
cd ~/Code/$api_repo
echo "On $api_repo"
# Make sure local files are up to date
git pull
git checkout $api_branch
git pull
# Check if temporary file exists and add it when necessary
if [ ! -e ~/Code/$api_repo/package.log ]; then
touch ~/Code/$api_repo/package.log
fi
# Check if we need to install NPM dependencies
now_checksum=$(md5sum ~/Code/$api_repo/package.json | awk '{ print $1 }')
last_checksum=$(while IFS='' read -r line || [[ -n "$line" ]]; do echo "$line"; done < ~/Code/$api_repo/package.log)
# If checksums are different, save the latest checksum and install NPM dependencies
if [[ ! "$now_checksum" == "$last_checksum" ]]; then
echo $now_checksum > ~/Code/$api_repo/package.log
echo "Installing NPM dependencies"
npm ci --silent
else
echo "Checksums match, skipping NPM dependencies"
fi
# Run the local environment
gnome-terminal --tab --title=$api_repo -- npm run dev
# Step 3: Open the browser and enjoy!
firefox --new-tab http://localhost:8080 >/dev/null 2>&1
@victorocna
Copy link
Author

Jump start

Jump start local node projects with style.

Usage

jump frsah beta frsah-api beta

Where:

  • jump = linux alias of the executable file
  • $1 argument = react git repository
  • $2 argument = react git branch
  • $3 argument = api git repository
  • $4 argument = api git branch

Initial config

  • Save this file in any folder
  • Make the file executable with chmod +x
  • Add the jump alias to the executable file
  • Enjoy!

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