default:
    @just --list
 
# build optimized wasm
build: && clean-wasm-pack
    # build with wasm-pack
    wasm-pack build --target web

# build dev wasm
dev: && clean-wasm-pack
    wasm-pack build --dev --target web 

# clean up after wasm-pack
clean-wasm-pack:
    # delete cruft from wasm-pack
    rm pkg/.gitignore pkg/package.json pkg/README.md
    rm -rf pkg/snippets
    # fix imports of rudus.js
    cp pkg/rudus.js pkg/rudus.js.backup
    echo 'import { io } from "./worker.js"' > pkg/rudus.js
    cat pkg/rudus.js.backup | tail -n+2>> pkg/rudus.js
    rm pkg/rudus.js.backup

from_branch := `git branch --show-current`
git_status := `git status -s`

# publish this branch into release
release:
    echo {{ if git_status == "" {"git status ok"} else {error("please commit changes first")} }}
    just build
    -git commit -am "release build"
    git checkout release
    git merge {{from_branch}}
    git push
    git checkout {{from_branch}}

# serve the pkg directory
serve:
    live-server pkg

