forked from lutzroeder/minimal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task
executable file
·114 lines (101 loc) · 2.99 KB
/
task
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
#!/bin/bash
if [ -f "${BASH_SOURCE[0]}.cfg" ]; then
source "${BASH_SOURCE[0]}.cfg"
fi
command="$1" && shift
while (( "$#" )); do
argument="$1" && shift
case ${argument} in
"--runtime") runtime=$1 && shift;;
"--theme") theme=$1 && shift;;
"--target") target=$1 && shift;;
"--output") output=$1 && shift;;
*) output=${argument}
esac
done
runtime=${runtime:-node}
theme=${theme:-default}
output=${output:-build}
bold() {
echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
}
client_build() {
case "${runtime}" in
"go") go run tools/generator.go ${output} --theme ${theme};;
"python") python tools/generator.py ${output} --theme ${theme};;
"node") node tools/generator.js ${output} --theme ${theme};;
esac
}
client_start() {
export ENVIRONMENT=development
client_build
arguments="${output} --port 8080 --index-page index.html --not-found-page 404.html --redirect-map redirect.map --browse"
case "${runtime}" in
"go") go run tools/server.go ${arguments};;
"python") python tools/server.py ${arguments};;
"node") node tools/server.js ${arguments};;
esac
}
client_deploy() {
export ENVIRONMENT=production
bold "build"
client_build
if [ ! -z "${target}" ]; then
bold "deploy"
deploy/${target} deploy $@
fi
}
client_log() {
if [ ! -z "${target}" ]; then
deploy/${target} log
fi
}
client_console() {
if [ ! -z "${target}" ]; then
deploy/${target} console
fi
}
client_watch() {
export ENVIRONMENT=development
client_build
case "$(uname -s)" in
Darwin*)
if [ -z "$(which fswatch)" ]; then
brew install fswatch
fi
fswatch -r -o . -e "${output}" | while read; do client_build; done
;;
esac
}
client_test() {
rm -rf ${output}/*
bold "node"
ENVIRONMENT=production node tools/generator.js ${output}/node --theme ${theme}
bold "go"
ENVIRONMENT=production go run tools/generator.go ${output}/go --theme ${theme}
bold "python"
ENVIRONMENT=production python tools/generator.py ${output}/python --theme ${theme}
bold "compare"
diff --brief -r ${output}/node/ ${output}/go/
diff --brief -r ${output}/node/ ${output}/python/
}
case "${command}" in
"build") client_build $@;;
"start") client_start $@;;
"deploy") client_deploy $@;;
"log") client_log $@;;
"console") client_console $@;;
"watch") client_watch $@;;
"test") client_test;;
*)
echo;
echo "Usage: $(tty -s && tput bold)$(basename "$0")$(tty -s && tput sgr0) <command> <options>"
echo
echo " build Build the website"
echo " start Build and launch simple local web server"
echo " deploy Build and deploy to production environment"
echo " log Show production log"
echo " console Connect to production environment via SSH"
echo;
;;
esac