mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-12 21:05:19 +02:00
a4f8340b04
Compiles assets/*.ts via sensiolabs/typescript-bundle (standalone SWC binary) and adds Deno for formatting, linting, type-checking, and tests, keeping the project's no-Node/npm approach intact. Wires all four into CI, the Justfile, and the pre-commit hook.
69 lines
2.2 KiB
Bash
Executable File
69 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
setopt ERR_EXIT PIPE_FAIL NOUNSET
|
|
|
|
# Collect staged PHP and Twig files
|
|
STAGED_PHP=()
|
|
while IFS= read -r file; do
|
|
[[ -n "$file" && "$file" != "config/reference.php" ]] && STAGED_PHP+=("$file")
|
|
done < <(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.php$' || true)
|
|
|
|
STAGED_TWIG=()
|
|
while IFS= read -r file; do
|
|
[[ -n "$file" ]] && STAGED_TWIG+=("$file")
|
|
done < <(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.twig$' || true)
|
|
|
|
STAGED_TS=()
|
|
while IFS= read -r file; do
|
|
[[ -n "$file" ]] && STAGED_TS+=("$file")
|
|
done < <(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.ts$' || true)
|
|
|
|
if [[ ${#STAGED_PHP[@]} -eq 0 && ${#STAGED_TWIG[@]} -eq 0 && ${#STAGED_TS[@]} -eq 0 ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Use exec if the service is up, otherwise spin up a one-off container
|
|
if docker compose exec -T php true 2>/dev/null; then
|
|
DOCKER_CMD=(docker compose exec -T php)
|
|
else
|
|
echo "PHP service not running — using docker compose run..."
|
|
DOCKER_CMD=(docker compose run --rm php)
|
|
fi
|
|
|
|
if [[ ${#STAGED_PHP[@]} -gt 0 ]]; then
|
|
echo "PHP (${#STAGED_PHP[@]} file(s)): Rector → CS-Fixer → PHPStan"
|
|
|
|
echo " → Rector"
|
|
"${DOCKER_CMD[@]}" vendor/bin/rector process "${STAGED_PHP[@]}"
|
|
git add "${STAGED_PHP[@]}"
|
|
|
|
echo " → PHP-CS-Fixer"
|
|
"${DOCKER_CMD[@]}" vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --path-mode=intersection "${STAGED_PHP[@]}"
|
|
git add "${STAGED_PHP[@]}"
|
|
|
|
echo " → PHPStan"
|
|
"${DOCKER_CMD[@]}" vendor/bin/phpstan analyse "${STAGED_PHP[@]}" --no-progress
|
|
fi
|
|
|
|
if [[ ${#STAGED_TWIG[@]} -gt 0 ]]; then
|
|
echo "Twig (${#STAGED_TWIG[@]} file(s)): Twig-CS-Fixer"
|
|
|
|
echo " → Twig-CS-Fixer"
|
|
"${DOCKER_CMD[@]}" vendor/bin/twig-cs-fixer fix "${STAGED_TWIG[@]}"
|
|
git add "${STAGED_TWIG[@]}"
|
|
fi
|
|
|
|
if [[ ${#STAGED_TS[@]} -gt 0 ]]; then
|
|
echo "TypeScript (${#STAGED_TS[@]} file(s)): Deno fmt → lint → check"
|
|
|
|
echo " → Deno fmt"
|
|
"${DOCKER_CMD[@]}" deno fmt "${STAGED_TS[@]}"
|
|
git add "${STAGED_TS[@]}"
|
|
|
|
echo " → Deno lint"
|
|
"${DOCKER_CMD[@]}" deno lint --fix "${STAGED_TS[@]}"
|
|
git add "${STAGED_TS[@]}"
|
|
|
|
echo " → Deno check"
|
|
"${DOCKER_CMD[@]}" deno check "${STAGED_TS[@]}"
|
|
fi
|