set dotenv-load := true

tangle-directions := "open elisp.org in emacs and run C-c C-v to generate elisp snippets!"


# attempt to generate elisp.
elisp:
  if command -v org-tangle &> /dev/null; then org-tangle ./elisp.org || echo "warning, org-tangle failed - {{ tangle-directions }}"; else echo "warning, org-tangle not found - {{ tangle-directions }}"; fi

# generate README.md from README.org
readme:
  pandoc -f org -t markdown README.org -o README.md

# generate elisp and README
generate: elisp readme

# build with cargo
build *ARGS: generate
  cargo build {{ARGS}}

# run tests
test: generate
  cargo test

# run type checks
check: generate
  cargo check

# run the app
run *ARGS: generate
  cargo run -- {{ ARGS }}

# do final generation before publishing
prepublish:
  if [ -n "$(git status --porcelain | awk '/ *[a-zA-Z\?]+ * mph\// { print $0 }')" ]; then echo "Refusing to move forward with a dirty tree!"; exit 1; fi
  @just generate
  if [ -n "$(git status --porcelain | awk '/ *[a-zA-Z\?]+ * mph\// { print $0 }')" ]; then git add README.md elisp && git commit -m '[prerelease] Regenerated elisp(?) and README'; fi

# Tag the release with tito
tag:
  tito tag --use-version "$(yq .package.version Cargo.toml)"

_push_tag:
  git push origin --follow-tags

# Apply copr configuration
apply-copr:
  coprctl apply -f ./package.yml

# Kick off the COPR build
build-copr:
  copr build-package jfhbrook/joshiverse --name "$(yq .package.name Cargo.toml)"

# Publish to cargo - allows a dirty tree outside the project
publish:
  if [ -n "$(git status --porcelain | awk '/ *[a-zA-Z\?]+ * mph\// { print $0 }')" ]; then echo "Refusing to move forward with a dirty tree!"; exit 1; fi
  cargo publish --allow-dirty

# Do a release
release: prepublish publish tag _push_tag apply-copr build-copr
