This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
/
createproject.sh
executable file
·167 lines (147 loc) · 4 KB
/
createproject.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
#Generate a new project from your HTML5 Boilerplate repo clone
#by: Rick Waldron & Michael Cetrulo
##first run
# $ cd html5-boilerplate/build
# $ chmod +x createproject.sh && ./createproject.sh [new_project]
##usage
# $ cd html5-boilerplate/build
# $ ./createproject.sh [new_project]
#
# If [new_project] is not specified the user we will prompted to enter it.
#
# The format of [new_project] should ideally be lowercase letters with no
# spaces as it represents the directory name that your new project will live
# in.
#
# If the new project is specified as just a name ( "foo" ) then the path
# will be a sibling to html5-boilerplate's directory.
#
# If the new project is specified with an absolute path ( "/home/user/foo" )
# that path will be used.
#
# find project root (also ensure script is ran from within repo)
version="1.0"
print_version() {
echo "$0 (c) 2011 by Rick Waldron & Michael Cetrulo version $version"
}
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 ""
}
# 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
while test "$1" != ""
do
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 [ ! -d "$src" ]; then
src=$(git rev-parse --show-toplevel) || {
echo "fatal: could not determine html5-boilerplate's root directory." >&2
exit 1
}
fi
dst="$dst/$project_name/"
if [ -d $dst ]
then
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"
cp -vr -- $src/css $src/js $src/img $src/build $src/*.html $src/*.xml $src/*.txt $src/*.png $src/*.ico $src/.htaccess "$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"