feat(build): add Makefile for frontend application management
This commit introduces a Makefile for the frontend application that: - Provides commands to start the app in background or foreground - Includes utilities to check status and stop the application - Reads environment variables from .env file with fallback values - Sets up logging infrastructure with timestamped log files - Includes help documentation for all available commands Signed-off-by: Shekar Siri <sshekarsiri@gmail.com>
This commit is contained in:
parent
b6cca71053
commit
f168f90f10
1 changed files with 110 additions and 0 deletions
110
frontend/makefile
Normal file
110
frontend/makefile
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# Variables
|
||||
YARN := $(shell which yarn)
|
||||
LOGS_DIR := logs
|
||||
ENV_FILE := .env
|
||||
|
||||
# Create logs directory if it doesn't exist
|
||||
$(shell mkdir -p $(LOGS_DIR))
|
||||
|
||||
# Function to read a variable from .env file, with default value
|
||||
define read_env
|
||||
$(shell if [ -f $(ENV_FILE) ]; then \
|
||||
grep -E "^$(1)=" $(ENV_FILE) 2>/dev/null | \
|
||||
sed -E 's/^$(1)=//;s/^"//;s/"$$//;s/^'\''//;s/'\''$$//' | \
|
||||
head -n 1; \
|
||||
else \
|
||||
echo "$(2)"; \
|
||||
fi)
|
||||
endef
|
||||
|
||||
# Read environment variables from .env file
|
||||
NODE_ENV := $(call read_env,NODE_ENV,development)
|
||||
API_EDP := $(call read_env,API_EDP,http://localhost:3000)
|
||||
|
||||
# Default target
|
||||
.PHONY: all
|
||||
all: start
|
||||
|
||||
# Target to start the frontend app
|
||||
.PHONY: start
|
||||
start:
|
||||
@if [ -z "$(YARN)" ]; then \
|
||||
echo "Error: yarn command not found. Please install yarn."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if pgrep -f "$(YARN) start" > /dev/null; then \
|
||||
echo "Frontend app is already running"; \
|
||||
echo "Running processes:"; \
|
||||
ps -ef | grep "$(YARN) start" | grep -v grep; \
|
||||
else \
|
||||
echo "Starting frontend app with NODE_ENV=$(NODE_ENV) and API_EDP=$(API_EDP)"; \
|
||||
mkdir -p $(LOGS_DIR); \
|
||||
LOG_FILE=$(LOGS_DIR)/frontend-$(shell date +%Y%m%d%H%M%S).log; \
|
||||
NODE_ENV=$(NODE_ENV) API_EDP=$(API_EDP) $(YARN) start > $$LOG_FILE 2>&1 & \
|
||||
echo "Frontend app started with PID: $$!"; \
|
||||
echo "Logs are available in $$LOG_FILE"; \
|
||||
fi
|
||||
|
||||
# Target to start the frontend app in foreground with visible logs
|
||||
.PHONY: start-fg
|
||||
start-fg:
|
||||
@if [ -z "$(YARN)" ]; then \
|
||||
echo "Error: yarn command not found. Please install yarn."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if pgrep -f "$(YARN) start" > /dev/null; then \
|
||||
echo "Frontend app is already running"; \
|
||||
echo "Running processes:"; \
|
||||
ps -ef | grep "$(YARN) start" | grep -v grep; \
|
||||
else \
|
||||
echo "Starting frontend app with NODE_ENV=$(NODE_ENV) and API_EDP=$(API_EDP)"; \
|
||||
mkdir -p $(LOGS_DIR); \
|
||||
LOG_FILE=$(LOGS_DIR)/frontend-$(shell date +%Y%m%d%H%M%S).log; \
|
||||
NODE_ENV=$(NODE_ENV) API_EDP=$(API_EDP) $(YARN) start 2>&1 | tee $$LOG_FILE; \
|
||||
fi
|
||||
|
||||
# Target to stop the frontend app
|
||||
.PHONY: stop
|
||||
stop:
|
||||
@if pgrep -f "yarn" > /dev/null; then \
|
||||
echo "Stopping all yarn processes..."; \
|
||||
pkill -f "yarn"; \
|
||||
echo "All yarn processes have been stopped."; \
|
||||
else \
|
||||
echo "No yarn processes are currently running."; \
|
||||
fi
|
||||
|
||||
# Target to show status of the frontend app
|
||||
.PHONY: status
|
||||
status:
|
||||
@if pgrep -f "$(YARN) start" > /dev/null; then \
|
||||
echo "Frontend app is running"; \
|
||||
echo "Running processes:"; \
|
||||
ps -ef | grep "$(YARN) start" | grep -v grep; \
|
||||
else \
|
||||
echo "Frontend app is not running"; \
|
||||
fi
|
||||
|
||||
# Target to show logs
|
||||
.PHONY: logs
|
||||
logs:
|
||||
@if [ -d "$(LOGS_DIR)" ] && [ "$$(ls -A $(LOGS_DIR) 2>/dev/null)" ]; then \
|
||||
echo "Available log files:"; \
|
||||
ls -la $(LOGS_DIR); \
|
||||
echo ""; \
|
||||
echo "To view a specific log file, use: cat $(LOGS_DIR)/<log_file>"; \
|
||||
else \
|
||||
echo "No log files found in $(LOGS_DIR)"; \
|
||||
fi
|
||||
|
||||
# Target to show help
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " make - Starts the frontend app in the background"
|
||||
@echo " make start - Starts the frontend app in the background"
|
||||
@echo " make start-fg - Starts the frontend app in the foreground with visible logs"
|
||||
@echo " make stop - Stops all yarn processes"
|
||||
@echo " make status - Shows the current status of the frontend app"
|
||||
@echo " make logs - Shows available log files"
|
||||
@echo " make help - Shows this help message"
|
||||
Loading…
Add table
Reference in a new issue