Skip to content
Browse files

Merge pull request #13 from andreas-marschke/relocateable-buildscript

Relocateable buildscript
  • Loading branch information...
2 parents b7efd36 + ebe77b9 commit 5034e2fa77c13f581a4230e87cf10378bfae5274 @roblarsen roblarsen committed Mar 29, 2012
Showing with 123 additions and 32 deletions.
  1. +123 −32 createproject.sh
View
155 createproject.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
#Generate a new project from your HTML5 Boilerplate repo clone
#by: Rick Waldron & Michael Cetrulo
@@ -27,50 +27,141 @@
#
# find project root (also ensure script is ran from within repo)
-src=$(git rev-parse --show-toplevel) || {
- echo "try running the script from within html5-boilerplate directories." >&2
- exit 1
+
+version="1.0"
+print_version() {
+ echo "$0 (c) 2011 by Rick Waldron & Michael Cetrulo version $version"
}
-[[ -d $src ]] || {
- echo "fatal: could not determine html5-boilerplate's root directory." >&2
- echo "try updating git." >&2
- exit 1
+
+print_help() {
+ print_version
+ echo "USAGE: $0 [--src SRC] [--dst DST] NAME"
+ echo "OPTIONS:"
+ echo "--src -s SRC \t set the source directory where your html5boilerplate lives"
+ echo "--dst -d DST \t set the destination directory in which to create your project"
+ echo "--vcs VCS \t make the new location a VCS repository. Currently supported"
+ echo " \t VCSs are: git and hg(mercurial)."
+ echo "--commit -c \t if set will commit the copied h5bp sources into the VCS."
+ echo " \t this only works with the --vcs option set"
+ echo ""
+ echo "If --src is not set it will use the toplevel dir of the current git dir"
+ echo "this behaviour expects that you are in the git repository of h5bp under /build"
+ echo ""
+ echo "If --dst is not set it will try to create the directory in the current directory"
+ echo "You can also set the same options in the ~/.h5bprc file"
+ echo "Here are the possible options:"
+ echo "\tsrc\t\t-\tThe source directory from where h5bp is located"
+ echo "\tdst\t\t-\tThe destination in which the new project shoul be created"
+ echo "\twhich_vcs\t-\tThe vcs you want to use"
+ echo "\tcommit_init\t-\tset this to \"yes\" if you want to commit the contents of the new project"
+ echo "Here is an example for the syntax(It is basically how shell variables are set):"
+ echo ""
+ echo "src=\"~/src/html5boilerplate\""
+ echo "dst=\"~/src\""
+ echo "which_vcs=\"git\""
+ echo "commit_init=\"yes\""
+ echo ""
}
-if [ $# -eq 1 ]
-then
- # get a name for new project from command line arguments
- name="$1"
+# this will be overridden if --src is set on the commandline
+src="./"
+dst="./"
+project_name=""
+with_vcs="no"
+which_vcs=""
+commit_init="no"
+
+if [ -e $HOME/.h5bprc ]; then
+ . $HOME/.h5bprc
fi
-# get a name for new project from input
-while [[ -z $name ]]
+while test "$1" != ""
do
- echo "To create a new html5-boilerplate project, enter a new directory name:"
- read name || exit
+ case $1 in
+ --help|-h)
+ print_help
+ exit 0
+ ;;
+ --version|-v)
+ print_version
+ exit 0
+ ;;
+ --src|-s)
+ shift
+ if [ -d $1 ]
+ then
+ src="$1"
+ fi
+ ;;
+ --dst|-d)
+ shift
+ if [ -d "$1" ]
+ then
+ dst="$1"
+ fi
+ ;;
+ --vcs)
+ with_vcs="yes"
+ shift
+ which_vcs=$1
+ ;;
+ --commit|-c)
+ commit_init="yes"
+ shift
+ ;;
+ *)
+ project_name="$1"
+ shift
+ ;;
+ esac
done
-if [[ "$name" = /* ]]
-then
- dst=$name
-else
- dst=$src/../$name
+if [ ! -d "$src" ]; then
+ src=$(git rev-parse --show-toplevel) || {
+ echo "fatal: could not determine html5-boilerplate's root directory." >&2
+ exit 1
+ }
fi
-if [[ -d $dst ]]
+dst="$dst/$project_name/"
+
+if [ -d $dst ]
then
- echo "$dst exists"
-else
- #create new project
- mkdir -p -- "$dst" || exit 1
+ echo "ERROR: Project $project_name already exists at $dst"
+ exit 1
+fi
+
+#create new project
+mkdir -p "$dst" || exit 1
- #success message
- echo "Created Directory: $dst"
+#success message
+echo "Created Directory: $dst"
- cd -- "$src"
- cp -vr -- css js img build *.html *.xml *.txt *.png *.ico .htaccess "$dst"
+cp -vr -- $src/css $src/js $src/img $src/build $src/*.html $src/*.xml $src/*.txt $src/*.png $src/*.ico $src/.htaccess "$dst"
- #success message
- echo "Created Project: $dst"
+if [ "$with_vcs" = "yes" ]
+then
+ if [ "$which_vcs" = "git" ]
+ then
+ git init $dst
+ if [ "$commit_init" = "yes" ]
+ then
+ cd $dst
+ git add css js img build *.html *.xml *.txt *.png *.ico .htaccess
+ git commit -am 'initial commit'
+ fi
+ elif [ "$which_vcs" = "hg" ]
+ then
+ hg init $dst
+ if [ "$commit_init" = "yes" ]
+ then
+ cd $dst
+ hg add css js img build *.html *.xml *.txt *.png *.ico .htaccess
+ hg commit -m 'initial commit' css js img build *.html *.xml *.txt *.png *.ico .htaccess
+ fi
+ fi
fi
+#success message
+echo "Created Project: $dst"
+

0 comments on commit 5034e2f

Please sign in to comment.
Something went wrong with that request. Please try again.