Skip to content

Commit

Permalink
[CMS-1058] Handle WordPress coding standards. (#464)
Browse files Browse the repository at this point in the history
* Handle WordPress coding standards.

* Add missing allow-plugins and build-assets script.

* Add ignore-platform-reqs and fix other behat-related issue.

* Remove wordpress behat extension temporarily.
  • Loading branch information
kporras07 authored Oct 13, 2022
1 parent 66d2e7d commit 04d656c
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/Commands/ProjectCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,37 @@ public function copyCiFiles($ci_provider, $created_folder, $cms_version, $ci_tem
}

$composer_json = $this->getComposerJson($created_folder);
if (!isset($composer_json['scripts']['build-assets'])) {
$composer_json['scripts']['build-assets'] = "echo 'Nothing to do.'";
}
if (!isset($composer_json['scripts']['unit-test'])) {
$composer_json['scripts']['unit-test'] = "echo 'No unit test step defined.'";
$composer_json['scripts']['lint'] = "find web/modules/custom web/themes/custom -name '*.php' -exec php -l {} \\;";
$composer_json['scripts']['code-sniff'] = [
"./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/modules/custom",
"./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/themes/custom",
"./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/modules/custom",
"./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/themes/custom",
];


if ($cms_version === 'd8' || $cms_version === 'd9') {
// Linting and coding standards.
$composer_json['scripts']['lint'] = "find web/modules/custom web/themes/custom -name '*.php' -exec php -l {} \\;";
$composer_json['scripts']['code-sniff'] = [
"./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/modules/custom",
"./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/themes/custom",
"./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/modules/custom",
"./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md --ignore=node_modules,bower_components,vendor ./web/themes/custom",
];

// Config export.
$composer_json['extra']['build-env']['export-configuration'] = "drush config-export --yes";
}
elseif ($cms_version === 'wp') {
// Linting and coding standards.
$composer_json['scripts']['lint'] = [
"mkdir -p ./web/wp-content",
"find web/wp-content -name '*.php' -exec php -l {} \\;",
];
$composer_json['scripts']['code-sniff'] = [
"mkdir -p ./web/wp-content",
"./vendor/bin/phpcs --standard=WordPress --extensions=php --ignore=node_modules,bower_components,vendor ./web/wp-content",
];
}
file_put_contents("$created_folder/composer.json", json_encode($composer_json, JSON_PRETTY_PRINT));
}
$fs->mkdir("$created_folder/web/modules/custom");
Expand Down Expand Up @@ -354,16 +373,18 @@ public function createProject(
// If folder does not exists, assume we need to install composer deps.
// Require basic testing general packages.
exec("composer --working-dir=$siteDir require --no-update --dev dealerdirect/phpcodesniffer-composer-installer squizlabs/php_codesniffer phpunit/phpunit");
exec("composer --working-dir=$siteDir config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true");
// Require behat related general packages.
exec("composer --working-dir=$siteDir require --no-update --dev behat/behat behat/mink behat/mink-extension dmore/behat-chrome-extension genesis/behat-fail-aid jcalderonzumba/mink-phantomjs-driver mikey179/vfsstream");
exec("composer --working-dir=$siteDir require --no-update --dev behat/behat behat/mink dmore/behat-chrome-extension genesis/behat-fail-aid jcalderonzumba/mink-phantomjs-driver mikey179/vfsstream");

// Install packages depending on the application.
if ($app === 'Drupal') {
exec("composer --working-dir=$siteDir require --no-update --dev drupal/coder drupal/drupal-extension drupal/drupal-driver");
exec("composer --working-dir=$siteDir require --no-update drush-ops/behat-drush-endpoint");
exec("composer --working-dir=$siteDir require --no-update pantheon-systems/quicksilver-pushback");
} elseif (strtolower($app) === 'wordpress') {
exec("composer --working-dir=$siteDir require --no-update --dev paulgibbs/behat-wordpress-extension --ignore-platform-reqs");
exec("composer --working-dir=$siteDir require --no-update --dev wp-coding-standards/wpcs");
//exec("composer --working-dir=$siteDir require --no-update --dev paulgibbs/behat-wordpress-extension --ignore-platform-reqs");
}
exec("composer --working-dir=$siteDir update");
}
Expand Down

0 comments on commit 04d656c

Please sign in to comment.