-
-
Save mulholo/6d3930847ccbb072d89ecedad40f6e37 to your computer and use it in GitHub Desktop.
Creates a new folder with Git and JavaScript optionally setup.
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
#!/bin/bash | |
# new-proj | |
# while number of args > 0 | |
while [[ $# -gt 0 ]] | |
do | |
case $1 in | |
-j | --javascript ) | |
# set the $JS variable to true if the -j or --javascript option is passed | |
JS=true | |
shift # change the position of the arguments by 1 | |
;; | |
-g | --git ) | |
# set the $GIT variable to true if the -g or --git option is passed | |
GIT=true | |
shift # change the position of the arguments by 1 | |
;; | |
*) | |
# set any other argument as the directory name | |
DIRNAME=$1 | |
shift # change the position of the arguments by 1 | |
esac; # end switch statement | |
done | |
# exit if directory name isn't set | |
if [ -z ${DIRNAME+x} ]; then | |
echo "ERROR: Could not find a directory name" | |
exit 1 | |
fi | |
setup-git() { | |
echo "Setting up Git" | |
if [[ $1 = true ]]; then | |
# add JS relevant lines to .gitignore | |
echo "node_modules" >> $DIRNAME/.gitignore | |
echo "dist" >> $DIRNAME/.gitignore | |
fi | |
git init --quiet $DIRNAME | |
} | |
setup-js() { | |
echo "Setting up JavaScript" | |
# create index.js | |
touch "$DIRNAME"/index.js | |
# change working directory to our passed in directoyr name | |
cd $DIRNAME | |
# init package.json and yarn, auto-answer yes to all Qs | |
yarn init --silent --yes | |
# jump back to level above | |
cd .. | |
} | |
# make a directory for our new project | |
mkdir $DIRNAME | |
# make some files | |
touch "$DIRNAME"/index.html | |
touch "$DIRNAME"/style.css | |
if [ "$JS" = true ]; then | |
setup-js | |
fi | |
if [ "$GIT" = true ]; then | |
setup-git "$JS" | |
fi | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment