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
19 changes: 14 additions & 5 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Feature: Scaffold a README.md file for an existing package
When I run `wp package path`
Then save STDOUT as {PACKAGE_PATH}

When I run `wp scaffold package wp-cli/default-readme`
When I try `wp scaffold package wp-cli/default-readme`
Then STDOUT should contain:
"""
Success: Created package readme.
Expand Down Expand Up @@ -66,7 +66,7 @@ Feature: Scaffold a README.md file for an existing package
When I run `wp package path`
Then save STDOUT as {PACKAGE_PATH}

When I run `wp scaffold package wp-cli/custom-branch`
When I try `wp scaffold package wp-cli/custom-branch`
Then STDOUT should contain:
"""
Success: Created package readme.
Expand All @@ -90,7 +90,7 @@ Feature: Scaffold a README.md file for an existing package
Scenario: Scaffold a README.md requiring a nightly build
Given an empty directory

When I run `wp scaffold package wp-cli/foo --dir=foo --require_wp_cli='>=0.24.0-alpha'`
When I try `wp scaffold package wp-cli/foo --dir=foo --require_wp_cli='>=0.24.0-alpha'`
Then STDOUT should contain:
"""
Success: Created package readme.
Expand All @@ -115,7 +115,7 @@ Feature: Scaffold a README.md file for an existing package
Scenario: Scaffold a README.md requiring the latest stable release
Given an empty directory

When I run `wp scaffold package wp-cli/foo --dir=foo --require_wp_cli='*'`
When I try `wp scaffold package wp-cli/foo --dir=foo --require_wp_cli='*'`
Then STDOUT should contain:
"""
Success: Created package readme.
Expand Down Expand Up @@ -294,7 +294,6 @@ Feature: Scaffold a README.md file for an existing package
*This README.md is generated dynamically from the project's codebase
"""

@broken
Scenario: Error when commands are specified but not present
Given an empty directory
And a foo/composer.json file:
Expand All @@ -318,6 +317,16 @@ Feature: Scaffold a README.md file for an existing package
"""
And the return code should be 1

Scenario: Does not error when commands are specified and present
Given an empty directory
When I try `wp scaffold package wp-cli/foo --dir=foo`
And I try `composer install -d foo`
And I try `wp scaffold package-readme foo`
Then STDERR should not contain:
"""
Error: Missing one or more commands defined in composer.json -> extra -> commands.
"""

Scenario: README for a bundled command
Given an empty directory
And a foo/composer.json file:
Expand Down
19 changes: 9 additions & 10 deletions src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,18 @@ public function package( $args, $assoc_args ) {
WP_CLI::runcommand( "scaffold package-tests {$package_dir} {$force_flag}", array( 'launch' => false ) );
}

if ( ! Utils\get_flag_value( $assoc_args, 'skip-readme' ) ) {
WP_CLI::runcommand( "scaffold package-readme {$package_dir} {$force_flag}", array( 'launch' => false ) );
}

if ( ! Utils\get_flag_value( $assoc_args, 'skip-github' ) ) {
WP_CLI::runcommand( "scaffold package-github {$package_dir} {$force_flag}", array( 'launch' => false ) );
}

if ( ! Utils\get_flag_value( $assoc_args, 'skip-install' ) ) {
Process::create( "composer install --working-dir {$package_dir}" )->run();
WP_CLI::runcommand( "package install {$package_dir}", array( 'launch' => false ) );
}

if ( ! Utils\get_flag_value( $assoc_args, 'skip-readme' ) ) {
WP_CLI::runcommand( "scaffold package-readme {$package_dir} {$force_flag}", array( 'launch' => false ) );
}
}

/**
Expand Down Expand Up @@ -309,9 +310,10 @@ public function package_readme( $args, $assoc_args ) {
$cmd_dump = WP_CLI::runcommand(
'cli cmd-dump',
[
'launch' => false,
'return' => true,
'parse' => 'json',
'launch' => false,
'return' => true,
'parse' => 'json',
'command_args' => [ "--path=$package_dir" ],
]
);
foreach ( $composer_obj['extra']['commands'] as $command ) {
Expand All @@ -332,12 +334,9 @@ public function package_readme( $args, $assoc_args ) {
}
} while ( $parent_command && $bits );

/* This check doesn't work because of the way the commands are fetched.
* Needs bigger refactor to put this check back in.
if ( empty( $parent_command ) ) {
WP_CLI::error( 'Missing one or more commands defined in composer.json -> extra -> commands.' );
}
*/

$longdesc = isset( $parent_command['longdesc'] ) ? $parent_command['longdesc'] : '';
$longdesc = (string) preg_replace( '/## GLOBAL PARAMETERS(.+)/s', '', $longdesc );
Expand Down
Loading