PLUGIN_ID := beaver
ASSETS    := manifest.json main.js styles.css versions.json

.PHONY: sync check fix test build install zip preview

sync:
	bun install

check:
	bun lint
	bun run check

fix:
	bun fix

test:
	bun run test

build:
	bun run build

install: build
	@test -n "$(VAULT)" || (echo "set VAULT=<path-to-vault>" >&2; exit 1)
	@test -d "$(VAULT)/.obsidian" || (echo "no .obsidian dir at $(VAULT)" >&2; exit 1)
	@target="$(VAULT)/.obsidian/plugins/$(PLUGIN_ID)"; \
	 mkdir -p "$$target"; \
	 cp $(ASSETS) "$$target/"; \
	 echo "installed → $$target"

zip: build
	@version=$$(node -p "require('./manifest.json').version"); \
	 out="beaver-plugin-$$version.zip"; \
	 rm -f "$$out"; \
	 zip -q -j "$$out" $(ASSETS); \
	 echo "wrote $$out"

preview:
	bun run preview
