# Build/install the CRF-T VS Code extension as a .vsix, without vsce or npm.
#
# A .vsix is just a ZIP in Open Packaging Conventions layout: the extension
# payload under extension/, plus extension.vsixmanifest and [Content_Types].xml
# at the archive root.  We assemble that with node (to derive the manifest from
# package.json) and zip.
#
#   make vsix       build crft-<version>.vsix
#   make install    build and install it into VS Code (code --install-extension)
#   make clean      remove build artefacts

NAME    := $(shell node -p "require('./package.json').name")
VERSION := $(shell node -p "require('./package.json').version")
VSIX    := $(NAME)-$(VERSION).vsix

# extension payload; relative paths are preserved under extension/
PAYLOAD := package.json language-configuration.json README.md \
           syntaxes/crft.tmLanguage.json sample.crft

.PHONY: vsix install clean

vsix: $(VSIX)

$(VSIX): $(PAYLOAD) vsix/gen.js
	rm -rf build
	mkdir -p build/extension
	cp --parents $(PAYLOAD) build/extension/
	node vsix/gen.js package.json build
	cd build && zip -q -r -X ../$(VSIX) '[Content_Types].xml' extension.vsixmanifest extension
	@echo "built $(VSIX)"

install: vsix
	code --install-extension $(VSIX) --force

clean:
	rm -rf build $(NAME)-*.vsix
