Skip to content

Commit 88a2177

Browse files
Produce a correct path to the template based on installation type
1 parent a6a9e39 commit 88a2177

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Scaffold_Command.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function _s( $args, $assoc_args ) {
306306

307307
if ( true === $unzip_result ) {
308308
$this->create_files( array(
309-
"$theme_path/{$theme_slug}/.editorconfig" => file_get_contents( WP_CLI_ROOT . "/templates/.editorconfig" ),
309+
"$theme_path/{$theme_slug}/.editorconfig" => file_get_contents( self::get_template_path( "templates/.editorconfig" ) ),
310310
), false );
311311
WP_CLI::success( "Created theme '{$data['theme_name']}'." );
312312
} else {
@@ -395,7 +395,7 @@ function child_theme( $args, $assoc_args ) {
395395
$files_written = $this->create_files( array(
396396
$theme_style_path => self::mustache_render( 'child_theme.mustache', $data ),
397397
$theme_functions_path => self::mustache_render( 'child_theme_functions.mustache', $data ),
398-
"$theme_dir/.editorconfig" => file_get_contents( WP_CLI_ROOT . "/templates/.editorconfig" ),
398+
"$theme_dir/.editorconfig" => file_get_contents( self::get_template_path( "/templates/.editorconfig" ) ),
399399
), $force );
400400
$this->log_whether_files_written(
401401
$files_written,
@@ -553,7 +553,7 @@ function plugin( $args, $assoc_args ) {
553553
"$plugin_dir/Gruntfile.js" => self::mustache_render( 'plugin-gruntfile.mustache', $data ),
554554
"$plugin_dir/.gitignore" => self::mustache_render( 'plugin-gitignore.mustache', $data ),
555555
"$plugin_dir/.distignore" => self::mustache_render( 'plugin-distignore.mustache', $data ),
556-
"$plugin_dir/.editorconfig" => file_get_contents( WP_CLI_ROOT . "/templates/.editorconfig" ),
556+
"$plugin_dir/.editorconfig" => file_get_contents( self::get_template_path( "/templates/.editorconfig" ) ),
557557
), $force );
558558

559559
$this->log_whether_files_written(
@@ -773,7 +773,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
773773
}
774774
$files_written[] = $file_name;
775775

776-
$wp_filesystem->copy( WP_CLI_ROOT . "/templates/$file", $file_name, true );
776+
$wp_filesystem->copy( self::get_template_path( "/templates/$file" ), $file_name, true );
777777
if ( 'install-wp-tests.sh' === $file ) {
778778
if ( ! $wp_filesystem->chmod( "$dir/$file", 0755 ) ) {
779779
WP_CLI::warning( "Couldn't mark 'install-wp-tests.sh' as executable." );
@@ -991,4 +991,19 @@ private static function mustache_render( $template, $data = array() ) {
991991
return Utils\mustache_render( dirname( dirname( __FILE__ ) ) . '/templates/' . $template, $data );
992992
}
993993

994+
/**
995+
* Get template path based on installation type
996+
*/
997+
private static function get_template_path( $template ) {
998+
$template_path = WP_CLI_ROOT . '/vendor/wp-cli/scaffold-command/templates/' . $template;
999+
if ( ! file_exists( $template_path ) ) {
1000+
// scaffold command must've been built with vendor/wp-cli/wp-cli
1001+
$template_path = WP_CLI_ROOT . '/../../../templates/' . $template;
1002+
if ( ! file_exists( $template_path ) ) {
1003+
WP_CLI::error( "Couldn't find {$template}" );
1004+
}
1005+
}
1006+
return $template_path;
1007+
}
1008+
9941009
}

0 commit comments

Comments
 (0)