Skip to content

Instantly share code, notes, and snippets.

@OoogleBoogle
Last active July 31, 2016 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OoogleBoogle/db5d97b8d3e631f3ae7cfd9fde33521d to your computer and use it in GitHub Desktop.
Save OoogleBoogle/db5d97b8d3e631f3ae7cfd9fde33521d to your computer and use it in GitHub Desktop.
setup_react.sh
# Colors
ESC_SEQ="\x1b["
RESET=$ESC_SEQ"39;49;00m"
RED=$ESC_SEQ"31;01m"
GREEN=$ESC_SEQ"32;01m"
#initial checks
git="$(which git)"
npm="$(which npm)"
node="$(which node)"
if [ ! $git ]
then
echo -p "$RED You need Git installed for this to work. Sorry. $RESET"; exit;
elif [ ! $npm ]
then
echo "$RED You don't appear to have NPM installed. Please check.$RESET"; exit;
elif [ ! $node ]
then
echo "$RED You don't appear to have node. Please check.$RESET"; exit;
fi
echo
#double check user wants to install
echo -e "$GREEN Do you want to install the react template in this folder?$RESET"
read -p "y/n " -n 1 -r yn
case $yn in
[Yn]* ) echo "Awesome!"; break;;
[Nn]* ) echo "Not installing"; exit;;
esac
echo
#get the future file name
echo -e "$GREEN What would you like to name your project? Please use - for spaces. e.g my-project:$RESET "
read -p "name: " name
# check text editor so it can be opened automatically if required
# New Check
atom="$(which atom)"
if [ "$atom" ]
then atom="Atom"
fi
subl="$(which subl)"
if [ "$subl" ]
then subl="Sublime"
fi;
code="$(which code)"
if [ "$code" ]
then code="VS_Code"
fi
declare -a choices=($atom $subl $code);
for choice in "${choices[@]}"; do
if [ $choice ]
then
read -p "Open in $choice? " -n 1 -r yn
case $yn in
[Yy]* ) choice=$choice; break;;
[Nn]* ) echo;;
esac
fi
done
if [ "$choice" = "Atom" ]
then
editor="atom ."
elif [ "$choice" = "VS_Code" ]
then
editor="code ."
elif [ "$choice" = "Sublime" ]
then
editor="subl ."
else
editor=""
fi
# check if hub is installed
hub="$(which hub)"
if [ "$hub" ]
then
hub="hub create"
else
hub=""
fi
echo
#DO IT!
git clone https://github.com/OoogleBoogle/react-template.git
mv react-template $name
cd $name
rm -fr .git
npm i
git init
echo "### $name" > readme.md
echo " " >> readme.md
echo "##### Created from the template [here](https://github.com/OoogleBoogle/react-template.git)" >> readme.md
git add .
git commit -m "Initial Commit"
if [ "$hub" ]
then
$hub
git push origin master
fi
$editor
npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment