define delete-files
	python3 -c "import shutil;shutil.rmtree('$(1)', ignore_errors=True)"
endef

codestyle: deps
	npm run lint

codestyle-fix: deps
	npm run lint:fix

unittests: deps
	npm test

clean:
	$(call delete-files,dist)

# Only run npm ci again when package.json or the lockfile is newer than the
# last clean install, or when npm has changed node_modules since (for example
# npm install), which rewrites node_modules/.package-lock.json.
deps: node_modules/.npm-ci-stamp

node_modules/.npm-ci-stamp: package.json package-lock.json $(wildcard node_modules/.package-lock.json)
	npm ci
	touch $@

build:
	npm run build

dist: deps clean build

.PHONY: codestyle codestyle-fix unittests deps build dist clean
