From 3352c6f21a33d6b02396e673a67e2a793b620564 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 4 Feb 2024 03:46:53 +0100 Subject: [PATCH] [#1] [Ticket] Setup Makefile --- app/.env.make | 16 ++++++ app/.php-version | 1 + app/Makefile | 126 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 app/.env.make create mode 100644 app/.php-version create mode 100644 app/Makefile diff --git a/app/.env.make b/app/.env.make new file mode 100644 index 0000000..827698d --- /dev/null +++ b/app/.env.make @@ -0,0 +1,16 @@ +# Colors +COLOR_BASE=\033 +COLOR_CLEAR=[0m +COLOR_BLUE=[34m +COLOR_GREEN=[32m +COLOR_YELLOW=[33m +COLOR_RED=[31m + +CLEAR=${COLOR_BASE}${COLOR_CLEAR} +BLUE=${COLOR_BASE}${COLOR_BLUE} +GREEN=${COLOR_BASE}${COLOR_GREEN} +YELLOW=${COLOR_BASE}${COLOR_YELLOW} +RED=${COLOR_BASE}${COLOR_RED} + +COLOR_HELP_GROUP=${COLOR_BLUE} +COLOR_HELP_COMMAND=${COLOR_GREEN} diff --git a/app/.php-version b/app/.php-version new file mode 100644 index 0000000..0dc0f32 --- /dev/null +++ b/app/.php-version @@ -0,0 +1 @@ +8.2 \ No newline at end of file diff --git a/app/Makefile b/app/Makefile new file mode 100644 index 0000000..199da44 --- /dev/null +++ b/app/Makefile @@ -0,0 +1,126 @@ +include .env.make + +##|--[ General ]---------------------------------------------------| +help: ## Shops available Commands + @grep -E '(^[a-zA-Z0-9_-]+:.*##.*$$)|(^##)' Makefile| \ + awk 'BEGIN {FS = ":.*?## "}{printf "${COLOR_BASE}${COLOR_HELP_COMMAND}%-20s${CLEAR} %s\n", $$1, $$2}' | \ + sed -e "s/\${COLOR_HELP_COMMAND}##/${COLOR_HELP_GROUP}/" + +check: ## Checks whether Requirements are met + @printf "${BLUE}▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n" + @printf "█ Checking Requirements █\n" + @printf "▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀${CLEAR}\n" + + @# Check Symfony CLI + @command -v symfony >/dev/null 2>&1 || \ + { \ + printf >&2 "${RED}✘ Symfony CLI${YELLOW} is ${RED}not installed${YELLOW}! please install it from:\nhttps://symfony.com/download\n"; \ + exit 1; \ + } + @printf >&2 "${GREEN}✔ Symfony CLI${BLUE} is ${GREEN}installed${BLUE}!\n" + + @# Check PHP + @command -v php >/dev/null 2>&1 || \ + { printf >&2 "${RED}✘ PHP${YELLOW} is ${RED}not installed${YELLOW}!\n"; exit 1;} + @# Check PHP Version + @required_php_version=$$(cat .php-version) && \ + current_php_version=$$(symfony php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;") && \ + [ "$${current_php_version}" = "$${required_php_version}" ] || \ + { \ + printf >&2 "${RED}✘ Wrong PHP Version${YELLOW} is installed!\n Version ${RED}$${required_php_version}${YELLOW} is ${RED}required${YELLOW}.\n"; \ + symfony local:php:list; \ + exit 1; \ + } && \ + printf >&2 "${GREEN}✔ PHP${BLUE} Version ${GREEN}$${current_php_version}${BLUE} is ${GREEN}installed${BLUE}.\n" + + @# Check Composer + @command -v composer >/dev/null 2>&1 || \ + { printf >&2 "${RED}✘ Composer${YELLOW} is ${RED}not installed${YELLOW}!\n"; exit 1;} + @# Check Composer Version + @current_composer_version=$$(composer --version | awk '{print $$3}' | cut -d '.' -f 1) && \ + [ "$${current_composer_version}" = "2" ] || \ + { \ + printf >&2 "${RED}✘ Wrong Composer Version${YELLOW} is installed!\n Version ${RED}2${YELLOW} is ${RED}required${YELLOW}.\n"; \ + exit 1; \ + } && \ + printf >&2 "${GREEN}✔ Composer${BLUE} Version ${GREEN}$${current_composer_version}${BLUE} is ${GREEN}installed${BLUE}.\n" + + @# Check Volta + @command -v volta >/dev/null 2>&1 || \ + { \ + printf >&2 "${RED}✘ Volta${YELLOW} is ${RED}not installed${YELLOW}! \n"; \ + exit 1; \ + } + @printf >&2 "${GREEN}✔ Volta${BLUE} is ${GREEN}installed${BLUE}.\n" + + @# Check Node + @command -v node >/dev/null 2>&1 || \ + { printf >&2 "${RED}✘ Node${YELLOW} is ${RED}not installed${YELLOW}!\n"; exit 1;} + @# Check Node Version + @required_node_version=$$(cat package.json | grep -oP '(?<="node": ")([0-9]*)(?=\.[0-9]*\.[0-9]")') && \ + current_major_node_version=$$(node -v | cut -c 2- | cut -d '.' -f 1) && \ + current_node_version=$$(node -v | cut -c 2-) && \ + [ "$${current_major_node_version}" = "$${required_node_version}" ] || \ + { \ + printf >&2 "${RED}✘ Wrong Node Version${YELLOW} is installed!\n Version ${RED}$${required_node_version}${YELLOW} is ${RED}required${YELLOW}.\n"; \ + exit 1; \ + } && \ + printf >&2 "${GREEN}✔ Node${BLUE} Version ${GREEN}$${current_node_version}${BLUE} is ${GREEN}installed${BLUE}.\n" + + @# Check NPM + @command -v npm >/dev/null 2>&1 || \ + { \ + printf >&2 "${RED}✘ NPM${YELLOW} is ${RED}not installed${YELLOW}!\n Install it via Volta.\n"; \ + exit 1; \ + } + @printf >&2 "${GREEN}✔ NPM${BLUE} is ${GREEN}installed${BLUE}.\n" + +##|--[ Local Server ]----------------------------------------------| +start: ## Starts the Local Instance + @make stop + make check + docker compose up -d + symfony local:server:start -d --no-tls + bash -c '$(npm run watch)& echo $! > ./npm-watch.pid' + +stop: ## Stops the Local Instance +ifneq (,$(wildcard ./npm-watch.pid)) + @printf "${RED}Killing ${YELLOW}Encore${CLEAR}!\n" + kill $$(cat ./npm-watch.pid) + @rm -rf ./npm-watch.pid +endif + symfony local:server:stop + docker compose down + +fresh: ## Starts a Fresh Local Instance + make stop + symfony composer install + npm i + make start + make db-demo + +##|--[ Code Quality ]----------------------------------------------| +lint: ## Runs the Linters + vendor/bin/php-cs-fixer fix + npm run lint:fix + php bin/console lint:fix + +analyze: ## Runs Static Code Analysis + vendor/bin/phpstan analyze + +test: ## Runs all Unittests + vendor/bin/phpunit + +##|--[ Data ]------------------------------------------------------| +db-demo: ## Writes the Demo Data to the Local Instance + symofny console doctrine:database:drop --if-exists --force + symofny console doctrine:database:create + symofny console doctrine:schema:update --force + symfony console doctrine:fixtures:load -n + symfony console cache:clear + +db-migration-gen: ## Generates a Migration + symfony console doctrine:migration:diff + +db-migration-do: ## Does the Migration + symfony console doctrine:migration:migrate \ No newline at end of file