|
| 1 | +# kagent.dev — combined build (Next.js marketing worker + Hugo docs) |
| 2 | +# |
| 3 | +# Architecture: the marketing site (home, blog, agents, tools, community, |
| 4 | +# enterprise) is a Next.js app deployed as an opennextjs Cloudflare Worker. The |
| 5 | +# documentation is a Hugo site in docs-site/, served entirely under the /docs |
| 6 | +# subpath (its baseURL carries the /docs prefix). `make build` builds the Hugo |
| 7 | +# docs, injects the static output into public/docs/ so the Worker serves it as |
| 8 | +# static assets, then builds the Worker. One build, one deploy, one origin. |
| 9 | +# |
| 10 | +# Hugo binary: defaults to the version-pinned `hugo160` used across the Solo docs |
| 11 | +# repos. CI can override with `make ... HUGO=hugo` if a bare hugo is on PATH. |
| 12 | + |
| 13 | +HUGO ?= hugo160 |
| 14 | +DOCS_DIR := docs-site |
| 15 | +DOCS_OUT := $(DOCS_DIR)/public |
| 16 | +# Where the docs static assets are injected in the Next app. Served at /docs. |
| 17 | +WEB_DOCS := public/docs |
| 18 | +# Optional Hugo baseURL override. Empty = use hugo.yaml's prod baseURL |
| 19 | +# (https://kagent.dev/docs/). `make preview` sets this to the local wrangler host |
| 20 | +# so internal absolute links (section cards, assets) stay on localhost instead of |
| 21 | +# jumping to production. The port matches `dev:worker` (wrangler --port 3000). |
| 22 | +DOCS_BASEURL ?= |
| 23 | + |
| 24 | +.DEFAULT_GOAL := help |
| 25 | + |
| 26 | +.PHONY: help |
| 27 | +help: ## List available targets |
| 28 | + @grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ |
| 29 | + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}' |
| 30 | + |
| 31 | +# ── Setup ────────────────────────────────────────────────────────────────── |
| 32 | +.PHONY: install |
| 33 | +install: ## Install web + docs dependencies (npm) and Hugo modules |
| 34 | + npm install |
| 35 | + cd $(DOCS_DIR) && npm install |
| 36 | + cd $(DOCS_DIR) && $(HUGO) mod get ./... |
| 37 | + |
| 38 | +# ── Docs (Hugo) ──────────────────────────────────────────────────────────── |
| 39 | +.PHONY: gen-docs |
| 40 | +gen-docs: ## Regenerate Hugo docs content from src/app/docs (the MDX source) |
| 41 | + node scripts/mdx-to-hugo.mjs --out $(DOCS_DIR)/content |
| 42 | + |
| 43 | +.PHONY: build-docs |
| 44 | +build-docs: ## Build the Hugo docs site -> docs-site/public |
| 45 | + cd $(DOCS_DIR) && $(HUGO) --config hugo.yaml $(if $(DOCS_BASEURL),--baseURL "$(DOCS_BASEURL)") --gc --minify |
| 46 | + |
| 47 | +.PHONY: inject-docs |
| 48 | +inject-docs: ## Copy built docs into public/docs (preserves tracked assets, e.g. versions/) |
| 49 | + @mkdir -p $(WEB_DOCS) |
| 50 | + rsync -a --delete --filter='protect versions/**' --filter='protect versions/' \ |
| 51 | + $(DOCS_OUT)/ $(WEB_DOCS)/ |
| 52 | + |
| 53 | +.PHONY: serve-docs |
| 54 | +serve-docs: ## Preview the docs alone at http://localhost:1313/docs/ |
| 55 | + cd $(DOCS_DIR) && $(HUGO) server --config hugo.yaml -D --disableFastRender |
| 56 | + |
| 57 | +# ── Web (Next.js) ────────────────────────────────────────────────────────── |
| 58 | +.PHONY: serve-web |
| 59 | +serve-web: ## Run the Next.js marketing dev server (http://localhost:3000) |
| 60 | + npm run dev |
| 61 | + |
| 62 | +.PHONY: build-web |
| 63 | +build-web: ## Build the opennextjs Cloudflare Worker (bundles public/ as assets) |
| 64 | + npm run build:worker |
| 65 | + |
| 66 | +# ── Combined ─────────────────────────────────────────────────────────────── |
| 67 | +.PHONY: build |
| 68 | +build: build-docs inject-docs build-web ## Build docs + inject into /docs + build the Worker |
| 69 | + |
| 70 | +.PHONY: preview |
| 71 | +# Target-specific var (inherited by the `build` prerequisite -> build-docs) so the |
| 72 | +# docs are built with the local host; keeps card/asset links on localhost. |
| 73 | +preview: DOCS_BASEURL := http://localhost:3000/docs/ |
| 74 | +preview: build ## Build everything and serve the combined site via wrangler dev |
| 75 | + npm run dev:worker |
| 76 | + |
| 77 | +.PHONY: deploy |
| 78 | +deploy: build ## Build everything and deploy the Worker to Cloudflare |
| 79 | + npx wrangler deploy --minify |
| 80 | + |
| 81 | +# ── Housekeeping ─────────────────────────────────────────────────────────── |
| 82 | +.PHONY: clean |
| 83 | +clean: ## Remove build artifacts (keeps tracked assets under public/docs) |
| 84 | + rm -rf $(DOCS_OUT) $(DOCS_DIR)/resources $(DOCS_DIR)/hugo_stats.json |
| 85 | + rm -rf .open-next .wrangler |
| 86 | + @# Drop injected docs but keep tracked files (versions/ etc.) |
| 87 | + find $(WEB_DOCS) -mindepth 1 -maxdepth 1 ! -name versions -exec rm -rf {} + 2>/dev/null || true |
0 commit comments