# pastel-dream — build & publish helpers (CODELESS .bnp workflow, WO-WZ-021)
#
# This theme is a CODELESS .bnp: pure declaration the host runs — blocks
# (blocks/blocks.yaml + .ninjatpl), page/system templates, template overrides,
# an email wrapper, master pages, presets, fonts and CSS in manifest.yaml. No
# Go, no templ, no plugin.wasm, no block/core dependency. `ninja plugin build`
# classifies the repo as codeless (no Go at the root) and packs the artifact
# with manifest.pb (codeless: true) and NO plugin.wasm.
#
# Usage:
#   make build          # pack pastel-dream-<version>.bnp (codeless — no wasm)
#   make verify         # validate the built .bnp (loader-identical checks)
#   make archive-check  # prove a clean `git archive HEAD` still builds codeless
#   make publish        # ninja plugin publish --bnp (to the active registry)
#   make clean          # remove build artefacts

.PHONY: build verify archive-check publish clean help

PLUGIN_NAME := pastel-dream
NINJA       := ninja
BNP         := $(PLUGIN_NAME)-$(shell grep '^version' plugin.mod | sed 's/.*"\(.*\)"/\1/').bnp

# Pack the codeless .bnp (manifest.pb synthesized from plugin.mod + manifest.yaml
# + blocks/ + templates/; no wasm compile, no DESCRIBE probe).
build:
	$(NINJA) plugin build --dir .

# Validate the built .bnp exactly as the registry/loader will.
verify:
	$(NINJA) plugin verify $(BNP)

# Prove a clean `git archive HEAD` (what publish ships) still packs codeless.
archive-check:
	@T=$$(mktemp -d /tmp/archive-check-$(PLUGIN_NAME).XXXXXX) && \
	trap 'rm -rf "$$T"' EXIT && \
	git archive HEAD | tar -x -C "$$T" && \
	cd "$$T" && $(NINJA) plugin build --dir . && \
	echo "archive-check OK"

# Publish the prebuilt .bnp to the active registry.
# Pass --host https://my.blockninja.dev for the dev orchestrator.
publish: build
	$(NINJA) plugin publish --bnp $(BNP)

# Remove build artefacts.
clean:
	rm -f $(PLUGIN_NAME)-*.bnp plugin.wasm

help:
	@echo "Targets:"
	@echo "  build          Pack the codeless .bnp (no wasm)"
	@echo "  verify         Validate the built .bnp (loader-identical checks)"
	@echo "  archive-check  Prove a clean git archive HEAD packs codeless"
	@echo "  publish        Publish the .bnp to the active registry"
	@echo "  clean          Remove build artefacts"
