This repository was archived by the owner on May 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
444 lines (379 loc) Β· 14.9 KB
/
Copy pathMakefile
File metadata and controls
444 lines (379 loc) Β· 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# xcsh CLI Makefile (TypeScript/Node.js)
#
# Usage:
# make build - Build the CLI for current platform
# make build-all - Build binaries for all platforms
# make test - Run all tests
# make lint - Run linter
# make clean - Clean build artifacts
# make docs - Generate documentation
# Include branding configuration (single source of truth)
include branding.mk
# Use branding variables
BINARY_NAME=$(CLI_NAME)
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Build output directory
DIST_DIR=binaries
# Node.js/npm settings
NODE_VERSION_MIN=18
NPM?=npm
NPX?=npx
.PHONY: all build build-all test clean lint fmt install help \
docs docs-all docs-clean docs-serve docs-build \
download-specs download-specs-force check-upstream \
generate generate-domains generate-operations generate-completions validate-generated gap-analysis \
ts ts-build ts-test ts-lint ts-check ts-install ts-generate \
ci pre-commit pre-push version
# Default target
all: build
# =============================================================================
# Build Targets
# =============================================================================
# Build the CLI for current platform
build:
@echo "Building $(BINARY_NAME) $(VERSION)..."
@$(NPM) run build
@echo "Build complete: dist/"
# Build standalone binaries for all platforms
build-all: clean-dist
@echo "Building binaries for all platforms..."
@$(NPM) run build:binaries
@echo ""
@echo "All builds complete:"
@ls -lh $(DIST_DIR)/
@echo ""
@echo "Checksums:"
@cd $(DIST_DIR) && shasum -a 256 * 2>/dev/null || sha256sum * 2>/dev/null || echo "Install shasum or sha256sum for checksums"
# =============================================================================
# Test Targets
# =============================================================================
# Run all tests
test:
@echo "Running all tests..."
@$(NPM) test -- --run
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
@$(NPM) test -- --run --coverage
@echo "Coverage report generated"
# Run tests in watch mode
test-watch:
@echo "Running tests in watch mode..."
@$(NPM) test
# =============================================================================
# Quality Targets
# =============================================================================
# Run linter
lint:
@echo "Running linter..."
@$(NPM) run lint
@$(NPM) run format:check
@echo "Lint passed"
# Run type checking
typecheck:
@echo "Running type check..."
@$(NPM) run typecheck
@echo "Type check passed"
# Format code
fmt:
@echo "Formatting code..."
@$(NPM) run format
@echo "Code formatted"
# Run all validation (typecheck + lint)
check: typecheck lint
@echo "All checks passed!"
# Python linting (requires ruff)
lint-python:
@echo "Linting Python scripts..."
@if command -v ruff > /dev/null; then \
ruff check scripts/*.py; \
else \
echo "ruff not installed. Install with: pip install ruff"; \
fi
# Format Python scripts
fmt-python:
@echo "Formatting Python scripts..."
@if command -v ruff > /dev/null; then \
ruff format scripts/*.py; \
ruff check --fix scripts/*.py; \
else \
echo "ruff not installed. Install with: pip install ruff"; \
fi
# Format shell scripts (requires shfmt)
fmt-shell:
@echo "Formatting shell scripts..."
@if command -v shfmt > /dev/null; then \
shfmt -i 2 -ci -bn -w scripts/*.sh install.sh; \
else \
echo "shfmt not installed. Install with: brew install shfmt"; \
fi
# Check shell script formatting
check-shell:
@echo "Checking shell script formatting..."
@if command -v shfmt > /dev/null; then \
shfmt -i 2 -ci -bn -d scripts/*.sh install.sh; \
else \
echo "shfmt not installed. Install with: brew install shfmt"; \
fi
# =============================================================================
# Clean Targets
# =============================================================================
# Clean build artifacts
clean: clean-dist
@echo "Cleaning..."
@rm -rf dist/
@rm -rf node_modules/.cache/
@echo "Clean complete"
clean-dist:
@rm -rf $(DIST_DIR)/
# =============================================================================
# Install Targets
# =============================================================================
# Install dependencies
install:
@echo "Installing dependencies..."
@$(NPM) ci
@echo "Dependencies installed"
# Run local dev build (recommended - doesn't pollute global npm)
dev-run:
@echo "Running local development build..."
@$(NPM) run build
@node dist/index.js $(ARGS)
# DANGEROUS: Link for local development (installs to global npm)
# This creates a global symlink that may conflict with released versions!
# Use 'make dev-run ARGS="<args>"' instead for safe local testing.
# To unlink: npm unlink -g $(BINARY_NAME)
link:
@echo ""
@echo "β οΈ WARNING: This installs a DEV build to your global npm!"
@echo " This may conflict with official releases installed via Homebrew."
@echo ""
@echo " Safer alternatives:"
@echo " make dev-run ARGS=\"version\" # Run without global install"
@echo " node dist/index.js <command> # Direct execution"
@echo ""
@echo " To unlink later: npm unlink -g $(BINARY_NAME)"
@echo ""
@read -p "Continue with global link? [y/N] " confirm && [ "$$confirm" = "y" ] || exit 1
@$(NPM) link
@echo "Linked: $(BINARY_NAME) (to unlink: npm unlink -g $(BINARY_NAME))"
# =============================================================================
# API Specifications
# =============================================================================
# Download enriched API specifications from GitHub releases
download-specs:
@echo "Downloading enriched API specifications..."
@./scripts/download-specs.sh
# Force re-download enriched API specifications (bypasses cache)
download-specs-force:
@echo "Force downloading enriched API specifications..."
@rm -rf .specs
@./scripts/download-specs.sh
# Check for upstream API specification updates
check-upstream:
@./scripts/check-upstream.sh
# Check for upstream updates (JSON output for scripting)
check-upstream-json:
@./scripts/check-upstream.sh --json
# =============================================================================
# Code Generation
# =============================================================================
# Generate all code (domains + operations + completions) from upstream specs
generate: download-specs generate-domains generate-operations generate-completions validate-generated
@echo ""
@echo "β
Code generation complete!"
@echo " Domains: src/types/domains_generated.ts"
@echo " Operations: src/types/operations_generated.ts"
@echo " Completions: completions/"
# Generate TypeScript domain registry from specs
generate-domains: download-specs
@echo "ποΈ Generating domains from upstream specs..."
@$(NPX) tsx scripts/generate-domains.ts
@echo "β Generated: src/types/domains_generated.ts"
# Generate TypeScript operations registry from OpenAPI specs
generate-operations: download-specs
@echo "ποΈ Generating operations from OpenAPI specs..."
@$(NPX) tsx scripts/generate-operations.ts
@echo "β Generated: src/types/operations_generated.ts"
# Generate shell completion scripts
generate-completions: generate-domains
@echo "π§ Generating shell completions..."
@$(NPX) tsx scripts/generate-completions.ts
@echo "β Generated: completions/"
# Analyze description gaps for upstream issues
gap-analysis: download-specs
@echo "π Analyzing description gaps..."
@$(NPX) tsx scripts/analyze-description-gaps.ts
@echo "β Report: docs/description-gaps.md"
# Validate generated files are present
validate-generated:
@echo "π Validating generated code..."
@test -f src/types/domains_generated.ts || (echo "β domains_generated.ts missing" && exit 1)
@test -f src/types/operations_generated.ts || (echo "β operations_generated.ts missing" && exit 1)
@test -d completions || (echo "β completions/ directory missing" && exit 1)
@test -f completions/xcsh.bash || (echo "β xcsh.bash completion missing" && exit 1)
@test -f completions/_xcsh || (echo "β _xcsh zsh completion missing" && exit 1)
@test -f completions/xcsh.fish || (echo "β xcsh.fish completion missing" && exit 1)
@echo "β All generated files present"
# =============================================================================
# Documentation Generation
# =============================================================================
PYTHON ?= python3
DOCS_OUTPUT = docs/commands
DOCS_TEMPLATES = scripts/templates
# Generate documentation from CLI
docs: build
@echo "Generating documentation..."
@VERSION=$$(node -p "require('./package.json').version"); \
NODE_VER=$$(node --version); \
$(PYTHON) scripts/generate-homebrew-docs.py \
--version "$$VERSION" \
--node-version "$$NODE_VER" \
--output docs/install/homebrew.md; \
$(PYTHON) scripts/generate-source-docs.py \
--node-version "$$NODE_VER" \
--output docs/install/source.md
@echo "Documentation generated!"
# Clean generated documentation
docs-clean:
@echo "Cleaning generated documentation..."
@rm -rf $(DOCS_OUTPUT)/*
@echo "Generated docs cleaned"
# Serve documentation locally with hot-reload
docs-serve: docs
@echo "Starting documentation server..."
@if command -v mkdocs > /dev/null; then \
mkdocs serve; \
else \
echo "mkdocs not installed. Install with: pip install mkdocs mkdocs-material"; \
fi
# Generate ALL documentation
docs-all: build
@echo "Generating all documentation..."
@VERSION=$$(node -p "require('./package.json').version"); \
NODE_VER=$$(node --version); \
echo ""; \
echo "Step 1/2: Homebrew documentation..."; \
$(PYTHON) scripts/generate-homebrew-docs.py \
--version "$$VERSION" \
--node-version "$$NODE_VER" \
--output docs/install/homebrew.md; \
echo ""; \
echo "Step 2/2: Source build documentation..."; \
$(PYTHON) scripts/generate-source-docs.py \
--node-version "$$NODE_VER" \
--output docs/install/source.md
@echo ""
@echo "β
All documentation generated!"
# Build the MkDocs documentation site
docs-build: docs-all
@echo "Building MkDocs site..."
@if command -v mkdocs > /dev/null; then \
mkdocs build --strict; \
echo "β
Site built successfully in site/"; \
else \
echo "mkdocs not installed. Install with: pip install -r requirements-docs.txt"; \
exit 1; \
fi
# =============================================================================
# CI/CD Consistency Targets
# =============================================================================
# Run the full CI pipeline locally
ci: lint typecheck test build
@echo ""
@echo "β
CI pipeline completed successfully!"
# Pre-commit hook: fast checks before committing
pre-commit: fmt lint typecheck
@echo ""
@echo "β
Pre-commit checks passed!"
# Pre-push hook: comprehensive checks before pushing
pre-push: ci docs-all
@echo ""
@echo "β
Pre-push checks passed!"
@echo " Your changes are ready to push."
# =============================================================================
# TypeScript CLI Aliases (for compatibility)
# =============================================================================
ts: check test build
@echo "β
TypeScript CLI all checks passed"
ts-build: build
ts-test: test
ts-lint: lint
ts-check: check
ts-install: install
ts-generate: generate-domains
ts-check-upstream: check-upstream
# =============================================================================
# Version Info
# =============================================================================
version:
@echo "Version: $(VERSION)"
@node -p "require('./package.json').version" 2>/dev/null || echo "Package version: unknown"
@node --version 2>/dev/null || echo "Node.js: not installed"
@$(NPM) --version 2>/dev/null | xargs -I{} echo "npm: {}" || echo "npm: not installed"
# =============================================================================
# Help
# =============================================================================
help:
@echo "$(CLI_NAME) CLI Makefile"
@echo ""
@echo "=== CI/CD Consistency Targets (RECOMMENDED) ==="
@echo " make ci - Run full CI pipeline locally"
@echo " make pre-commit - Fast checks before committing (fmt, lint, typecheck)"
@echo " make pre-push - Comprehensive checks before pushing (ci + docs)"
@echo ""
@echo "=== Build Commands ==="
@echo " make build - Build for current platform"
@echo " make build-all - Build binaries for all platforms"
@echo " make install - Install npm dependencies"
@echo " make dev-run ARGS= - Run local build safely (recommended)"
@echo " make link - β οΈ Global npm link (NOT recommended)"
@echo " make clean - Clean build artifacts"
@echo ""
@echo "=== Test Commands ==="
@echo " make test - Run all tests"
@echo " make test-coverage - Run tests with coverage report"
@echo " make test-watch - Run tests in watch mode"
@echo ""
@echo "=== Quality Commands ==="
@echo " make fmt - Format code"
@echo " make lint - Run linter"
@echo " make typecheck - Run TypeScript type checking"
@echo " make check - Run all checks (typecheck + lint)"
@echo ""
@echo "=== Documentation Commands ==="
@echo " make docs - Generate documentation"
@echo " make docs-all - Generate ALL documentation"
@echo " make docs-build - Generate docs and build MkDocs site"
@echo " make docs-clean - Clean generated documentation"
@echo " make docs-serve - Generate docs and serve locally"
@echo ""
@echo "=== API Specifications ==="
@echo " make download-specs - Download latest enriched API specs"
@echo " make download-specs-force - Force re-download specs"
@echo " make check-upstream - Check if upstream specs have updates"
@echo ""
@echo "=== Code Generation ==="
@echo " make generate - Run full generation pipeline (domains + operations + completions)"
@echo " make generate-domains - Generate domain registry from specs"
@echo " make generate-operations - Generate operations registry from OpenAPI specs"
@echo " make generate-completions - Generate shell completion scripts"
@echo " make validate-generated - Validate generated files are present"
@echo " make gap-analysis - Analyze description gaps for upstream issues"
@echo ""
@echo "=== Compatibility Aliases ==="
@echo " make ts - Run all checks (alias for check + test + build)"
@echo " make ts-build - Build (alias)"
@echo " make ts-test - Test (alias)"
@echo " make ts-lint - Lint (alias)"
@echo " make ts-check - Check (alias)"
@echo " make ts-install - Install (alias)"
@echo " make ts-generate - Generate domains (alias)"
@echo ""
@echo "=== Development Workflow ==="
@echo " Before committing: make pre-commit"
@echo " Before pushing: make pre-push"
@echo " Full CI locally: make ci"
@echo ""
@echo "=== Version Info ==="
@echo " make version - Show version information"