-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (61 loc) · 2.8 KB
/
Makefile
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
# Makefile for getabc.sh Next.js Project
.DEFAULT_GOAL := help
# Colors for help message
BLUE = \033[34m
CYAN = \033[36m
GREEN = \033[32m
YELLOW = \033[33m
RESET = \033[0m
# Check for required commands
REQUIRED_BINS := npm node
$(foreach bin,$(REQUIRED_BINS),\
$(if $(shell command -v $(bin) 2> /dev/null),,$(error Please install `$(bin)`)))
# Help
.PHONY: help
help: ## Display this help message
@echo "$(CYAN)getabc.sh$(RESET) development commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(BLUE)make %-20s$(RESET) %s\n", $$1, $$2}'
.PHONY: clean
clean: ## Clean all artifacts and dependencies
@echo "$(GREEN)Cleaning project...$(RESET)"
@rm -rf .next out node_modules package-lock.json tsconfig.tsbuildinfo
# Setup and Environment
node_modules: package.json ## Install dependencies
@echo "$(GREEN)Installing dependencies...$(RESET)"
@npm install
@touch node_modules
.PHONY: setup
setup: clean node_modules ## Setup/reset development environment
@echo "$(GREEN)Ready for development. Run 'make serve-dev' to start the development server.$(RESET)"
# Development
.PHONY: serve-dev
serve-dev: node_modules ## Start development server with hot-reload
@echo "$(GREEN)Starting development server with hot-reload on port 3000...$(RESET)"
@npm run dev
.PHONY: checks
checks: node_modules ## Run all checks (lint and type-check)
@echo "$(GREEN)Running linter...$(RESET)"
@npm run lint || (echo "$(YELLOW)Linting failed. Please fix the issues above.$(RESET)" && exit 1)
@echo "$(GREEN)Checking types...$(RESET)"
@npx tsc --noEmit
# Static website build (mimics production)
out: node_modules $(shell find app -type f) next.config.js package.json tsconfig.json install-script-header.txt
@echo "$(GREEN)Building static website...$(RESET)"
@rm -rf out
@NODE_ENV=production npm run build
@touch out/.nojekyll
@echo "$(GREEN)Adding installation script to index.html...$(RESET)"
@cat install-script-header.txt out/index.html > out/getabc-index-with-install-script.html.tmp && mv out/getabc-index-with-install-script.html.tmp out/index.html
.PHONY: build-static
build-static: out ## Build static website to mimic prod
@echo "$(GREEN)Static website generated in 'out' directory$(RESET)"
.PHONY: serve-static
serve-static: build-static ## Serve static website build locally
@echo "$(GREEN)Starting static website server on port 3001...$(RESET)"
@NODE_ENV=production npx serve@latest out -l 3001
.PHONY: tree
tree: ## Generate project tree structure in doc/tree.txt
@echo "$(GREEN)Generating project tree structure...$(RESET)"
@mkdir -p doc
@bash -c 'parent=$$(dirname $$(git rev-parse --show-toplevel)) && dir=$$(pwd) && echo "$${dir#$$parent/}" && git ls-files | tree --fromfile -a --filesfirst | tail +2' > doc/tree.txt
@echo "$(GREEN)Tree structure saved to doc/tree.txt$(RESET)"