-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtask
More file actions
executable file
·123 lines (110 loc) · 3.35 KB
/
Copy pathtask
File metadata and controls
executable file
·123 lines (110 loc) · 3.35 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
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
#!/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)"
}
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
}
start() {
export ENVIRONMENT=development
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} & server_pid=$!;;
"python") python tools/server.py ${arguments} & server_pid=$!;;
"node") node tools/server.js ${arguments} & server_pid=$!;;
esac
}
deploy() {
export ENVIRONMENT=production
bold "build"
build
if [ ! -z "${target}" ]; then
bold "deploy"
deploy/${target} deploy $@
fi
}
log() {
if [ ! -z "${target}" ]; then
deploy/${target} log
fi
}
console() {
if [ ! -z "${target}" ]; then
deploy/${target} console
fi
}
watch() {
export ENVIRONMENT=development
checksum=""
while true; do
if stat --version >/dev/null 2>&1; then
new_checksum=$(find *.* task content deploy themes tools -type f -exec stat --format='%Y.%N %n' {} + | sort -nr | sha1sum)
else
new_checksum=$(find *.* task content deploy themes tools -type f -exec stat -f '%m %N' {} + | sort -nr | sha1sum)
fi
if [[ "$new_checksum" != "$checksum" ]]; then
if [[ "$checksum" == "" ]]; then
start
trap "echo Stopping server...; kill $server_pid; exit" INT TERM
else
build
fi
checksum="${new_checksum}"
fi
sleep 1
done
}
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") build $@;;
"start") start $@;;
"deploy") deploy $@;;
"log") log $@;;
"console") console $@;;
"watch") watch $@;;
"test") 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