Skip to content

Commit

Permalink
Update makefile and configurations for wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHolbrook committed Jul 11, 2022
1 parent 53594d0 commit 946af21
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "proprietary",
"type": "project",
"require": {
"php": "^8.0 || ^8.1"
"php": "^8.0 || ^8.1",
"yosymfony/toml": "^1.0"
},
"require-dev": {},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
Expand Down
9 changes: 0 additions & 9 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ class Application
*/
private const VERSION = '0.1.0';

private const COMPOSER_PACKAGES = [
'friendsofphp/php-cs-fixer',
'pestphp/pest',
'php-parallel-lint/php-console-highlighter',
'php-parallel-lint/php-parallel-lint',
'phpmd/phpmd',
'phpstan/phpstan',
];

/**
* Whether to overwrite existing build process files
* By default it will NOT overwrite existing files in cases where someone has altered them for the project
Expand Down
12 changes: 10 additions & 2 deletions src/Traits/ComposerPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

namespace ZeekBuildProcess\Traits;

use Yosymfony\Toml\Toml;

trait ComposerPackages
{
private function composerPackages(): array {
$packages = Toml::parseFile($this->templateDir . '/composer-packages.toml');

return $packages['packages'];
}

private function setupComposerPackages(): void
{
$this->exec(sprintf('composer require --dev -n --quiet %s',
implode(' ', self::COMPOSER_PACKAGES)
implode(' ', $this->composerPackages())
));
}

private function removeComposerPackages(): void
{
$this->exec(sprintf('composer remove --dev -n --quiet %s',
implode(' ', self::COMPOSER_PACKAGES)
implode(' ', $this->composerPackages())
));
}
}
27 changes: 12 additions & 15 deletions templates-wp/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
.DEFAULT_GOAL := help
.PHONY: $(filter-out vendor node_modules,$(MAKECMDGOALS))

bin = ./mu-plugins/app/vendor/bin
appDir = ./mu-plugins/app
bin = $(appDir)/vendor/bin

help: ## This help message
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
@grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}'

# Aliases
precommit: cs-fixer lint phpstan ## Run style fixing and linting commands
precommit: cs-fixer lint ## Run style fixing and linting commands
scan: cs-fixer lint phpmd phpstan ## Run all scans including mess detection and static analysis
baseline: phpstan-baseline phpmd-baseline ## Generate baselines for mess detection and static analysis
build: versions clean vendor node_modules precommit ## Recompile all assets from scratch

# Version Management
versions: ## Set PHP version
@valet use php@8.1
versions: ## Set PHP version. Using php 8.0 as it is the latest allowable version on WP Engine
@valet use php@8.0

## Build Processes
vendor: composer.json composer.lock ## Install PHP dependencies
Expand All @@ -35,29 +36,25 @@ cs-fixer: ## Code styling fixer
@$(bin)/php-cs-fixer fix --config=build/php-cs-fixer/php-cs-fixer.dist.php --quiet

lint: ## PHP Syntax Checking
@$(bin)/parallel-lint -j 10 app config routes --no-progress --colors --blame
@$(bin)/parallel-lint -j 10 $(appDir) --exclude $(appDir)/vendor --no-progress --colors --blame

lint-ci:
$(bin)/parallel-lint -j 10 app --no-progress --colors --checkstyle > report.xml
$(bin)/parallel-lint -j 10 $(appDir) --exclude $(appDir)/vendor --no-progress --colors --checkstyle > report.xml

phpmd: ## PHP Mess Detection
@$(bin)/phpmd app ansi build/phpmd/phpmd.xml
@$(bin)/phpmd $(appDir)/src,$(appDir)/src-psr-4 ansi build/phpmd/phpmd.xml

phpmd-ci:
@$(bin)/phpmd app github build/phpmd/phpmd.xml
@$(bin)/phpmd $(appDir)/src,$(appDir)/src-psr-4 github build/phpmd/phpmd.xml

phpmd-baseline: ## PHP Mess Detection. Generate Baseline
@$(bin)/phpmd app ansi build/phpmd/phpmd.xml --generate-baseline
@$(bin)/phpmd $(appDir)/src,$(appDir)/src-psr-4 ansi build/phpmd/phpmd.xml --generate-baseline

phpstan: ## PHP Static Analyzer
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist

phpstan-ci:
@$(bin)/phpstan analyse --no-progress --error-format=github build/phpstan/phpstan.neon.dist
@$(bin)/phpstan analyse --no-progress --error-format=github -c build/phpstan/phpstan.neon.dist

phpstan-baseline: ## PHP Static Analyzer. Generate Baseline.
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist --generate-baseline=build/phpstan/phpstan-baseline.neon

# Testing. Requires installing Pest. (Not included by default).
pest: ## PHP Tests
$(bin)/pest --colors=always -c build/pest/phpunit.xml
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist --generate-baseline=build/phpstan/phpstan-baseline.neon --allow-empty-baseline
7 changes: 2 additions & 5 deletions templates-wp/build/php-cs-fixer/php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
$appDir = dirname(__DIR__, 2);

$finder = PhpCsFixer\Finder::create()
->in($appDir.'/app')
->in($appDir.'/config')
->in($appDir.'/database')
->in($appDir.'/routes')
->in($appDir.'/mu-plugins/app')
->name('*.php')
->notName('*.blade.php')
->notName('*.env.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('vendor');
Expand Down
4 changes: 3 additions & 1 deletion templates-wp/build/phpstan/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
includes:
- phpstan-baseline.neon
- ../../mu-plugins/app/vendor/szepeviktor/phpstan-wordpress/extension.neon

parameters:
reportUnmatchedIgnoredErrors: false
paths:
- ../../app
- ../../mu-plugins/app/src
- ../../mu-plugins/app/src-psr-4

# The level 8 is the highest level
level: 4
8 changes: 8 additions & 0 deletions templates-wp/composer-packages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packages = [
"friendsofphp/php-cs-fixer",
"php-parallel-lint/php-console-highlighter",
"php-parallel-lint/php-parallel-lint",
"phpmd/phpmd",
"phpstan/phpstan",
"szepeviktor/phpstan-wordpress",
]
4 changes: 2 additions & 2 deletions templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ phpstan: ## PHP Static Analyzer
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist

phpstan-ci:
@$(bin)/phpstan analyse --no-progress --error-format=github build/phpstan/phpstan.neon.dist
@$(bin)/phpstan analyse --no-progress --error-format=github -c build/phpstan/phpstan.neon.dist

phpstan-baseline: ## PHP Static Analyzer. Generate Baseline.
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist --generate-baseline=build/phpstan/phpstan-baseline.neon
@$(bin)/phpstan analyse --error-format=table -c build/phpstan/phpstan.neon.dist --generate-baseline=build/phpstan/phpstan-baseline.neon --allow-empty-baseline

# Testing. Requires installing Pest. (Not included by default).
pest: ## PHP Tests
Expand Down
8 changes: 8 additions & 0 deletions templates/composer-packages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packages = [
"friendsofphp/php-cs-fixer",
"pestphp/pest",
"php-parallel-lint/php-console-highlighter",
"php-parallel-lint/php-parallel-lint",
"phpmd/phpmd",
"phpstan/phpstan"
]

0 comments on commit 946af21

Please sign in to comment.