Skip to content

Commit 9b8096f

Browse files
authored
Merge pull request #159 from alleyinteractive/typescript
Switching to using Typescript by default
2 parents fd360da + 4de472b commit 9b8096f

File tree

19 files changed

+194
-10
lines changed

19 files changed

+194
-10
lines changed

bin/create-block/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ module.exports = {
1111
description: '',
1212
dashicon: 'palmtree',
1313
category: 'widgets',
14-
editorScript: 'file:index.js',
14+
editorScript: 'file:index.ts',
1515
editorStyle: 'file:index.css',
1616
style: ['file:style-index.css'],
17-
render: 'file:render.php',
1817
},
1918
variants: {
2019
static: {},
21-
dynamic: {},
20+
'static-javascript': {
21+
blockTemplatesPath: path.join(__dirname, 'templates', 'block', 'javascript'),
22+
},
23+
dynamic: {
24+
render: 'file:render.php',
25+
},
26+
'dynamic-javascript': {
27+
blockTemplatesPath: path.join(__dirname, 'templates', 'block', 'javascript'),
28+
render: 'file:render.php',
29+
},
2230
},
23-
blockTemplatesPath: path.join(__dirname, 'templates', 'block'),
31+
blockTemplatesPath: path.join(__dirname, 'templates', 'block', 'typescript'),
2432
};

bin/create-block/templates/block/edit.jsx.mustache renamed to bin/create-block/templates/block/javascript/edit.jsx.mustache

File renamed without changes.

bin/create-block/templates/block/index.js.mustache renamed to bin/create-block/templates/block/javascript/index.js.mustache

File renamed without changes.

bin/create-block/templates/block/index.php.mustache renamed to bin/create-block/templates/block/javascript/index.php.mustache

File renamed without changes.

bin/create-block/templates/block/index.scss.mustache renamed to bin/create-block/templates/block/javascript/index.scss.mustache

File renamed without changes.

bin/create-block/templates/block/render.php.mustache renamed to bin/create-block/templates/block/javascript/render.php.mustache

File renamed without changes.

bin/create-block/templates/block/save.jsx.mustache renamed to bin/create-block/templates/block/javascript/save.jsx.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { useBlockProps } from '@wordpress/block-editor';
1818
*/
1919
export default function save() {
2020
return (
21-
<p { ...useBlockProps.save() }>
22-
{ '{{title}} – hello from the saved content!' }
21+
<p {...useBlockProps.save()}>
22+
{'{{title}} – hello from the saved content!'}
2323
</p>
2424
);
2525
}

bin/create-block/templates/block/style.scss.mustache renamed to bin/create-block/templates/block/javascript/style.scss.mustache

File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Retrieves the translation of text.
3+
*
4+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
5+
*/
6+
import { __ } from '@wordpress/i18n';
7+
8+
/**
9+
* React hook that is used to mark the block wrapper element.
10+
* It provides all the necessary props like the class name.
11+
*
12+
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
13+
*/
14+
import { useBlockProps } from '@wordpress/block-editor';
15+
16+
/**
17+
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
18+
* Those files can contain any CSS code that gets applied to the editor.
19+
*
20+
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
21+
*/
22+
import './index.scss';
23+
24+
/**
25+
* The edit function describes the structure of your block in the context of the
26+
* editor. This represents what the editor will render when the block is used.
27+
*
28+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
29+
*
30+
* @return {WPElement} Element to render.
31+
*/
32+
export default function Edit() {
33+
return (
34+
<p {...useBlockProps()}>
35+
{ __('Block Title – hello from the editor!', 'create-wordpress-plugin') }
36+
</p>
37+
);
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Block Name: {{title}}.
4+
*
5+
* @package create-wordpress-plugin
6+
*/
7+
8+
/**
9+
* Registers the block using the metadata loaded from the `block.json` file.
10+
* Behind the scenes, it registers also all assets so they can be enqueued
11+
* through the block editor in the corresponding context.
12+
*
13+
* @see https://developer.wordpress.org/reference/functions/register_block_type/
14+
*/
15+
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
16+
// Register the block by passing the location of block.json.
17+
register_block_type(
18+
__DIR__
19+
);
20+
21+
}
22+
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );

0 commit comments

Comments
 (0)