diff --git a/features/scaffold-package-readme.feature b/features/scaffold-package-readme.feature index 4b64bab..0333909 100644 --- a/features/scaffold-package-readme.feature +++ b/features/scaffold-package-readme.feature @@ -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. @@ -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. @@ -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. @@ -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. @@ -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: @@ -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: diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 8f1f2a7..ca6f2d6 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -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 ) ); + } } /** @@ -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 ) { @@ -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 );