Skip to content

Instantly share code, notes, and snippets.

@jisaacks
Last active December 10, 2018 15:45
Show Gist options
  • Save jisaacks/8ebf1e594da71b2fe8ec to your computer and use it in GitHub Desktop.
Save jisaacks/8ebf1e594da71b2fe8ec to your computer and use it in GitHub Desktop.
Use a git repo as a template for new projects

Setup Instructions

Create ~/bin directory

mkdir ~/bin

Add ~/bin to $PATH

sudo zsh -c "if ! grep '^/Users/`whoami`/bin$' /etc/paths > /dev/null; then echo '/Users/`whoami`/bin' >> /etc/paths; fi"

Download Script

curl https://gist.githubusercontent.com/jisaacks/8ebf1e594da71b2fe8ec/raw/newapp --retry 5 > ~/bin/newapp

Make Script Exacutable

chmod +x ~/bin/newapp

Usage

specify 2 arguments:

  • github user/repo to use as template
  • new project name
newapp jisaacks/app_template my_new_app
#!/bin/zsh
local RED='\033[1;31m'
local BLUE='\033[1;34m'
local NC='\033[0m' # No Color
local REPO=$1
local PROJ=$2
local ORG='tiy-atl-js-feb-2016'
# CHECK FOR ARGUMENTS
if [ -z $REPO ] || [ -z $PROJ ]; then
echo "${RED}usage:${BLUE} $(basename $0) user/repo new_project_name${NC}"
exit 1
fi
# CHECK REPO FOR OWNER
if ! echo $REPO | grep "/" > /dev/null
then
REPO="$ORG/$REPO"
fi
# MAKE SURE NEW PROJECT NAME DOESN'T ALREADY EXIST
if [ -e $PROJ ]; then
echo "${RED}$PROJ aleady exists"
exit 1
fi
# CLONE GIT REPO
git clone "git@github.com:$REPO.git" $PROJ
# CD TO NEW PROJECT
cd $PROJ
# REMOVE REPO DATA
rm -rf "./.git"
# RUN `npm install` IF package.json IS PRESENT
if [ -e "./package.json" ]
then npm install
fi
# RUN `bower install` IF bower.json IS PRESENT
if [ -e "./bower.json" ]
then bower install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment