This repository has been archived by the owner on Mar 19, 2023. It is now read-only.
/
hugoctl
executable file
·118 lines (97 loc) · 2.58 KB
/
hugoctl
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
#!/usr/bin/env bash
function usage() {
cat<<EOF
Usage: $0 <command>
Commands:
install Pulls project and installs dependencies
build Build into specified directory, accepts project path as arg
dev Serve project locally, accepts project path as arg
deploy Deploys project to live environment, accepts deploy path as arg
cleanup Delete all temporary files
EOF
exit 0
}
function install() {
echo "Installing hugo/iamschulz"
git pull --recurse-submodule
yarn install
yarn --cwd themes/iamschulz-hugo-theme install
}
function purgeCache() {
echo "Purging Cloudflare Cache"
urls='{"files":["'`hugo list all | egrep -o 'https?://[^ ,]+' | tr '\n' ',' | sed 's/,/","/g'`https://iamschulz.com'"]}'
curl -X POST "https://api.cloudflare.com/client/v4/zones/5c2be641b5bc5530a92693d2504d2f91/purge_cache" \
-H "Authorization: Bearer oG1sVL68INjo5muWwGkndL_7yx1J-5zU6ch1mSpH" \
-H "Content-Type: application/json" \
--data $urls
}
function build() {
local targetDir=$1
if [[ "$targetDir" == "" ]]; then
targetDir="public"
fi
yarn --cwd themes/iamschulz-hugo-theme build
hugo -d $targetDir --cacheDir $HOME/tmp
node convert-images.js dir="./$targetDir"
}
function buildClean() {
local targetDir=$1
if [[ "$targetDir" == "" ]]; then
targetDir="public"
fi
yarn --cwd themes/iamschulz-hugo-theme build
hugo -d $targetDir --cacheDir $HOME/tmp --cleanDestinationDir
node convert-images.js dir="./$targetDir"
}
function dev() {
local targetDir=$1
if [[ "$targetDir" == "" ]]; then
targetDir="public"
fi
yarn --cwd themes/iamschulz-hugo-theme watch &
node convert-images.js dir="./$targetDir"
hugo server -d $targetDir
}
function cleanup() {
rm -rf public
rm -rf resources
rm -rf node_modules
rm -rf themes/iamschulz-hugo-theme/node_modules
rm -rf $HOME/tmp/iamschulz-hugo
echo "cleanup done"
}
function deploy() {
local targetDir=$1
if [[ "$targetDir" == "" ]]; then
targetDir="../html/next/"
fi
install
build public
echo "Syncing files to prod directory"
rsync -rc public/ $targetDir
echo "Syncing done"
purgeCache
echo "Finished deployment"
}
### Commands ###
subcommand=$1;
if [ -z "$subcommand" ]; then
usage
fi
shift
case "$subcommand" in
install)
install;;
build)
build $@;;
dev)
dev $@;;
cleanup)
cleanup;;
deploy)
deploy $@;;
purge)
purgeCache;;
*)
usage;;
esac