Skip to content

Instantly share code, notes, and snippets.

@mulholo
Created February 28, 2019 15:23
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 mulholo/6d3930847ccbb072d89ecedad40f6e37 to your computer and use it in GitHub Desktop.
Save mulholo/6d3930847ccbb072d89ecedad40f6e37 to your computer and use it in GitHub Desktop.
Creates a new folder with Git and JavaScript optionally setup.
#!/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