diff --git a/README.md b/README.md index ee340f7..b664507 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,15 @@ Install [nvm](https://github.com/nvm-sh/nvm): curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash ``` +Optionally, you may install [just](https://just.systems/man/en/), which is +essentially a modernized makefile. It is not required, but it is convenient. +This repo's `justfile` has some useful commands. that are also referenced +in this README. And after installing `just`, then you can run the command +to see all available recipes: + +![just recipes](./docs/just-recipes.png 'just recipes') +(just recipes as of 18-Sep-2023) + Follow any extra instructions from the script and restart your terminal. Then run: ```bash @@ -31,12 +40,16 @@ Install npm and then run: ```bash npm install +# OR +just init ``` To start a web server that auto-reloads on changes, run: ```bash npm start +# OR +just dev ``` ## Test Release version @@ -45,6 +58,8 @@ Run: ```bash npm run start:dist +# OR +just start-dist ``` Note that you need Python 3.8 (2019 release) or newer, @@ -59,6 +74,8 @@ To publish/deploy run: ```bash npm run deploy +# OR +just publish ``` ## Test @@ -69,6 +86,8 @@ Run all tests: ```bash npm run test:node +# OR +just test-node ``` That command is an alias for `WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --node`. @@ -76,7 +95,9 @@ That command is an alias for `WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --node Or run a specific test file: ```bash -npm run test:node -- --test tier_0 +npm run test:node -- --test tier_0 --test tier_1 +# OR +just test-node tier_0 tier_1 ``` ### Manual Way diff --git a/docs/just-recipes.png b/docs/just-recipes.png new file mode 100644 index 0000000..bf94e72 Binary files /dev/null and b/docs/just-recipes.png differ diff --git a/justfile b/justfile new file mode 100644 index 0000000..4542a91 --- /dev/null +++ b/justfile @@ -0,0 +1,89 @@ +# bash/justfile + +# https://just.systems/man/en/chapter_1.html + +[private] +@default: + echo "View file 'justfile' to see internals of any recipe." + just --list --unsorted + +# ------------------------------------------------------------------------------ +# BASICS +# ------------------------------------------------------------------------------ + +# TODO: add check for all installations (rust, npm, nvm/n, wasm-pack, etc.), +# and auto-install anything missing. +# Initialize the repo. Necessary after initial git-clone. +@init: + npm install + echo "Note that this init script does not (yet) install Rust, nvm/n, wasm-pack, etc." + echo "Please follow the guidance in the README.md file to install everything." + +# Clean up the repo by removing all generated files. +@clean: + rm -rf dist pkg + +# ------------------------------------------------------------------------------ +# LINTING +# ------------------------------------------------------------------------------ + +# Lint all code. +@lint: lint-js lint-rs + +# Only lint the JavaScript code via eslint. +@lint-js: + eslint --ext .js,.vue --ignore-path .gitignore --fix js + +# Only lint the Rust code via Clippy. +@lint-rs: + cargo clippy --all-targets --all-features -- -D warnings + +# ------------------------------------------------------------------------------ +# RUN LOCAL SERVERS +# ------------------------------------------------------------------------------ + +# Run the development server, which has hot-reloading and debug-mode. +@start-dev: clean + webpack-dev-server --open -d +alias dev := start-dev + +# Run the distribution server, which does NOT have hot-reloading or debug-mode. +@start-dist: build + python3 -m http.server 8000 --directory dist + +# ------------------------------------------------------------------------------ +# BUILD & DEPLOY +# ------------------------------------------------------------------------------ + +# Build the deployable distribution. +@build: clean + webpack + +# Manually publish the app to GitHub Pages. +@publish: build && clean + gh-pages -d dist + +# ------------------------------------------------------------------------------ +# TESTING +# ------------------------------------------------------------------------------ + +# Run all tests. +test: test-rs test-wasm test-node + +# Run Rust tests. +@test-rs: + cargo test + +# Run headless Wasm tests. Optionally give specific browsers; ex: just test-wasm chrome safari +@test-wasm *BROWSERS='node chrome firefox safari': + BROWSER_ARG=$(echo {{BROWSERS}} | sed 's/[^ ]* */--&/g') && \ + wasm-pack test --headless $BROWSER_ARG; \ + +# Run Wasm tests with Node.js. Optionally give specific tests; ex: just test-node tier_0 tier_1 +@test-node *TESTS: + if [ -z "{{TESTS}}" ]; then \ + WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --node; \ + else \ + TEST_ARG=$(echo {{TESTS}} | sed 's/[^ ]* */--test &/g') && \ + WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --node -- $TEST_ARG; \ + fi \ No newline at end of file