default: build

src/main.wasm:
	@cd src && \
		go mod tidy && \
		go generate && \
		go mod tidy && \
		GOOS=js GOARCH=wasm go build -o main.wasm && \
	cd -

dist/index.html: prebuild index.html
	@cp  -fv index.html ./dist

dist/wasm_exec.js: prebuild
	@cp -fv "$$(go env GOROOT)/misc/wasm/wasm_exec.js" ./dist

dist/main.wasm: prebuild src/main.wasm
	@cp -fv src/main.wasm ./dist

dist/main.css: prebuild stylesheets/index.scss
	@sass stylesheets/index.scss dist/main.css

build: dist/index.html dist/main.wasm dist/main.css dist/wasm_exec.js
	@cp -a ./dist ../dist

prebuild:
	@mkdir -p ./dist

clean:
	@rm -rf ./dist
	@rm -rf ../dist
	@rm -rf ./bin
	@rm -rf ./wailsjs
	@cd src && rm -rf bin main.wasm 0_components_vgen.go main_wasm.go components/0_components_vgen.go && cd -
	@cd src && go clean && cd -

dev: build
	@cd src && vgrun devserver.go && cd -

.PHONY: build dev prebuild clean