From f98a69e21f2b313d2a6641f0ea81019c4929ac27 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 26 Jan 2024 07:57:07 +0000 Subject: [PATCH] Initial Sculpin support * Add Sculpin as a project type * Declare initial files to generate * Add flake.nix.twig * Add .gitignore.twig * Add run.twig --- src/Action/CreateListOfFilesToGenerate.php | 11 ++++++ src/DataTransferObject/ConfigDto.php | 2 +- src/Enum/ProjectType.php | 1 + templates/php/sculpin/.gitignore.twig | 12 +++++++ templates/php/sculpin/flake.nix.twig | 25 +++++++++++++ templates/php/sculpin/run.twig | 41 ++++++++++++++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 templates/php/sculpin/.gitignore.twig create mode 100644 templates/php/sculpin/flake.nix.twig create mode 100755 templates/php/sculpin/run.twig diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index 22bddd6..e56fab0 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -25,6 +25,17 @@ final class CreateListOfFilesToGenerate $filesToGenerate = collect(); switch (strtolower($configDto->type)) { + case (strtolower(ProjectType::Sculpin->name)): + $filesToGenerate = collect([ + new TemplateFile(data: 'php/sculpin/.gitignore', name: '.gitignore'), + new TemplateFile(data: 'php/sculpin/run', name: 'run'), + ]); + + if ($configDto->isFlake) { + $filesToGenerate->push(new TemplateFile(data: 'php/sculpin/flake.nix', name: 'flake.nix')); + } + break; + case (strtolower(ProjectType::Fractal->name)): $filesToGenerate = collect([ new TemplateFile(data: 'fractal/.gitignore', name: '.gitignore'), diff --git a/src/DataTransferObject/ConfigDto.php b/src/DataTransferObject/ConfigDto.php index 3f3c577..fe01b6e 100644 --- a/src/DataTransferObject/ConfigDto.php +++ b/src/DataTransferObject/ConfigDto.php @@ -243,7 +243,7 @@ final class ConfigDto #[Assert\Type('string')] public string $projectRoot; - #[Assert\Choice(choices: ['drupal', 'fractal', 'laravel', 'php-library', 'symfony', 'terraform'])] + #[Assert\Choice(choices: ['drupal', 'fractal', 'laravel', 'php-library', 'sculpin', 'symfony', 'terraform'])] public string $type; #[Assert\Collection([ diff --git a/src/Enum/ProjectType.php b/src/Enum/ProjectType.php index ef8507c..50b1f50 100644 --- a/src/Enum/ProjectType.php +++ b/src/Enum/ProjectType.php @@ -10,6 +10,7 @@ enum ProjectType: string case Fractal = 'fractal'; case Laravel = 'laravel'; case PHPLibrary = 'php-library'; + case Sculpin = 'sculpin'; case Symfony = 'symfony'; case Terraform = 'terraform'; } diff --git a/templates/php/sculpin/.gitignore.twig b/templates/php/sculpin/.gitignore.twig new file mode 100644 index 0000000..dba51ca --- /dev/null +++ b/templates/php/sculpin/.gitignore.twig @@ -0,0 +1,12 @@ +# {{ managedText|raw }} + +/output_*/ +/vendor/ + +{% if isFlake %} +/.direnv/ +{% endif %} + +{% for path in git.ignore %} +{{ path }} +{% endfor %} diff --git a/templates/php/sculpin/flake.nix.twig b/templates/php/sculpin/flake.nix.twig new file mode 100644 index 0000000..ba5eff8 --- /dev/null +++ b/templates/php/sculpin/flake.nix.twig @@ -0,0 +1,25 @@ +# {{ managedText|raw }} + +{ + inputs = { + devshell.url = "github:numtide/devshell"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ inputs.devshell.flakeModule ]; + + systems = [ "x86_64-linux" ]; + + perSystem = { config, self', inputs', pkgs, system, ... }: { + devshells.default = { + packages = with pkgs; [ +{% for package in flake.devshell.packages %} + "{{ package }}" +{% endfor %} + ]; + }; + }; + }; +} diff --git a/templates/php/sculpin/run.twig b/templates/php/sculpin/run.twig new file mode 100755 index 0000000..dfe82d3 --- /dev/null +++ b/templates/php/sculpin/run.twig @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +PATH="${PATH}:./vendor/bin" + +# Generate the site. +function generate { + local args=() + + if [[ "${APP_ENV:-}" == "production" ]]; then + args=(--env="prod") + else + args=(--server --watch) + fi + + sculpin generate "${args[@]}" +} + +function help { + printf "%s [args]\n\nTasks:\n" "${0}" + + compgen -A function | grep -v "^_" | cat -n + + printf "\nExtended help:\n Each task has comments for general usage\n" +} + +# Start the project. +function start { + sculpin generate --server --watch "${@}" +} + +# Include any local tasks. +[[ -e run.local ]] && source run.local + +TIMEFORMAT="Task completed in %3lR" +time "${@:-help}" + +# vim: ft=bash