From 88b92924fb1cc25e3c85f6c8c5c9bf812840002b Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 24 Sep 2023 23:13:43 +0100 Subject: [PATCH] feat(astro): add justfile --- src/Action/CreateListOfFilesToGenerate.php | 1 + templates/astro/justfile.twig | 62 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 templates/astro/justfile.twig diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index 98c5ecc..8434385 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -31,6 +31,7 @@ final class CreateListOfFilesToGenerate new TemplateFile(data: 'astro/.envrc', name: '.envrc'), new TemplateFile(data: 'astro/.gitignore', name: '.gitignore'), new TemplateFile(data: 'astro/flake.nix', name: 'flake.nix'), + new TemplateFile(data: 'astro/justfile', name: 'justfile'), new TemplateFile(data: 'astro/tsconfig.json', name: 'tsconfig.json'), ]); break; diff --git a/templates/astro/justfile.twig b/templates/astro/justfile.twig new file mode 100644 index 0000000..30bb81e --- /dev/null +++ b/templates/astro/justfile.twig @@ -0,0 +1,62 @@ +# {{ managedText|raw }} + +{% set isFlake = flake is defined %} + +default: + @just --list + +{% if not isFlake %} +# Start the project +start: + cp -v --no-clobber .env.example .env + docker compose up -d + +# Stop the project +stop: + docker compose down +{% endif %} + +yarn *args: +{% if isFlake %} + {{ "just _exec yarn {{ args }}" | raw }} +{% else %} + {{ "just _exec node yarn {{ args }}" | raw }} +{% endif %} + +# Enable or disable Git hooks +git-hooks command: + #!/usr/bin/env bash + set -euo pipefail + + case "{{ '{{ command }}'|raw }}" in + "on") + echo "Enabling Git hooks..." + git config core.hooksPath .githooks + ;; + "off") + echo "Disabling Git hooks..." + git config --unset core.hooksPath + ;; + *) + echo "Error: Invalid argument. Must be either 'on' or 'off'" + ;; + esac + +_exec +args: +{% if flake is defined %} + {{ "nix develop --command {{ args }}" | raw }} +{% else %} + {{ "docker compose exec -T {{ args }}" | raw }} +{% endif %} + +{% if flake is not defined %} +_run service command *args: + docker compose run \ + --entrypoint {{ "{{ command }}"|raw }} \ + --no-deps \ + --rm \ + -T \ + {{ "{{ service }} {{ args }}"|raw }} +{% endif %} + +# vim: ft=just