Skip to content

Commit 1d815f3

Browse files
authored
Merge pull request #142 from salcode/sf/block-index-js-138
Modify scaffold block to create index.js
2 parents 3666c1f + 58a8b98 commit 1d815f3

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

features/scaffold-block.feature

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Feature: WordPress block code scaffolding
4040
"""
4141
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
4242
"""
43-
$block_js = 'the-green-mile/block.js';
43+
index_js = 'the-green-mile/index.js';
4444
"""
4545
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
4646
"""
@@ -58,24 +58,24 @@ Feature: WordPress block code scaffolding
5858
"""
5959
add_action( 'init', 'the_green_mile_block_init' );
6060
"""
61-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should exist
62-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
61+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should exist
62+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
6363
"""
6464
registerBlockType( 'movies/the-green-mile', {
6565
"""
66-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
66+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
6767
"""
6868
title: __( 'The green mile' ),
6969
"""
70-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
70+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
7171
"""
7272
category: 'widgets',
7373
"""
74-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
74+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
7575
"""
7676
__( 'Hello from the editor!' )
7777
"""
78-
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
78+
And the {PLUGIN_DIR}/blocks/the-green-mile/index.js file should contain:
7979
"""
8080
__( 'Hello from the saved content!' )
8181
"""
@@ -96,7 +96,7 @@ Feature: WordPress block code scaffolding
9696

9797
Scenario: Scaffold a block with a specific title provided
9898
When I run `wp scaffold block shawshank-redemption --plugin=movies --title="The Shawshank Redemption"`
99-
Then the {PLUGIN_DIR}/blocks/shawshank-redemption/block.js file should contain:
99+
Then the {PLUGIN_DIR}/blocks/shawshank-redemption/index.js file should contain:
100100
"""
101101
title: __( 'The Shawshank Redemption' ),
102102
"""
@@ -107,7 +107,7 @@ Feature: WordPress block code scaffolding
107107

108108
Scenario: Scaffold a block with a specific dashicon provided
109109
When I run `wp scaffold block forrest-gump --plugin=movies --dashicon=movie`
110-
Then the {PLUGIN_DIR}/blocks/forrest-gump/block.js file should contain:
110+
Then the {PLUGIN_DIR}/blocks/forrest-gump/index.js file should contain:
111111
"""
112112
icon: 'movie',
113113
"""
@@ -118,7 +118,7 @@ Feature: WordPress block code scaffolding
118118

119119
Scenario: Scaffold a block with a specific category provided
120120
When I run `wp scaffold block pulp-fiction --plugin=movies --category=embed`
121-
Then the {PLUGIN_DIR}/blocks/pulp-fiction/block.js file should contain:
121+
Then the {PLUGIN_DIR}/blocks/pulp-fiction/index.js file should contain:
122122
"""
123123
category: 'embed',
124124
"""
@@ -130,7 +130,7 @@ Feature: WordPress block code scaffolding
130130
Scenario: Scaffold a block for an active theme
131131
When I run `wp scaffold block fight-club --theme`
132132
Then the {THEME_DIR}/blocks/fight-club.php file should exist
133-
And the {THEME_DIR}/blocks/fight-club/block.js file should exist
133+
And the {THEME_DIR}/blocks/fight-club/index.js file should exist
134134
And the {THEME_DIR}/blocks/fight-club/editor.css file should exist
135135
And the {THEME_DIR}/blocks/fight-club/style.css file should exist
136136
And STDOUT should be:
@@ -148,7 +148,7 @@ Feature: WordPress block code scaffolding
148148
Scenario: Scaffold a block for a specific theme
149149
When I run `wp scaffold block intouchables --theme=p2`
150150
Then the {THEME_DIR}/blocks/intouchables.php file should exist
151-
And the {THEME_DIR}/blocks/intouchables/block.js file should exist
151+
And the {THEME_DIR}/blocks/intouchables/index.js file should exist
152152
And the {THEME_DIR}/blocks/intouchables/editor.css file should exist
153153
And the {THEME_DIR}/blocks/intouchables/style.css file should exist
154154
And STDOUT should be:

src/Scaffold_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function block( $args, $assoc_args ) {
300300

301301
$files_written = $this->create_files( array(
302302
"$block_dir/$slug.php" => self::mustache_render( 'block-php.mustache', $data ),
303-
"$block_dir/$slug/block.js" => self::mustache_render( 'block-block-js.mustache', $data ),
303+
"$block_dir/$slug/index.js" => self::mustache_render( 'block-index-js.mustache', $data ),
304304
"$block_dir/$slug/editor.css" => self::mustache_render( 'block-editor-css.mustache', $data ),
305305
"$block_dir/$slug/style.css" => self::mustache_render( 'block-style-css.mustache', $data ),
306306
), $control_args['force'] );
File renamed without changes.

templates/block-php.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ function {{machine_name}}_block_init() {
2020
$dir = get_template_directory() . '/blocks';
2121
{{/theme}}
2222

23-
$block_js = '{{slug}}/block.js';
23+
$index_js = '{{slug}}/index.js';
2424
wp_register_script(
2525
'{{slug}}-block-editor',
2626
{{#plugin}}
27-
plugins_url( $block_js, __FILE__ ),
27+
plugins_url( $index_js, __FILE__ ),
2828
{{/plugin}}
2929
{{#theme}}
30-
get_template_directory_uri() . "/blocks/$block_js",
30+
get_template_directory_uri() . "/blocks/$index_js,
3131
{{/theme}}
3232
array(
3333
'wp-blocks',
3434
'wp-i18n',
3535
'wp-element',
3636
),
37-
filemtime( "$dir/$block_js" )
37+
filemtime( "$dir/$index_js" )
3838
);
3939

4040
$editor_css = '{{slug}}/editor.css';

0 commit comments

Comments
 (0)