Files
ia-fit/Makefile
T

106 lines
4.7 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# IA-Fit — point d'entrée unique (voir CLAUDE.md, « Le contrat du Makefile »).
SHELL := bash
.DEFAULT_GOAL := help
# Vérificateur de types des annotations JSDoc (tsc --checkJs, ADR 0007). Outil de
# développement seulement, installé dans build/tools, jamais publié. Apache-2.0.
TYPESCRIPT_VERSION := 5.9.2
TOOLS := build/tools
TSC := $(TOOLS)/node_modules/.bin/tsc
# Analyse des scripts shell, dans Docker pour ne rien installer sur le PC.
SHELLCHECK_IMAGE := koalaman/shellcheck:v0.10.0
DEV_PORT := 8080
# Publication (lot 1f, docs/deploiement.md). APP_DIR et SITE_BUILD peuvent être
# changés à l'appel : tests/test_site.sh assemble ainsi son site d'essai hors de
# build/.
APP_DIR := app
SITE_BUILD := build
SITE := $(SITE_BUILD)/site
# Ce qui, dans app/, n'est jamais publié : fichiers cachés, tests, restes
# d'éditeur.
SITE_EXCLUDE := .[!./]* *.test.js *~ *.swp *.orig
.PHONY: help setup dev test test-docs test-unit test-site lint site package deploy-prod
help: ## Liste les commandes disponibles
@echo "IA-Fit : commandes disponibles"
@grep -E '^[a-zA-Z0-9_-]+:.*## ' $(MAKEFILE_LIST) \
| awk 'BEGIN { FS = ":.*## " } { printf " make %-14s %s\n", $$1, $$2 }'
setup: $(TSC) ## Installe les outils de développement (idempotent)
$(TSC):
npm install --silent --no-audit --no-fund --prefix $(TOOLS) typescript@$(TYPESCRIPT_VERSION)
dev: ## Sert l'app en local sur le port 8080 (Ctrl+C pour arrêter)
@echo "App : http://localhost:$(DEV_PORT)/"
@python3 -m http.server $(DEV_PORT) --directory app
test: test-docs test-unit ## Lance tous les tests (dont test-site si Docker répond)
@if docker info >/dev/null 2>&1; then $(MAKE) --no-print-directory test-site; \
else echo "test-site sauté : Docker indisponible, l'image de production n'est pas vérifiée."; fi
test-docs: ## Vérifie la forme des ADR et du glossaire
@scripts/check-docs.sh
test-unit: ## Tests du domaine et de l'architecture (node --test)
@node --test 'tests/**/*.test.js'
lint: $(TSC) ## Vérifie les types (JSDoc), la syntaxe et les scripts shell
@$(TSC) -p tsconfig.json
@for f in $$(find app tests -name '*.js'); do node --check "$$f" || exit 1; done
@if command -v shellcheck >/dev/null; then shellcheck scripts/*.sh tests/*.sh; \
else docker run --rm -v "$(CURDIR):/mnt:ro" -w /mnt $(SHELLCHECK_IMAGE) scripts/*.sh tests/*.sh; fi
@echo "Lint : OK"
# Parcours dans un vrai navigateur (ADR 0007) : Chromium de l'image Playwright,
# le paquet playwright (Apache-2.0) installé dans build/browser-tools, jamais
# publié. Captures 412×915 et poids transféré dans build/shots/.
PLAYWRIGHT_VERSION := 1.48.2
PLAYWRIGHT_IMAGE := mcr.microsoft.com/playwright:v$(PLAYWRIGHT_VERSION)-noble
BROWSER_TOOLS := build/browser-tools
PLAYWRIGHT := $(BROWSER_TOOLS)/node_modules/playwright/package.json
$(PLAYWRIGHT):
npm install --silent --no-audit --no-fund --prefix $(BROWSER_TOOLS) playwright@$(PLAYWRIGHT_VERSION)
.PHONY: test-browser
test-browser: $(PLAYWRIGHT) ## Parcours Playwright de l'app, captures dans build/shots/ (Docker)
@mkdir -p build/shots
@docker run --rm --init --ipc=host -u "$$(id -u):$$(id -g)" -e HOME=/tmp \
-v "$(CURDIR)/$(APP_DIR):/app:ro" -v "$(CURDIR)/tests/browser:/tests:ro" \
-v "$(CURDIR)/$(BROWSER_TOOLS):/tools:ro" -v "$(CURDIR)/build/shots:/shots" \
$(PLAYWRIGHT_IMAGE) node /tests/parcours.cjs /app /shots
test-site: ## Construit l'image de production en local et vérifie ce qu'elle sert (Docker)
@tests/test_site.sh
# Le site tel qu'il sera publié, reconstruit entièrement à chaque appel :
# - tout le contenu de app/ tel qu'il est au moment de l'assemblage (aucune
# liste en dur : un module ajouté est publié), sauf SITE_EXCLUDE ;
# - version.json (commit publié) ;
# - sw.js, complété par la liste de tous ces fichiers et leur empreinte
# (scripts/service-worker.sh).
site: ## Assemble le site publié dans build/site/
@[ -f "$(APP_DIR)/sw.js" ] || { echo "$(APP_DIR)/sw.js absent"; exit 1; }
@rm -rf -- "$(SITE)"
@mkdir -p "$(SITE)"
@tar -C "$(APP_DIR)" $(foreach p,$(SITE_EXCLUDE),--exclude='$(p)') -cf - . | tar -C "$(SITE)" -xf -
@printf '{"commit": "%s"}\n' "$$(git rev-parse HEAD)" > "$(SITE)/version.json"
@scripts/service-worker.sh "$(SITE)"
@echo "Site assemblé : $(SITE)/ ($$(find "$(SITE)" -type f | wc -l) fichiers)"
# L'archive envoyée à CapRover : captain-definition, Dockerfile, Caddyfile et
# le site. CapRover construit l'image (une simple copie) sur le serveur.
package: site ## Prépare l'archive de déploiement build/ia-fit.tar
@rm -rf -- "$(SITE_BUILD)/deploy"
@cp -r deploy "$(SITE_BUILD)/deploy"
@cp -r "$(SITE)" "$(SITE_BUILD)/deploy/site"
@tar -cf "$(SITE_BUILD)/ia-fit.tar" -C "$(SITE_BUILD)/deploy" .
@echo "Archive prête : $(SITE_BUILD)/ia-fit.tar"
deploy-prod: ## Publie main sur CapRover (voir docs/deploiement.md)
@scripts/deploy.sh