diff --git a/.gitignore b/.gitignore index 6263750..fe5361d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode *.out -cover.txt +cover-test cover.html +cover.txt diff --git a/Makefile b/Makefile index 2e93f2f..7c376d2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,28 @@ +LOCAL_COVER_DIR := cover-test + .PHONY: release release: git tag -d v1 git tag v1 HEAD git push -f origin v1 + +$(LOCAL_COVER_DIR)/revisions: + @mkdir -p "$(LOCAL_COVER_DIR)/revisions" + +$(LOCAL_COVER_DIR)/revisions/local.html: $(LOCAL_COVER_DIR)/revisions + @cd go-test-app-01; make test + @cd go-test-app-01; go tool cover -html=cover.out -o "../$(LOCAL_COVER_DIR)/revisions/local.html" + @cp $(LOCAL_COVER_DIR)/revisions/local.html $(LOCAL_COVER_DIR)/revisions/local-inc.html + @for file in assets/*; do ln -s "$$PWD/$$file" "$(LOCAL_COVER_DIR)/$(shell basename "$$file")"; done + @cd $(LOCAL_COVER_DIR); REVISION=local ../scripts/beautify-html.sh "$$html_file" + +preview: clean $(LOCAL_COVER_DIR)/revisions/local.html + @echo "" + @echo preview live at: http://localhost:8000?hash=local + @echo " ctrl+c to stop" + @echo "" + @cd $(LOCAL_COVER_DIR); python3 -m http.server 8000 > /dev/null + +clean: + @rm -rf "$(LOCAL_COVER_DIR)" + @cd go-test-app-01; make clean diff --git a/assets/index.js b/assets/index.js index 2850de3..51b7270 100644 --- a/assets/index.js +++ b/assets/index.js @@ -34,7 +34,7 @@ function main() { configureCodeBlocks() configureSyntaxHighlight('pre .code .editor') - addCoverageSpans('pre .coverage span') + addCoverageSpans('pre .coverage .editor') addLineNumbers() // setup complete, restore the page visibility @@ -42,7 +42,7 @@ function main() { } function addCoverageSpans(cssSelector) { - let spans = Array.from(document.querySelectorAll(cssSelector)) + let spans = Array.from(document.querySelectorAll(`${cssSelector} span`)) spans.forEach((span) => { let html = span.innerHTML diff --git a/scripts/beautify-html.sh b/scripts/beautify-html.sh new file mode 100755 index 0000000..79e72cf --- /dev/null +++ b/scripts/beautify-html.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ "${REVISION}" = "local" ]; then + set -eo pipefail +else + set -xeo pipefail +fi + +if [ -z "${REVISION}" ]; then + echo "REVISION is not set" + exit 1 +fi + +# this is useful for browser caching +hash=$(cat index.css index.js | md5sum | awk '{print $1}') + +for file in "revisions/${REVISION}.html" "revisions/${REVISION}-inc.html"; do + ex -sc '%s/\n\t\t