quite a lot of things
This commit is contained in:
122
Makefile
122
Makefile
@@ -1,78 +1,66 @@
|
||||
# Simple Makefile for a Go project
|
||||
# ============================================
|
||||
# BILLIT - Makefile
|
||||
# ============================================
|
||||
|
||||
.PHONY: all build run dev clean scss scss-watch test docker-build docker-run
|
||||
|
||||
# Variables
|
||||
APP_NAME := billit
|
||||
MAIN_PATH := ./cmd/api
|
||||
SCSS_DIR := internal/web/assets/scss
|
||||
CSS_DIR := internal/web/assets/css
|
||||
|
||||
# Default target
|
||||
all: scss build
|
||||
|
||||
# Build the application
|
||||
all: build test
|
||||
templ-install:
|
||||
@if ! command -v templ > /dev/null; then \
|
||||
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
|
||||
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
|
||||
go install github.com/a-h/templ/cmd/templ@latest; \
|
||||
if [ ! -x "$$(command -v templ)" ]; then \
|
||||
echo "templ installation failed. Exiting..."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
else \
|
||||
echo "You chose not to install templ. Exiting..."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi
|
||||
tailwind-install:
|
||||
|
||||
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-x64 -o tailwindcss; fi
|
||||
@chmod +x tailwindcss
|
||||
|
||||
build: tailwind-install templ-install
|
||||
@echo "Building..."
|
||||
@templ generate
|
||||
@./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
|
||||
@CGO_ENABLED=1 GOOS=linux go build -o main cmd/api/main.go
|
||||
build:
|
||||
@echo "Building $(APP_NAME)..."
|
||||
go build -o bin/$(APP_NAME) $(MAIN_PATH)
|
||||
|
||||
# Run the application
|
||||
run:
|
||||
@go run cmd/api/main.go
|
||||
# Create DB container
|
||||
docker-run:
|
||||
@if docker compose up --build 2>/dev/null; then \
|
||||
: ; \
|
||||
else \
|
||||
echo "Falling back to Docker Compose V1"; \
|
||||
docker-compose up --build; \
|
||||
fi
|
||||
run: scss
|
||||
@echo "Running $(APP_NAME)..."
|
||||
go run $(MAIN_PATH)
|
||||
|
||||
# Shutdown DB container
|
||||
docker-down:
|
||||
@if docker compose down 2>/dev/null; then \
|
||||
: ; \
|
||||
else \
|
||||
echo "Falling back to Docker Compose V1"; \
|
||||
docker-compose down; \
|
||||
fi
|
||||
# Development mode with hot reload
|
||||
dev:
|
||||
@echo "Starting development server..."
|
||||
air
|
||||
|
||||
# Test the application
|
||||
test:
|
||||
@echo "Testing..."
|
||||
@go test ./... -v
|
||||
# Compile SCSS to CSS
|
||||
scss:
|
||||
@echo "Compiling SCSS..."
|
||||
sass $(SCSS_DIR)/main.scss $(CSS_DIR)/output.css --style=compressed
|
||||
|
||||
# Clean the binary
|
||||
# Watch SCSS for changes
|
||||
scss-watch:
|
||||
@echo "Watching SCSS for changes..."
|
||||
sass $(SCSS_DIR)/main.scss $(CSS_DIR)/output.css --style=compressed --watch
|
||||
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
@rm -f main
|
||||
rm -rf bin/
|
||||
rm -f $(CSS_DIR)/output.css
|
||||
rm -f $(CSS_DIR)/output.css.map
|
||||
|
||||
# Live Reload
|
||||
watch:
|
||||
@if command -v air > /dev/null; then \
|
||||
air; \
|
||||
echo "Watching...";\
|
||||
else \
|
||||
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
|
||||
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
|
||||
go install github.com/air-verse/air@latest; \
|
||||
air; \
|
||||
echo "Watching...";\
|
||||
else \
|
||||
echo "You chose not to install air. Exiting..."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi
|
||||
# Run tests
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
go test ./...
|
||||
|
||||
.PHONY: all build run test clean watch tailwind-install templ-install
|
||||
# Docker build
|
||||
docker-build: scss
|
||||
@echo "Building Docker image..."
|
||||
docker compose -f compose.build.yml build
|
||||
|
||||
# Docker run
|
||||
docker-run:
|
||||
@echo "Running Docker container..."
|
||||
docker compose up
|
||||
|
||||
# Build for production
|
||||
release: scss
|
||||
@echo "Building for production..."
|
||||
CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o bin/$(APP_NAME) $(MAIN_PATH)
|
||||
|
||||
Reference in New Issue
Block a user