Skip to content

Instantly share code, notes, and snippets.

@kingcons
Forked from timwco/README.md
Last active July 7, 2017 01:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kingcons/a25733c233faf10847cbb4ff557e6843 to your computer and use it in GitHub Desktop.
Save kingcons/a25733c233faf10847cbb4ff557e6843 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

Open ~/.zpreztorc in your editor. Find an existing line that starts with export $PATH. If it exists, tack $HOME/bin: after the equals sign and double quote. If there is no such line, add it to the bottom as follows:

export PATH="$HOME/bin:$PATH"

Download Script

curl https://gist.githubusercontent.com/kingcons/a25733c233faf10847cbb4ff557e6843/raw/2145332aa48a4d531a836079a71b8720bc88e4f7/newapp --retry 5 > ~/bin/newapp

Make Script Executable

chmod +x ~/bin/newapp

Usage

Specify 2 arguments:

  • The first may be either the name of a repo in our course organization or a full user/repo
  • The folder name of the new project
newapp template jquery-intro

How to you as a student might use the newapp tool.

  1. Navigate to your projects folder (or wherever you store projects)
  2. Run $ newapp template <project-name> where "project-name" is the name of your project
    • Note that the template is a specific repo in our organization
  3. Change directory into your project $ cd <project-name>
  4. Initialize the repo $ git init
  5. Build something
#!/bin/zsh
local RED='\033[1;31m'
local BLUE='\033[1;34m'
local NC='\033[0m' # No Color
local REPO=$1
local PROJ=$2
# 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="tiy-atl-js-jan-2017/$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 "https://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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment