Last active
November 16, 2019 23:31
-
-
Save jdolitsky/34b67113afe515e096064a4d01fd4dd6 to your computer and use it in GitHub Desktop.
Script to help with Octant plugin development. Watches .go files, rebuilds plugin, and automatically restarts Octant server. Requires fswatch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
cd "${DIR}" | |
REQUIRED_SYSTEM_COMMANDS=( | |
"go" | |
"octant" | |
"fswatch" | |
) | |
function log { | |
echo "[dev.sh] $@" | |
} | |
function build_plugin { | |
log "Building plugin..." | |
go build -o bin/octant-plugin . | |
log "Plugin built to bin/octant-plugin" | |
} | |
function start_octant { | |
local extra_args="$@" | |
log "Starting Octant..." | |
octant --plugin-path=bin/ ${extra_args} & | |
log "Octant available at http://127.0.0.1:7777/" | |
} | |
function stop_octant { | |
log "Stopping Octant..." | |
pkill -9 octant || true | |
} | |
function watch_files { | |
eval "export $(go env | grep GOPATH)" && fswatch -0 -o \ | |
$(go list ./... | awk -v gp="${GOPATH}/src/" '{print gp $1 "/*.go"}' | xargs) | |
} | |
function main { | |
for c in ${REQUIRED_SYSTEM_COMMANDS[@]}; do | |
if [[ ! -x "$(command -v ${c})" ]]; then | |
log "System command missing: $c" | |
exit 1 | |
fi | |
done | |
build_plugin | |
stop_octant | |
start_octant | |
trap "log \"Goodbye\"" EXIT | |
watch_files | while read -d "" event; do | |
log "Source change detected, rebuilding plugin..." | |
build_plugin | |
log "Plugin rebuilt, restarting octant..." | |
stop_octant | |
start_octant --disable-open-browser | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment