From 208bdf138fd3808adeb1e81956051fce5c3afc55 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Wed, 18 Jun 2025 09:48:35 +0300 Subject: [PATCH] build: update build files --- .lintstagedrc.cjs | 8 +++----- .php-cs-fixer.dist.php | 1 + Makefile | 30 +++++++++++++++++++++++------- composer.json | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.lintstagedrc.cjs b/.lintstagedrc.cjs index 97e3676..7047bb5 100644 --- a/.lintstagedrc.cjs +++ b/.lintstagedrc.cjs @@ -1,8 +1,6 @@ module.exports = { '*.{ts,vue}': ['eslint --fix'], - '*.{scss,vue,ts,md,json}': ['prettier --write'], - '*.php': [ - 'php vendor-bin/cs-fixer/vendor/php-cs-fixer/shim/php-cs-fixer.phar --config=.php-cs-fixer.dist.php fix', - ], - 'ApiController.php': [() => 'make openapi'], + 'src/*.{scss,vue,ts,md,json}': ['prettier --write'], + '*.php': [() => 'make php-cs-fixer'], + '*Controller.php': [() => 'make openapi', () => 'git add openapi.json'], } diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 91fc1d9..d7614fa 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -14,6 +14,7 @@ $config ->notPath('node_modules') ->notPath('src') ->notPath('vendor') + ->notPath('gen') ->in(__DIR__); return $config; diff --git a/Makefile b/Makefile index a6518e3..3065d23 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ appstore_build_directory=$(CURDIR)/build/artifacts/appstore appstore_package_name=$(appstore_build_directory)/$(app_name) pnpm=$(shell which pnpm 2> /dev/null) composer=$(shell which composer 2> /dev/null) +composer_phar=build/tools/composer.phar all: build @@ -73,10 +74,13 @@ ifeq (, $(composer)) @echo "No composer command available, downloading a copy from the web" mkdir -p $(build_tools_directory) curl -sS https://getcomposer.org/installer | php - mv composer.phar $(build_tools_directory) - php $(build_tools_directory)/composer.phar install --prefer-dist + mv composer.phar $(composer_phar) +endif +ifneq ("$(wildcard vendor)","") + @echo "Vendor directory already exists, skipping composer install" else - composer install --prefer-dist + @echo "Installing composer dependencies..." + $(if $(composer),$(composer),php $(composer_phar)) install --prefer-dist endif # Installs pnpm dependencies @@ -172,17 +176,29 @@ test: composer .PHONY: lint lint: pnpm lint - build/tools/composer.phar run lint + $(composer_phar) run lint + +.PHONY: php-cs-fixer +php-cs-fixer: + @echo "\x1b[33mFixing PHP files...\x1b[0m" + @FILES=$$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$$' | grep -v '^gen/'); \ + if [ -z "$$FILES" ]; then \ + echo "No PHP files staged."; \ + else \ + echo "Running CS fixer on:" $$FILES; \ + php -l $$FILES || exit 1; \ + PHP_CS_FIXER_IGNORE_ENV=true php vendor-bin/cs-fixer/vendor/php-cs-fixer/shim/php-cs-fixer.phar --config=.php-cs-fixer.dist.php fix $$FILES || exit 1; \ + fi .PHONY: format format: pnpm format - PHP_CS_FIXER_IGNORE_ENV=true build/tools/composer.phar run cs:fix + PHP_CS_FIXER_IGNORE_ENV=true $(composer_phar) run cs:fix .PHONY: openapi -openapi: composer +openapi: @echo "\x1b[33mGenerating OpenAPI documentation...\x1b[0m" - build/tools/composer.phar run openapi + $(if $(composer),$(composer),php $(composer_phar)) run openapi @echo "\x1b[32mOpenAPI documentation generated at build/openapi/openapi.json\x1b[0m" .PHONY: sign diff --git a/composer.json b/composer.json index 2b675d7..cfec675 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "post-update-cmd": [ "@composer bin all update --ansi" ], - "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", + "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -not -path './gen/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l", "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "psalm": "psalm --threads=1 --no-cache",