all: target/release/upend webui/dist

package: all
	rm -fr dist
	linuxdeploy-x86_64.AppImage --appdir dist
	cp target/release/upend dist/usr/bin/upend
	cp -r webui/dist dist/usr/bin/webui
	cp media/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:
	cargo build --release

frontend: tools/upend_js/index.js
	cd webui && yarn add ../tools/upend_js && yarn install --immutable && yarn build

jslib:
	cd tools/upend_js && yarn install --immutable && yarn build

target/release/upend:
	make backend

webui/dist:
	make frontend

tools/upend_js/index.js:
	make jslib

lint: backend_lint frontend_lint

backend_lint:
	cargo clippy

backend_lint_no_default:
	cargo clippy --no-default-features

frontend_lint:
	cd webui && yarn add ../tools/upend_js && yarn install --immutable && yarn check && yarn lint

frontend_lib_lint:
	cd tools/upend_js && yarn install --immutable && yarn lint

backend_test:
	cargo test --workspace --verbose

backend_test_no_default:
	cargo test --no-default-features --workspace --verbose

clean: clean_tools clean_frontend clean_backend

clean_tools:
	rm -vrf tools/upend_js/*.js

clean_frontend:
	rm -vrf webui/dist webui/public/vendor

clean_backend:
	cargo clean

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