From 78dfdbe162260748b1c9d8854e8f718403453540 Mon Sep 17 00:00:00 2001 From: Darko Gjorgjijoski <5760249+gdarko@users.noreply.github.com> Date: Tue, 2 Sep 2025 03:32:21 +0200 Subject: [PATCH] Devenv subcommands for test / format (#462) * Add devenv subcommands for test / format * Rename dev-env-config to devenvconfig for consitency sake --- .dockerignore | 2 +- .gitignore | 2 +- devenv | 46 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index fb8ec04b..80d0b6b3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -21,6 +21,7 @@ tests/ vendor/ .dockerignore +.devenvconfig .editorconfig .env .env.testing @@ -28,7 +29,6 @@ vendor/ .gitattributes .gitignore .prettierrc.json -.dev-env-config devenv CODE_OF_CONDUCT.md diff --git a/.gitignore b/.gitignore index 0b38b06c..9fddec3b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ Homestead.yaml !storage/fonts/.gitkeep .DS_Store .php-cs-fixer.cache -.dev-env-config +.devenvconfig /storage/fonts* package-lock.json /docker/development/docker-compose.yml diff --git a/devenv b/devenv index 9858d3cc..bdb3a46a 100755 --- a/devenv +++ b/devenv @@ -42,6 +42,8 @@ show_usage() { echo " rebuild Rebuild and restart the development environment" echo " shell Enter the PHP container's shell" echo " run [CMD] Run a command inside the PHP container (e.g., ./artisan)" + echo " test Run the test suite (Pest)" + echo " format Format the code (Pint)" echo "" echo "Examples:" echo " $0 # Interactive setup and start" @@ -72,7 +74,7 @@ get_docker_compose_cmd() { # Function to find the most recent compose file used find_compose_file() { - local config_file=".dev-env-config" + local config_file=".devenvconfig" if [ -f "$config_file" ]; then cat "$config_file" @@ -84,7 +86,7 @@ find_compose_file() { # Function to save compose file configuration save_config() { local compose_file=$1 - echo "$compose_file" > .dev-env-config + echo "$compose_file" > .devenvconfig } # Function to check if host entry exists @@ -333,7 +335,7 @@ cmd_destroy() { if $docker_compose -f "$compose_file" down --rmi all --volumes --remove-orphans; then print_success "Development environment destroyed successfully!" # Remove the config file since everything is destroyed - rm -f .dev-env-config + rm -f .devenvconfig else print_error "Failed to destroy development environment" exit 1 @@ -427,6 +429,36 @@ cmd_run() { docker exec -it -w /var/www/html invoiceshelf-dev-php "$@" } +# Function to run tests +cmd_test() { + print_info "Running tests (Pest)..." + + # Check if the container is running first + if ! docker ps --format "{{.Names}}" | grep -q "invoiceshelf-dev-php"; then + print_error "PHP container 'invoiceshelf-dev-php' is not running." + print_info "Start the development environment first with: $0 start" + exit 1 + fi + + shift # Remove 'test' from arguments + docker exec -it -w /var/www/html invoiceshelf-dev-php /var/www/html/vendor/bin/pest "$@" +} + +# Function to format code +cmd_format() { + print_info "Formatting code (Pint)..." + + # Check if the container is running first + if ! docker ps --format "{{.Names}}" | grep -q "invoiceshelf-dev-php"; then + print_error "PHP container 'invoiceshelf-dev-php' is not running." + print_info "Start the development environment first with: $0 start" + exit 1 + fi + + shift # Remove 'format' from arguments + docker exec -it -w /var/www/html invoiceshelf-dev-php /var/www/html/vendor/bin/pint "$@" +} + # Function to show service information show_service_info() { echo "" @@ -537,6 +569,14 @@ main() { validate_environment > /dev/null cmd_run "$@" ;; + "test") + validate_environment > /dev/null + cmd_test "$@" + ;; + "format") + validate_environment > /dev/null + cmd_format "$@" + ;; "help"|"-h"|"--help") show_usage ;;