This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
go
executable file
·101 lines (79 loc) · 2.7 KB
/
go
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
#! /bin/bash
command_exists () {
type "$1" &> /dev/null ;
}
bold_text() {
echo -e "\033[1m$1\033[0m"
}
green_tick() {
echo -e "\033[1;92m✓\033[0m $1"
}
show_instructions () {
echo "$(bold_text Usage): ./go <command>"
echo ""
echo "where <command> is one of:"
echo " $(bold_text "setup ") setups your development machine"
echo " $(bold_text "install | i " ) installs any required dependencies"
echo " $(bold_text "test | t " ) runs all your unit tests"
echo " $(bold_text "test:dev | td") runs all your unit tests and watch any changes (dev mode)"
echo " $(bold_text "precommit | p " ) prepares your changes to be committed"
echo " $(bold_text "start | s " ) runs your local development server at http://localhost:8000"
}
set_nvm_env() {
# copied from NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
}
setup_nvm () {
echo "Installing Node Version Manager (https://github.com/creationix/nvm)"
curl --progress-bar -o- "https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh" | bash &> /dev/null
}
echo " _ ________ ________ _ _ _ _____ ____ _ _ _____ _ _____ "
echo " | | | ____\ \ / / ____| | | | | | __ \ | _ \| | | |_ _| | | __ \ "
echo " | | | |__ \ \ / /| |__ | | | | | | |__) | | |_) | | | | | | | | | | | |"
echo " | | | __| \ \/ / | __| | | | | | | ___/ | _ <| | | | | | | | | | | |"
echo " | |____| |____ \ / | |____| |___| |__| | | | |_) | |__| |_| |_| |____| |__| |"
echo " |______|______| \/ |______|______\____/|_| |____/ \____/|_____|______|_____/ "
echo ""
echo ""
intro_message() {
echo "It looks like this is your first time trying to run the app."
echo "Before you start, I need to set a few things up for you."
}
case "$1" in
"setup")
node_version=$(cat .nvmrc)
[[ -d node_modules ]] || intro_message
[[ -s $NVM_DIR/nvm.sh ]] || setup_nvm
echo $(green_tick "Installed nvm")
set_nvm_env
[[ "$(node -v)" = "v$node_version" ]] || nvm install &> /dev/null
echo $(green_tick "Installed node v$node_version")
[[ -d node_modules ]] || npm -s install &> /dev/null
echo $(green_tick "Installed npm packages")
echo ""
echo "All done! You can now start using the app!"
;;
"install" | "i")
npm -s install
;;
"test" | "t" )
npm -s test
exit $?
;;
"test:dev" | "td")
npm -s run test:dev
exit $?
;;
"precommit" | "p")
npm -s run precommit
exit $?
;;
"start" | "s")
npm run start
;;
*)
show_instructions
;;
esac