Skip to content

Commit

Permalink
Add base feature for generating a new feature of the plugin (#317)
Browse files Browse the repository at this point in the history
* Stubbing out the dream syntax

* Adjusting the stub files

* Adjusting the stub files0

* Finish the templates

* Readme update

* REVERT

* Adjusting the stubs

* Wrapping up the stubs

* Update feature name

* Remove bad file

* Adjusting the stub files

* Finishing new stubs

* Wrap up feature for generating a plugin feature

* Revert plugin deletiojn
  • Loading branch information
srtfisher authored Mar 6, 2024
1 parent 2304e00 commit f98a5ae
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .scaffolder/plugin-feature/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: create-wordpress-plugin@plugin-feature

inputs:
- name: featureName
description: "Feature Name"
type: string
- name: tests
description: "Include Tests?"
type: boolean
default: true

files:
- source: feature.php.hbs
destination: src/features/{{ wpClassFilename inputs.featureName }}
- source: test.php.hbs
if: "{{ inputs.tests }}"
destination: tests/Features/{{ psrClassFilename inputs.featureName suffix="Test.php" }}
27 changes: 27 additions & 0 deletions .scaffolder/plugin-feature/feature.php.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* {{ wpClassName inputs.featureName }} class file
*
* @package Create_WordPress_Plugin
*/

namespace Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Features" }};

use Alley\WP\Types\Feature;

/**
* {{ replace (wpClassName inputs.featureName) "_" " " }} Feature
*/
final class {{ wpClassName inputs.featureName }} implements Feature {
/**
* Set up the feature.
*/
public function __construct() {}

/**
* Boot the feature.
*/
public function boot(): void {
// Add any actions or filters here.
}
}
25 changes: 25 additions & 0 deletions .scaffolder/plugin-feature/test.php.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* {{ psrClassName name }} test class file
*
* @package create-wordpress-plugin
*/

namespace Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Tests\Features" }};

use Create_WordPress_Plugin\Tests\TestCase;
use Create_WordPress_Plugin\\{{ wpNamespace inputs.featureName prefix="Features" }}\\{{ wpClassName inputs.featureName }};

/**
* {{ replace (psrClassName inputs.featureName) "_" " " }} Test for the {{ wpClassName inputs.featureName }} class.
*
* @link https://mantle.alley.com/docs/testing
*/
class {{ psrClassName inputs.featureName suffix="Test" }} extends TestCase {
/**
* An example test for the feature.
*/
public function test_example() {
$this->assertTrue( true );
}
}
34 changes: 33 additions & 1 deletion configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,39 @@ function determine_separator( string $path ): string {
* @return array<int, string>
*/
function list_all_files_for_replacement(): array {
return explode( PHP_EOL, run( 'grep -R -l . --exclude LICENSE --exclude configure.php --exclude .phpunit.result.cache --exclude-dir .phpcs --exclude composer.lock --exclude-dir .git --exclude-dir .github --exclude-dir vendor --exclude-dir node_modules --exclude-dir modules --exclude-dir .phpcs' ) );
$exclude = [
'LICENSE',
'configure.php',
'.phpunit.result.cache',
'.phpcs',
'composer.lock',
];

$exclude_dirs = [
'.git',
'pantheon-mu-plugin',
'vendor',
'node_modules',
'.phpcs',
'.scaffolder',
];

$exclude = array_map(
fn ( string $file ) => "--exclude {$file}",
$exclude,
);

$exclude_dirs = array_map(
fn ( string $dir ) => "--exclude-dir {$dir}",
$exclude_dirs,
);

return explode(
PHP_EOL,
run(
"grep -R -l . " . implode( ' ', $exclude_dirs ) . ' ' . implode( ' ', $exclude ),
),
);
}

/**
Expand Down

0 comments on commit f98a5ae

Please sign in to comment.