Skip to content

Instantly share code, notes, and snippets.

@scottfwalter
Created September 26, 2022 16:09
Show Gist options
  • Save scottfwalter/6fd02946f7d5ccf230bdf69ef525df1c to your computer and use it in GitHub Desktop.
Save scottfwalter/6fd02946f7d5ccf230bdf69ef525df1c to your computer and use it in GitHub Desktop.
Angular Play
#! /bin/bash
PLAYDIR="$HOME/code/angular/angular-play"
if [ $# -eq 0 ]
then
echo "Angular Version?"
read VERSION
else
VERSION="$1"
fi
echo $VERSION
cd $PLAYDIR
git br | grep "angular_$VERSION"
if [ $? -eq 1 ]
then
#branch does not exist yet
git switch "main" --discard-changes
git reset --hard
git clean -fd
rm -rf node_modules
echo "need to install angular"
git co -b "angular_$VERSION"
npx @angular/cli@$VERSION new angular-play --directory=.
git add .
git commit -m "new angular template"
fi
git switch "angular_$VERSION" --discard-changes
git reset --hard
git clean -fd
CORE_VERSION=$(cat package.json | jq -r '.dependencies["@angular/core"]')
REQUESTED_VERSION="^$VERSION"
echo $CORE_VERSION
if [[ $CORE_VERSION == $REQUESTED_VERSION.* ]]
then
echo "already have a template for this version"
npm install
else
echo "using different version as previous so need to clean node_modules"
rm -rf node_modules
npm install
fi
code .
npx ng serve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment