Skip to content

Commit 258e37a

Browse files
committed
Add Python-based --serve option
Before the previous commit, the --docker option would automatically serve the result on https://localhost:8080, which was convenient. This adds a general option, for both Docker and non-Docker builds, to get the same behavior.
1 parent da2a27b commit 258e37a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ If you get permissions errors on Windows, you need to first [configure](https://
5252

5353
After you complete the build steps above, the build will run and generate the single-page version of the spec, the multipage version, and more. If all goes well, you should very soon have an `output/` directory containing important files like `index.html`, `multipage/`, and `dev/`.
5454

55+
You can also use the `--serve` option to `build.sh` to automatically serve the results on `https://localhost:8080/` after building (as long as you Python 3.7+ installed).
56+
5557
Now you're ready to edit the `html/source` file—and after you make your changes, you can run the `build.sh` script again to see the new output.
5658

5759
## A note on Git history

build.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ DO_UPDATE=true
1818
USE_DOCKER=false
1919
VERBOSE=false
2020
QUIET=false
21+
SERVE=false
2122
HTML_SHA=""
2223
HIGHLIGHT_SERVER_PID=""
2324

@@ -41,6 +42,8 @@ BUILD_SHA_OVERRIDE=${BUILD_SHA_OVERRIDE:-}
4142
# This needs to be coordinated with the bs-highlighter package
4243
HIGHLIGHT_SERVER_URL="http://127.0.0.1:8080"
4344

45+
SERVE_PORT=8080
46+
4447
function main {
4548
processCommandLineArgs "$@"
4649

@@ -101,6 +104,12 @@ function main {
101104

102105
$QUIET || echo
103106
$QUIET || echo "Success!"
107+
108+
if [[ $SERVE == "true" ]]; then
109+
stopHighlightServer
110+
cd "$HTML_OUTPUT"
111+
python3 -m http.server "$SERVE_PORT"
112+
fi
104113
}
105114

106115
# Processes incoming command-line arguments
@@ -124,6 +133,7 @@ function processCommandLineArgs {
124133
echo
125134
echo "Build options:"
126135
echo " -d|--docker Use Docker to build in a container."
136+
echo " -s|--serve After building, serve the results on http://localhost:$SERVE_PORT."
127137
echo " -n|--no-update Don't update before building; just build."
128138
echo " -q|--quiet Don't emit any messages except errors/warnings."
129139
echo " -v|--verbose Show verbose output from every build step."
@@ -144,6 +154,9 @@ function processCommandLineArgs {
144154
QUIET=false
145155
set -vx
146156
;;
157+
-s|--serve)
158+
SERVE=true
159+
;;
147160
*)
148161
;;
149162
esac
@@ -393,10 +406,13 @@ function doDockerBuild {
393406

394407
docker build "${DOCKER_BUILD_ARGS[@]}" .
395408

396-
DOCKER_RUN_ARGS=( whatwg-html )
409+
DOCKER_RUN_ARGS=()
410+
$SERVE && DOCKER_RUN_ARGS+=( --publish "$SERVE_PORT:$SERVE_PORT" )
411+
DOCKER_RUN_ARGS+=( whatwg-html )
397412
$QUIET && DOCKER_RUN_ARGS+=( --quiet )
398413
$VERBOSE && DOCKER_RUN_ARGS+=( --verbose )
399414
$DO_UPDATE || DOCKER_RUN_ARGS+=( --no-update )
415+
$SERVE && DOCKER_RUN_ARGS+=( --serve )
400416

401417
# Pass in the html-build SHA (since there's no .git directory inside the container)
402418
docker run --rm --interactive --tty \

0 commit comments

Comments
 (0)