-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-project
More file actions
executable file
·76 lines (59 loc) · 1.52 KB
/
Copy pathstart-project
File metadata and controls
executable file
·76 lines (59 loc) · 1.52 KB
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
#!/bin/bash
set -euo pipefail
root="https://intro.gigamonkeys.com/starter-kits"
function usage {
echo "To create a new project, run this script with two arguments, the name of the project "
echo "and the name of the starter kit you want to use. For example:"
echo ""
echo " $0 my-first-web-project trivial-web"
echo ""
echo "To list the available kits:"
echo ""
echo " $0 --list"
exit 1
}
if (($# < 1)); then usage; fi
if (($# == 1)) && [ "$1" == "--list" ]; then
curl -sS "$root/kits.txt"
exit 0
fi
if (($# < 2)); then usage; fi
if (($# > 2)); then
echo "Too many arguments. Did you use a name with spaces in it?"
exit 1
fi
if [ "$(git branch --show-current)" != "main" ]; then
echo "Must start projects from main branch."
exit 1
fi
name="$1"
kit="$2"
proj="projects/$name"
if ! curl -sS "$root/kits.txt" | egrep "^$kit " > /dev/null; then
echo "$kit is not a kit."
echo ""
curl -sS "$root/kits.txt"
exit 1
fi
if [ -e "$proj" ]; then
echo "Project directory $proj already exists!"
exit 1
fi
if git show-ref --verify --quiet "refs/heads/$proj"; then
echo "Project branch $proj already exists!"
exit 1
fi
# Make the project branch
git switch -c "$proj"
# Make the project directory
mkdir -p "$proj"
# Download the starter code
cd "$proj"
tmp=$(mktemp)
curl --fail "$root/$kit.tgz" > "$tmp"
tar xzf "$tmp"
# Install the libraries
npm install
# Commit the starter code
git add .
git commit -m "Starting project $name with starter code from $kit."