Skip to content

Commit

Permalink
Add many improvements to the makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <[email protected]>
  • Loading branch information
alexander-demicev committed Jan 17, 2025
1 parent 3968180 commit a515e36
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 289 deletions.
89 changes: 73 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,80 @@
local:
mkdir -p tmp
# Define variables for reuse
TMP_DIR = tmp
BUILD_DIR = build
LOG_DIR = $(TMP_DIR)
SITE_DIR = $(BUILD_DIR)/site

# Playbooks
GH_PAGES_PLAYBOOK = turtles-gh-pages-playbook.yml
REMOTE_PLAYBOOK = playbook-remote.yml
DEV_PLAYBOOK = turtles-dev-playbook.yml

# Logs
GH_PAGES_LOG = $(LOG_DIR)/gh-pages-build.log
REMOTE_LOG = $(LOG_DIR)/remote-build.log
DEV_LOG = $(LOG_DIR)/dev-build.log

##@ General

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

.PHONY: build
build: ## Build the site using a specified playbook. Usage: make build PLAYBOOK=<playbook> LOG=<log_file>
@if [ -z "$(PLAYBOOK)" ] || [ -z "$(LOG)" ]; then \
echo "Error: PLAYBOOK and LOG variables must be set."; \
exit 1; \
fi
mkdir -p $(TMP_DIR)
npx antora --version
npx antora --stacktrace --log-format=pretty --log-level=info \
turtles-local-playbook.yml \
2>&1 | tee tmp/local-build.log 2>&1
$(PLAYBOOK) \
2>&1 | tee $(LOG)

remote:
mkdir -p tmp
npm install && npm update
npx antora --version
npx antora --stacktrace --log-format=pretty \
playbook-remote.yml \
2>&1 | tee tmp/remote-build.log 2>&1
.PHONY: gh-pages
gh-pages: environment ## Build the site locally using the GitHub Pages playbook.
$(MAKE) build PLAYBOOK=$(GH_PAGES_PLAYBOOK) LOG=$(GH_PAGES_LOG)

.PHONY: remote
remote: environment ## Build the site remotely using the remote playbook.
$(MAKE) build PLAYBOOK=$(REMOTE_PLAYBOOK) LOG=$(REMOTE_LOG)

clean:
rm -rf build
##@ Cleanup

environment:
.PHONY: clean
clean: ## Remove the build and temporary directories.
rm -rf $(BUILD_DIR) $(TMP_DIR)

##@ Environment

.PHONY: environment
environment: ## Install and update npm dependencies.
npm install && npm update
npm install -g nodemon
npm install -g concurrently

##@ Preview

.PHONY: preview
preview: ## Preview the site locally with http-server.
npx http-server $(SITE_DIR) -c-1

##@ Development

.PHONY: dev
dev: environment ## Build the site using the development playbook.
$(MAKE) build PLAYBOOK=$(DEV_PLAYBOOK) LOG=$(DEV_LOG)

.PHONY: watch
watch: environment ## Watch for changes, rebuild, and preview with hot reload.
concurrently \
"nodemon --watch content --watch docs --ext adoc,yml --exec 'make dev'" \
"make preview"

##@ CI

preview:
npx http-server build/site -c-1
.PHONY: ci
ci: environment gh-pages dev ## Run the build for continuous integration.
Loading

0 comments on commit a515e36

Please sign in to comment.