#1 [Ticket] Improve Makefile
Some checks failed
Quality Check / Check (push) Failing after 14s

This commit is contained in:
Snoweuph 2024-02-19 22:23:38 +01:00
parent 8496de3c84
commit a6603432a5
Signed by: Snoweuph
GPG key ID: A494330694B208EF
5 changed files with 191 additions and 116 deletions

View file

@ -1,16 +0,0 @@
# 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}

View file

@ -1,120 +1,59 @@
include .env.make
##|——[ General ]—————————————————————————————————————————————————————————————————————————|
help: ## Shops available commands
@bin/make/help.sh
##|--[ 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"
@printf >&2 "${RED}TODO:${YELLOW} check for Docker compose.\n"
check: ## Checks whether requirements are met
@bin/make/check.sh
##|--[ 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'
##|——[ Local Server ]————————————————————————————————————————————————————————————————————|
up: ## Starts the Local Instance
@make down -s
@make check -s
@docker compose up -d
@symfony local:server:start -d --no-tls
@bash -c '$$(npm run watch >> var/log/encore.log)& echo $$! > ./npm-watch.pid'
stop: ## Stops the Local Instance
down: ## 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
@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
@make down -s
@symfony composer install -s
@npm i .s
@make up .s
@make db-demo s
##|--[ Code Quality ]----------------------------------------------|
lint: ## Runs the Linters
vendor/bin/php-cs-fixer fix --allow-risky=yes
npm run lint:fix
php bin/console lint:twig
##|——[ Code Quality ]————————————————————————————————————————————————————————————————————|
test: ## Runs all Unittests
vendor/bin/phpunit
analyze: ## Runs Static Code Analysis
vendor/bin/phpstan analyze
test: ## Runs all Unittests
vendor/bin/phpunit
lint: ## Runs the Linters
@make lint-php -s
@make lint-ts -s
@make lint-twig -s
##|--[ Data ]------------------------------------------------------|
lint-php: ## Runs the PHP Linting
vendor/bin/php-cs-fixer fix --allow-risky=yes
lint-ts: ## Runs the Typescript Linting
npm run lint:fix
lint-twig: ## Runs Twig Linting
vendor/bin/twig-cs-fixer lint --fix
php bin/console lint:twig
##|——[ Data ]————————————————————————————————————————————————————————————————————————————|
db-demo: ## Writes the Demo Data to the Local Instance
symofny console doctrine:database:drop --if-exists --force
symofny console doctrine:database:create

99
app/bin/make/check.sh Executable file
View file

@ -0,0 +1,99 @@
#!/bin/bash
source bin/make/colors.sh
printf "${BLUE_BG} ${CLEAR}\n"
printf "${BLUE_BG}${BLACK_FG} Checking Requirements ${CLEAR}\n"
printf "${BLUE_BG} ${CLEAR}\n"
# Check Symfony CLI
command -v symfony >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ Symfony CLI${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}! please install it from:\nhttps://symfony.com/download\n"; \
exit 1; \
}
printf >&2 "${GREEN_FG}✔ Symfony CLI${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}!\n"
# Check PHP
command -v php >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ PHP${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\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_FG}✘ Wrong PHP Version${YELLOW_FG} is installed!\n Version ${RED_FG}${required_php_version}${YELLOW_FG} is ${RED_FG}required${YELLOW_FG}.\n"; \
symfony local:php:list; \
exit 1; \
} && \
printf >&2 "${GREEN_FG}✔ PHP${BLUE_FG} Version ${GREEN_FG}${current_php_version}${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check Composer
command -v composer >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ Composer${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\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_FG}✘ Wrong Composer Version${YELLOW_FG} is installed!\n Version ${RED_FG}2${YELLOW_FG} is ${RED_FG}required${YELLOW_FG}.\n"; \
exit 1; \
} && \
printf >&2 "${GREEN_FG}✔ Composer${BLUE_FG} Version ${GREEN_FG}${current_composer_version}${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check Volta
command -v volta >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ Volta${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}! \n"; \
exit 1; \
}
printf >&2 "${GREEN_FG}✔ Volta${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check Node
command -v node >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ Node${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\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_FG}✘ Wrong Node Version${YELLOW_FG} is installed!\n Version ${RED_FG}${required_node_version}${YELLOW_FG} is ${RED_FG}required${YELLOW_FG}.\n"; \
exit 1; \
} && \
printf >&2 "${GREEN_FG}✔ Node${BLUE_FG} Version ${GREEN_FG}${current_node_version}${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check NPM
command -v npm >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ NPM${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\n Install it via Volta.\n"; \
exit 1; \
}
printf >&2 "${GREEN_FG}✔ NPM${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check for Docker
command -v docker >/dev/null 2>&1 || \
{ \
printf >&2 "${RED_FG}✘ Docker${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\n"; \
exit 1; \
}
printf >&2 "${GREEN_FG}✔ Docker${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"
# Check for Docker Compose
! docker compose version >/dev/null 2>&1 && \
{ \
printf >&2 "${RED_FG}✘ Docker Compose${YELLOW_FG} is ${RED_FG}not installed${YELLOW_FG}!\n"; \
exit 1; \
}
printf >&2 "${GREEN_FG}✔ Docker Compose${BLUE_FG} is ${GREEN_FG}installed${BLUE_FG}.\n"

42
app/bin/make/colors.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/bash
# Colors
COLOR_MARKER='\033'
COLOR_START='['
COLOR_END='m'
COLOR_CLEAR='0'
COLOR_FG='3'
COLOR_BG='4'
COLOR_WHITE='8'
COLOR_BLACK='7'
COLOR_RED='1'
COLOR_GREEN='2'
COLOR_YELLOW='3'
COLOR_BLUE='4'
COLOR_MAGENTA='5'
COLOR_CYAN='6'
# Clear Color
CLEAR=${COLOR_MARKER}${COLOR_START}${COLOR_CLEAR}${COLOR_END}
# Set Foreground
WHITE_FG=${COLOR_MARKER}${COLOR_START}${COLOR_WHITE}${COLOR_WHITE}${COLOR_END}
BLACK_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_BLACK}${COLOR_END}
RED_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_RED}${COLOR_END}
YELLOW_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_YELLOW}${COLOR_END}
GREEN_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_GREEN}${COLOR_END}
CYAN_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_CYAN}${COLOR_END}
BLUE_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_BLUE}${COLOR_END}
MAGENTA_FG=${COLOR_MARKER}${COLOR_START}${COLOR_FG}${COLOR_MAGENTA}${COLOR_END}
# Set Background
WHITE_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_WHITE}${COLOR_END}
BLACK_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_BLACK}${COLOR_END}
RED_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_RED}${COLOR_END}
YELLOW_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_YELLOW}${COLOR_END}
GREEN_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_GREEN}${COLOR_END}
CYAN_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_CYAN}${COLOR_END}
BLUE_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_BLUE}${COLOR_END}
MAGENTA_BG=${COLOR_MARKER}${COLOR_START}${COLOR_BG}${COLOR_MAGENTA}${COLOR_END}

11
app/bin/make/help.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
source bin/make/colors.sh
COLOR_HELP_GROUP=${COLOR_START}${COLOR_FG}${COLOR_BLUE}${COLOR_END}
COLOR_HELP_COMMAND=${COLOR_START}${COLOR_FG}${COLOR_GREEN}${COLOR_END}
COLOR_HELP_COMMAND_DESCRIPTION=${CLEAR}
grep -E '(^[a-zA-Z0-9_-]+:.*##.*$$)|(^##)' Makefile \
| awk "BEGIN {FS = \":.*?## \"}{printf \"${COLOR_MARKER}${COLOR_HELP_COMMAND}%-20s${COLOR_HELP_COMMAND_DESCRIPTION} %s\n\", \$1, \$2}" \
| sed -e "s/\\${COLOR_HELP_COMMAND}##/${COLOR_HELP_GROUP}/"