Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ wp-cli/scaffold-package-command

Scaffolds WP-CLI commands with functional tests, full README.md, and more.

[![Testing](https://github.com/wp-cli/scaffold-package-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/scaffold-package-command/actions/workflows/testing.yml) [![CircleCI](https://circleci.com/gh/wp-cli/scaffold-package-command/tree/main.svg?style=svg)](https://circleci.com/gh/wp-cli/scaffold-package-command/tree/main)
[![Testing](https://github.com/wp-cli/scaffold-package-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/scaffold-package-command/actions/workflows/testing.yml) [![CircleCI](https://circleci.com/gh/wp-cli/scaffold-package-command/tree/master.svg?style=svg)](https://circleci.com/gh/wp-cli/scaffold-package-command/tree/master)

Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)

Expand All @@ -22,7 +22,7 @@ wp scaffold package <name> [--description=<description>] [--homepage=<homepage>]
Default behavior is to create the following files:
- command.php
- composer.json (with package name, description, and license)
- .gitignore, .editorconfig, and .distignore
- .gitignore, .editorconfig, .distignore, and phpcs.xml.dist
- README.md (via wp scaffold package-readme)
- Test harness (via wp scaffold package-tests)

Expand Down Expand Up @@ -316,7 +316,7 @@ wp package install wp-cli/scaffold-package-command:@stable
To install the latest development version of this package, use the following command instead:

```bash
wp package install wp-cli/scaffold-package-command:dev-main
wp package install wp-cli/scaffold-package-command:dev-master
```

## Contributing
Expand Down
13 changes: 13 additions & 0 deletions features/scaffold-package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Feature: Scaffold WP-CLI commands
"""
.gitignore
"""
And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should exist
And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should contain:
"""
WP_CLI_CS
"""
And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should contain:
"""
wpcli_foo
"""
And the {PACKAGE_PATH}/local/wp-cli/foo/composer.json file should exist
And the {PACKAGE_PATH}/local/wp-cli/foo/composer.json file should contain:
"""
Expand Down Expand Up @@ -127,6 +136,7 @@ Feature: Scaffold WP-CLI commands
"""
And the custom-directory/.gitignore file should exist
And the custom-directory/.editorconfig file should exist
And the custom-directory/phpcs.xml.dist file should exist
And the custom-directory/composer.json file should exist
And the custom-directory/hello-world-command.php file should exist
And the custom-directory/wp-cli.yml file should exist
Expand Down Expand Up @@ -157,6 +167,7 @@ Feature: Scaffold WP-CLI commands
s
s
s
s
"""

When I try `wp scaffold package wp-cli/same-package --skip-tests --skip-github`
Expand Down Expand Up @@ -195,6 +206,7 @@ Feature: Scaffold WP-CLI commands
"""
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.gitignore file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.editorconfig file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/phpcs.xml.dist file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/composer.json file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/hello-world-command.php file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/wp-cli.yml file should exist
Expand Down Expand Up @@ -260,5 +272,6 @@ Feature: Scaffold WP-CLI commands
Installing package
"""
And the {PACKAGE_PATH}/local/wp-cli/foo/.gitignore file should exist
And the {PACKAGE_PATH}/local/wp-cli/foo/phpcs.xml.dist file should exist
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/PULL_REQUEST_TEMPLATE file should not exist
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/ISSUE_TEMPLATE file should not exist
6 changes: 5 additions & 1 deletion src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ScaffoldPackageCommand {
* Default behavior is to create the following files:
* - command.php
* - composer.json (with package name, description, and license)
* - .gitignore, .editorconfig, and .distignore
* - .gitignore, .editorconfig, .distignore, and phpcs.xml.dist
* - README.md (via wp scaffold package-readme)
* - Test harness (via wp scaffold package-tests)
*
Expand Down Expand Up @@ -87,6 +87,9 @@ public function package( $args, $assoc_args ) {
WP_CLI::error( "'{$assoc_args['name']}' is an invalid package name. Package scaffold expects '<author>/<package>'." );
}

// Generate a slug from the package name for use in prefixes.
$assoc_args['package_name_slug'] = str_replace( '-', '_', $bits[1] );

if ( ! empty( $assoc_args['dir'] ) ) {
$package_dir = $assoc_args['dir'];
} else {
Expand Down Expand Up @@ -118,6 +121,7 @@ public function package( $args, $assoc_args ) {
"{$package_dir}/.gitignore" => file_get_contents( "{$package_root}/.gitignore" ),
"{$package_dir}/.editorconfig" => file_get_contents( "{$package_root}/.editorconfig" ),
"{$package_dir}/.distignore" => file_get_contents( "{$package_root}/.distignore" ),
"{$package_dir}/phpcs.xml.dist" => Utils\mustache_render( "{$template_path}/phpcs.xml.dist.mustache", $assoc_args ),
"{$package_dir}/CONTRIBUTING.md" => file_get_contents( "{$package_root}/CONTRIBUTING.md" ),
"{$package_dir}/wp-cli.yml" => $wp_cli_yml,
"{$package_dir}/hello-world-command.php" => Utils\mustache_render( "{$template_path}/hello-world-command.mustache", $assoc_args ),
Expand Down
54 changes: 54 additions & 0 deletions templates/phpcs.xml.dist.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<ruleset name="WP-CLI-{{package_name_slug}}">
<description>Custom ruleset for WP-CLI {{name}}</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
#############################################################################
-->

<!-- What to scan. -->
<file>.</file>

<!-- Show progress. -->
<arg value="p"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>

<!--
#############################################################################
USE THE WP_CLI_CS RULESET
#############################################################################
-->

<rule ref="WP_CLI_CS"/>

<!--
#############################################################################
PROJECT SPECIFIC CONFIGURATION FOR SNIFFS
#############################################################################
-->

<!-- For help understanding the `testVersion` configuration setting:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="7.2-"/>

<!-- Verify that everything in the global namespace is either namespaced or prefixed.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="WP_CLI"/><!-- Namespaces. -->
<element value="wpcli_{{package_name_slug}}"/><!-- Global variables and such. -->
</property>
</properties>
</rule>

</ruleset>