all: package

package: target/release/upend ui/dist/index.html
	rm -fr dist
	linuxdeploy-x86_64.AppImage --appdir dist
	cp target/release/upend dist/usr/bin/upend
	cp -r ui/dist dist/usr/bin/webui
	cp upend.png dist/usr/share/icons/upend.png
	VERSION="$$(grep '^version' Cargo.toml|grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')" \
		linuxdeploy-x86_64.AppImage --appdir dist -d upend.desktop --output appimage

backend: target/release/upend

target/release/upend:
	cargo build --release

frontend: ui/dist/index.html

ui/dist/index.html:
	cd ui && yarn install && yarn build

lint: backend_lint frontend_lint

backend_lint:
	cargo clippy

frontend_lint: ui/node_modules
	cd ui && yarn lint

backend_test:
	cargo test --workspace --verbose

ui/node_modules:
	cd ui && yarn install

clean:
	rm -r target
	rm -r ui/node_modules ui/dist

update_schema:
	rm -f upend.sqlite3
	diesel migration run --migration-dir migrations/upend/
	diesel print-schema > src/schema.rs
