|
| 1 | +# Build System |
| 2 | +# ============ |
| 3 | +# This Makefile orchestrates the cmux build process. |
| 4 | +# |
| 5 | +# Quick Start: |
| 6 | +# make help - Show all available targets |
| 7 | +# make dev - Start development server with hot reload |
| 8 | +# make build - Build all targets (parallel when possible) |
| 9 | +# make static-check - Run all static checks (lint + typecheck + fmt-check) |
| 10 | +# make test - Run tests |
| 11 | +# |
| 12 | +# Parallelism: |
| 13 | +# Use make -jN to run independent tasks concurrently (e.g., make -j4 build) |
| 14 | +# |
| 15 | +# Backwards Compatibility: |
| 16 | +# All commands also work via `bun run` (e.g., `bun run dev` calls `make dev`) |
| 17 | +# |
| 18 | +# Adding New Targets: |
| 19 | +# Add `## Description` after the target to make it appear in `make help` |
| 20 | + |
| 21 | +.PHONY: all build dev start clean help |
| 22 | +.PHONY: build-main build-preload build-renderer |
| 23 | +.PHONY: lint lint-fix fmt fmt-check fmt-shell fmt-shell-check typecheck static-check |
| 24 | +.PHONY: test test-unit test-integration test-watch test-coverage |
| 25 | +.PHONY: dist dist-mac dist-win dist-linux |
| 26 | +.PHONY: docs docs-build docs-watch |
| 27 | + |
| 28 | +# Prettier patterns for formatting |
| 29 | +PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'tests/**/*.{ts,json}' 'docs/**/*.{md,mdx}' '*.{json,md}' |
| 30 | + |
| 31 | +# Default target |
| 32 | +all: build |
| 33 | + |
| 34 | +## Help |
| 35 | +help: ## Show this help message |
| 36 | + @echo 'Usage: make [target]' |
| 37 | + @echo '' |
| 38 | + @echo 'Available targets:' |
| 39 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' |
| 40 | + |
| 41 | +## Development |
| 42 | +dev: build-main ## Start development server (Vite + TypeScript watcher) |
| 43 | + @bun x concurrently -k \ |
| 44 | + "bun x concurrently \"bun x tsc -w -p tsconfig.main.json\" \"bun x tsc-alias -w -p tsconfig.main.json\"" \ |
| 45 | + "vite" |
| 46 | + |
| 47 | +start: build-main build-preload ## Build and start Electron app |
| 48 | + @electron . |
| 49 | + |
| 50 | +## Build targets (can run in parallel) |
| 51 | +build: dist/version.txt build-renderer build-main build-preload ## Build all targets |
| 52 | + |
| 53 | +build-main: dist/version.txt ## Build main process |
| 54 | + @echo "Building main process..." |
| 55 | + @bun x tsc -p tsconfig.main.json |
| 56 | + @bun x tsc-alias -p tsconfig.main.json |
| 57 | + |
| 58 | +build-preload: ## Build preload script |
| 59 | + @echo "Building preload script..." |
| 60 | + @bun build src/preload.ts \ |
| 61 | + --format=cjs \ |
| 62 | + --target=node \ |
| 63 | + --external=electron \ |
| 64 | + --sourcemap=inline \ |
| 65 | + --outfile=dist/preload.js |
| 66 | + |
| 67 | +build-renderer: dist/version.txt ## Build renderer process |
| 68 | + @echo "Building renderer..." |
| 69 | + @bun x vite build |
| 70 | + |
| 71 | +dist/version.txt: ## Generate version file |
| 72 | + @./scripts/generate-version.sh |
| 73 | + |
| 74 | +## Quality checks (can run in parallel) |
| 75 | +static-check: lint typecheck fmt-check ## Run all static checks |
| 76 | + |
| 77 | +lint: ## Run linter and typecheck |
| 78 | + @./scripts/lint.sh |
| 79 | + |
| 80 | +lint-fix: ## Run linter with --fix |
| 81 | + @./scripts/lint.sh --fix |
| 82 | + |
| 83 | +fmt: ## Format code with Prettier |
| 84 | + @echo "Formatting TypeScript/JSON/Markdown files..." |
| 85 | + @bun x prettier --write $(PRETTIER_PATTERNS) |
| 86 | + |
| 87 | +fmt-check: ## Check code formatting |
| 88 | + @echo "Checking TypeScript/JSON/Markdown formatting..." |
| 89 | + @bun x prettier --check $(PRETTIER_PATTERNS) 2>&1 | grep -v 'No files matching' |
| 90 | + |
| 91 | +fmt-shell: ## Format shell scripts with shfmt |
| 92 | + @./scripts/fmt.sh --shell |
| 93 | + |
| 94 | +typecheck: ## Run TypeScript type checking |
| 95 | + @./scripts/typecheck.sh |
| 96 | + |
| 97 | +## Testing |
| 98 | +test-integration: ## Run all tests (unit + integration) |
| 99 | + @bun test src |
| 100 | + @TEST_INTEGRATION=1 bun x jest tests |
| 101 | + |
| 102 | +test-unit: ## Run unit tests |
| 103 | + @bun test src |
| 104 | + |
| 105 | +test: test-unit ## Alias for test-unit |
| 106 | + |
| 107 | +test-watch: ## Run tests in watch mode |
| 108 | + @./scripts/test.sh --watch |
| 109 | + |
| 110 | +test-coverage: ## Run tests with coverage |
| 111 | + @./scripts/test.sh --coverage |
| 112 | + |
| 113 | +## Distribution |
| 114 | +dist: build ## Build distributable packages |
| 115 | + @bun x electron-builder --publish never |
| 116 | + |
| 117 | +dist-mac: build ## Build macOS distributable |
| 118 | + @bun x electron-builder --mac --publish never |
| 119 | + |
| 120 | +dist-win: build ## Build Windows distributable |
| 121 | + @bun x electron-builder --win --publish never |
| 122 | + |
| 123 | +dist-linux: build ## Build Linux distributable |
| 124 | + @bun x electron-builder --linux --publish never |
| 125 | + |
| 126 | +## Documentation |
| 127 | +docs: ## Serve documentation locally |
| 128 | + @./scripts/docs.sh |
| 129 | + |
| 130 | +docs-build: ## Build documentation |
| 131 | + @./scripts/docs_build.sh |
| 132 | + |
| 133 | +docs-watch: ## Watch and rebuild documentation |
| 134 | + @cd docs && mdbook watch |
| 135 | + |
| 136 | +## Clean |
| 137 | +clean: ## Clean build artifacts |
| 138 | + @echo "Cleaning build artifacts..." |
| 139 | + @rm -rf dist release |
| 140 | + @echo "Done!" |
| 141 | + |
| 142 | +# Parallel build optimization - these can run concurrently |
| 143 | +.NOTPARALLEL: build-main # TypeScript can handle its own parallelism |
| 144 | + |
| 145 | +fmt-shell-check: ## Check shell script formatting |
| 146 | + @if ! command -v shfmt &>/dev/null; then \ |
| 147 | + echo "shfmt not found. Install with: brew install shfmt"; \ |
| 148 | + exit 1; \ |
| 149 | + fi |
| 150 | + @echo "Checking shell script formatting..." |
| 151 | + @shfmt -i 2 -ci -bn -d scripts |
0 commit comments