feat(build.sh): Add a watch mode for automatic recompilation (#160)

This features uses and requires https://github.com/AgentCosmic/xnotify
and should work on any platform

Use it with

* Watch & compile: build.sh --watch
* Watch, compile, test: build.sh --watch --test
* Watch, compile, test & verbose output: build.sh --watch --test --verbose

(shortcuts -w && -t can be used, too)
This commit is contained in:
Roland Huß 2019-06-07 03:10:40 +02:00 committed by Knative Prow Robot
parent 01da225f85
commit 8a1adf0cb0
2 changed files with 38 additions and 3 deletions

View File

@ -75,6 +75,8 @@ You can link that script into a directory within your search `$PATH`. This allow
* `build.sh -f` - Compile only
* `build.sh -f -t` - Compile & test
* `build.sh -u` - Update dependencies before compiling
* `build.sh -w` - Enter watch mode for automatic recompilation
* `build.sh -w -t` - Enter watch mode for automatic recompilation & running tests
See `build.sh --help` for a full list of options and usage examples.

View File

@ -39,6 +39,11 @@ run() {
exit 0
fi
if $(has_flag --watch -w); then
watch
# No exit, needs to be stopped with CTRL-C anyways
fi
if $(has_flag -u --update); then
# Update dependencies
update_deps
@ -105,6 +110,31 @@ generate_docs() {
go run "./hack/generate-docs.go" "."
}
watch() {
local command="./hack/build.sh --fast"
local notify_opts="--include cmd --include pkg --batch 500"
if $(has_flag --test -t); then
command="$command --test"
fi
if $(has_flag --verbose); then
notify_opts="$notify_opts --verbose"
fi
set +e
which xnotify >/dev/null 2>&1
if [ $? -ne 0 ]; then
local green=""
local reset=""
echo "🤷 Watch: Cannot find ${green}xnotify${reset}"
echo "🌏 Please download from ${green}https://github.com/AgentCosmic/xnotify/releases${reset} and install in \$PATH"
exit 1
fi
set -e
echo "🔁 Watch"
xnotify $notify_opts -- $command
}
# Dir where this script is located
basedir() {
# Default is current directory
@ -154,10 +184,12 @@ Usage: $(basename $BASH_SOURCE) [... options ...]
with the following options:
-f --fast Only compile (without formatting, testing, doc generation)
-t --test Run tests when used with --fast
-t --test Run tests when used with --fast or --watch
-u --update Update dependencies before compiling
-w --watch Watch for source changes and recompile in fast mode
-h --help Display this help message
--verbose Verbose script output (set -x)
--verbose More output
--debug Debug information for this script (set -x)
You can add a symbolic link to this build script into your PATH so that it can be
called from everywhere. E.g.:
@ -169,10 +201,11 @@ Examples:
* Compile, format, tests, docs: build.sh
* Compile only: build.sh --fast
* Compile with tests: build.sh -f -t
* Automatice recompilation: build.sh --watch
EOT
}
if $(has_flag --verbose); then
if $(has_flag --debug); then
export PS4='+($(basename ${BASH_SOURCE[0]}):${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
fi