Skip to content

Commit

Permalink
Taskfile: Add task serve for viewing output. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao authored Mar 8, 2024
1 parent 34beac7 commit b7c92f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Follow the steps below to build and view the site locally.

## Requirements

* [Node.js] >= 16 to be able to [view the output](#viewing-the-output)
* python3
* python3-venv
* [Task]
Expand All @@ -30,13 +31,13 @@ Follow the steps below to build and view the site locally.

## Viewing the output

You can use [npm] with [http-server] to view the output:
Run task `serve` to install [http-server] and view the output:

```shell
npx http-server build/html -c-1
task serve
```

[docs.yscope.com]: https://docs.yscope.com
[npm]: https://nodejs.org/en/download/current
[http-server]: https://www.npmjs.com/package/http-server
[Node.js]: https://nodejs.org/en/download/current
[Task]: https://taskfile.dev/
32 changes: 31 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: "3"
vars:
# Paths
BUILD_DIR: "{{.TASKFILE_DIR}}/build"
DOCS_OUTPUT_DIR: "{{.BUILD_DIR}}/html"
NODE_DEPS_DIR: "{{.BUILD_DIR}}/node"
VENV_DIR: "{{.BUILD_DIR}}/venv"

# Other variables
Expand All @@ -25,7 +27,7 @@ tasks:
deps: ["venv"]
vars:
CHECKSUM_FILE: "{{.BUILD_DIR}}/{{.TASK}}.md5"
OUTPUT_DIR: "{{.BUILD_DIR}}/html"
OUTPUT_DIR: "{{.DOCS_OUTPUT_DIR}}"
cmds:
- |
. "{{.VENV_DIR}}/bin/activate"
Expand All @@ -44,6 +46,13 @@ tasks:
<(cd '{{.OUTPUT_DIR}}' && tar cf - {{.CHECKSUM_TAR_BASE_ARGS}} . | md5sum)
"{{.CHECKSUM_FILE}}"
serve:
deps:
- "docs"
- "http-server"
cmds:
- "npm --prefix '{{.NODE_DEPS_DIR}}' exec http-server '{{.DOCS_OUTPUT_DIR}}' -c-1"

venv:
internal: true
vars:
Expand Down Expand Up @@ -72,3 +81,24 @@ tasks:
diff
<(cd '{{.OUTPUT_DIR}}' && tar cf - {{.CHECKSUM_TAR_BASE_ARGS}} . | md5sum)
"{{.CHECKSUM_FILE}}"
http-server:
internal: true
vars:
CHECKSUM_FILE: "{{.BUILD_DIR}}/{{.TASK}}.md5"
OUTPUT_DIR: "{{.NODE_DEPS_DIR}}"
cmds:
- "rm -rf '{{.OUTPUT_DIR}}'"
- "npm --prefix '{{.OUTPUT_DIR}}' install http-server"
# Checksum the generated files (this command must be last)
- |-
cd "{{.OUTPUT_DIR}}"
tar cf - {{.CHECKSUM_TAR_BASE_ARGS}} . | md5sum > "{{.CHECKSUM_FILE}}"
sources:
- "Taskfile.yml"
status:
- "test -f '{{.CHECKSUM_FILE}}'"
- >-
diff
<(cd '{{.NODE_DEPS_DIR}}' && tar cf - {{.CHECKSUM_TAR_BASE_ARGS}} . | md5sum)
"{{.CHECKSUM_FILE}}"

0 comments on commit b7c92f0

Please sign in to comment.