This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
forked from ringcentral/slate
-
Notifications
You must be signed in to change notification settings - Fork 28
/
watch_and_serve_local_dev
executable file
·79 lines (61 loc) · 1.92 KB
/
watch_and_serve_local_dev
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
#! /bin/bash -e
set -o pipefail
source ./bin/check_deps
log_file_dir=build-local_dev
mkdir -p "$log_file_dir"
log_file="$log_file_dir/log-$(date +%Y-%m-%dT%H:%M:%S%Z)"
to_make=(
source/includes/app-components-reference/_index.html.md
source/includes/api-reference/_index.html.md
)
run_middleman() {
if ! bundle exec middleman serve --watcher-force-polling; then
echo "failed to run middleman" >&2
exit 1
fi
}
acquire_lock() {
file_lock="$log_file_dir/LOCK"
if [[ -f "$file_lock" ]]; then
{
echo "This script may already be running somewhere in process $(cat "$file_lock"),"
echo "or has left behind a lockfile at $file_lock"
echo "If you're sure it's not running, you can manually remove it."
echo "Otherwise, you should kill the script that is running elsewhere like so:"
echo '`kill -- -'"$(cat "$file_lock")"'`'
} >&2
exit 1
fi
trap "rm -f '$file_lock'" EXIT
echo "$$" >"$file_lock"
}
echo "logging to $log_file"
make --jobs 8 "${to_make[@]}"
echo
echo "***"
echo
echo " Watching \$OPENAPI_DIR for changes."
echo " Editing OAS (e.g., asana_oas.yaml) will automatically regenerate the docs site."
echo " Refresh the localhost browser window to see the new changes."
echo
echo "***"
echo
parent="$$"
asdf exec bundle config set --local path 'vendor/bundle'
asdf exec bundle install
acquire_lock
# This instructs bash to honor the SIGCHLD signal. We use that below to kill the
# background watch and make job.
set -o monitor notify
./bin/watch_and_make "${to_make[@]}" &
child="$!"
trap on_child_died SIGCHLD
# This can be called for either run_middleman or watch_and_make.
on_child_died() {
echo "killing background jobs (pgid): -$child"
# The "-" prefix indicates to kill that we're killing progress groups and not
# just individual processes. This needs to be done to kill everything in the
# watch_and_make script.
kill -- "-$child" "-$parent"
}
run_middleman