From 3a5510470b52147b70f12d35e132d3510cc25c6b Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 24 Apr 2023 00:42:03 +0200 Subject: [PATCH] Implemented the documentation preview and generation workflows in the Makefile file. --- .env | 11 +++++++++++ Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .env create mode 100644 Makefile diff --git a/.env b/.env new file mode 100644 index 0000000..4cf43d9 --- /dev/null +++ b/.env @@ -0,0 +1,11 @@ +# -- PROJECT --- + +SWIFT_TARGET_NAME=AmiiboService + +# --- DOCUMENTATION --- + +SWIFT_DOC_FOLDER=./Documentation +SWIFT_DOC_GITHUB_OUTPUT=${SWIFT_DOC_FOLDER}/github +SWIFT_DOC_GITHUB_BASE_PATH=amiibo-service +SWIFT_DOC_PREVIEW_URL=http://localhost:8080/documentation/amiiboservice +SWIFT_DOC_XCODE_OUTPUT=${SWIFT_DOC_FOLDER}/${SWIFT_TARGET_NAME}.doccarchive diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..23c114c --- /dev/null +++ b/Makefile @@ -0,0 +1,57 @@ +# --- IMPORTS --- + +# Imports environment variables. +environment_vars ?= .env + +include $(environment_vars) +export $(shell sed 's/=.*//' $(environment_vars)) + +# --- DOCUMENTATION --- + +preview-doc: ## Previews the project documentation for web. + @open -a safari $(SWIFT_DOC_PREVIEW_URL) + @swift package \ + --disable-sandbox \ + preview-documentation \ + --target $(SWIFT_TARGET_NAME) + +generate-doc: generate-doc-setup generate-doc-xcode generate-doc-github ## Generates the project documentation for Xcode and Github. + +generate-doc-setup: +# Checks if the documentation root folder exists. +ifeq ("$(shell test -e ${SWIFT_DOC_FOLDER} && echo yes)","yes") + @echo Cleaning up the documentation folder... + @rm -rf ${SWIFT_DOC_FOLDER} +endif + @echo Creating the documentation folder... + @mkdir ${SWIFT_DOC_FOLDER} + +generate-doc-xcode: + @echo Generating documentation for Xcode... + @swift package \ + --allow-writing-to-directory $(SWIFT_DOC_XCODE_OUTPUT) \ + generate-documentation \ + --target $(SWIFT_TARGET_NAME) \ + --output-path $(SWIFT_DOC_XCODE_OUTPUT) + +generate-doc-github: + @echo Generating documentation for Github pages... + @swift package \ + --allow-writing-to-directory $(SWIFT_DOC_GITHUB_OUTPUT) \ + generate-documentation \ + --target $(SWIFT_TARGET_NAME) \ + --disable-indexing \ + --transform-for-static-hosting \ + --hosting-base-path $(SWIFT_DOC_GITHUB_BASE_PATH) \ + --output-path $(SWIFT_DOC_GITHUB_OUTPUT) + +# --- HELP --- + +# Outputs the documentation for each of the defined tasks when `help` is called. +# Reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.PHONY: help + +help: ## Prints the written documentation for all the defined tasks. + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help