Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
39 changes: 36 additions & 3 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.:
Expand All @@ -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
Expand Down