-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for @wordpress/scripts, block.json and create block #82
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
6cea812
add create-block templates for create-block script
stevenslack 5790ede
add create-block, scripts, and run update dependencies
stevenslack f617b72
add copy-webpack-plugin
stevenslack 8cc37a4
update dependencies
stevenslack b17784b
use @alleyinteractive/stylelint-config for stylelint configuration
stevenslack aed60e9
add blocks directory
stevenslack 2ba7a44
add tsconfig.json configuration file
stevenslack 6091461
update readme with dependency update info
stevenslack 9c13eab
add blocks directory to be removed in configure file
stevenslack 18260a2
move slotfills to entries
stevenslack 2e329dc
move src files to inc directory
stevenslack f8ababb
update entries directory to src
stevenslack f6a191e
update the composer file to reference the inc directory
stevenslack 32c5862
add jest configuration
stevenslack 96f3431
update eslint config for typescript, update editorconfig to include ts
stevenslack 8a7816b
remove unused assets
stevenslack b6baf2c
remove jest config in package.json remove babel config
stevenslack 36bb440
refine asset helper functions and examples
stevenslack 407ee8c
correct namespaces and package name in create block
stevenslack 7ae9d45
Merge branch 'feature/wp-scripts' into feature/wp-scripts-develop
stevenslack 26ded45
update dependencies, remove stylelint
stevenslack 1ebb1a6
move load_scripts to assets.php file
stevenslack 8f4657e
ensure css files are output in src directory
stevenslack d602ba6
Merge branch 'develop' into feature/wp-scripts
stevenslack ab50a03
fix jest to work with Typescript
stevenslack 5a3261c
phpcs fix
stevenslack 0f2c38f
allow linting and tests to pass without files
stevenslack 5d6f924
update configure file to remove correct files
stevenslack e486439
Small phpcs adjustment, heading block
srtfisher e59bf3c
move js entries from src back to entries, add render to block.json
stevenslack 0c3388d
Merge branch 'feature/wp-scripts-SRC' into feature/wp-scripts
stevenslack 8b2796c
add changes for render template in block json for wp 6.1
stevenslack b21373a
update block configuration for 6.1 scaffolding
stevenslack 98b25a8
use constant for glob includes
stevenslack 5c2d706
Merge branch 'develop' into feature/wp-scripts
stevenslack 7a0b6b0
revert src to entries for deleting front end assets
stevenslack 266ca6d
entry assets to src assets
stevenslack 6773eb0
correct path for phpcs exclusion, update comment
stevenslack 62c8bc9
replace instances of wp-starter-plugin strings
stevenslack 0478007
replace package_name with plugin slug
stevenslack 60271bf
remove ESLint disabling rule for props spreading
stevenslack 3acee62
update block directory README
stevenslack 354174a
update docs for including example CSS
stevenslack ead4540
update base README
stevenslack 9d9cd54
Merge branch 'develop' into feature/wp-scripts
stevenslack 9ff8d6f
Merge remote-tracking branch 'origin/develop' into feature/wp-scripts
srtfisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,3 @@ | ||
{ | ||
"extends": "stylelint-config-sass-guidelines", | ||
"rules": { | ||
"max-nesting-depth": [ | ||
3, | ||
{ | ||
"ignoreAtRules": [ | ||
"each", | ||
"media", | ||
"supports", | ||
"include" | ||
] | ||
} | ||
], | ||
"selector-class-pattern": [ | ||
"^[a-z0-9\\-_]+$", | ||
{ | ||
"message": | ||
"Selector should be written in lowercase with hyphens and/or underscores (selector-class-pattern)" | ||
} | ||
], | ||
"selector-no-qualifying-type": null | ||
} | ||
} | ||
"extends": "@alleyinteractive/stylelint-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This babel config is used by Jest to ensure that tests | ||
* will run correctly in Typescript and JavaScript files. | ||
* | ||
* Jest supports TypeScript, via Babel. | ||
* | ||
* @see https://jestjs.io/docs/getting-started#using-typescript | ||
*/ | ||
module.exports = { | ||
presets: [ | ||
'@babel/preset-env', | ||
'@wordpress/babel-preset-default', | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const path = require('path'); | ||
|
||
/** | ||
* Custom Variables and templates for scaffolding blocks. | ||
* @see https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/docs/external-template.md#external-project-templates | ||
*/ | ||
module.exports = { | ||
defaultValues: { | ||
namespace: 'create-wordpress-plugin', | ||
plugin: false, | ||
description: '', | ||
dashicon: 'palmtree', | ||
category: 'widgets', | ||
editorScript: 'file:index.js', | ||
editorStyle: 'file:index.css', | ||
style: ['file:style-index.css'], | ||
render: 'file:render.php', | ||
}, | ||
variants: { | ||
static: {}, | ||
dynamic: {}, | ||
}, | ||
blockTemplatesPath: path.join(__dirname, 'templates', 'block'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Retrieves the translation of text. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* Those files can contain any CSS code that gets applied to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './index.scss'; | ||
|
||
/** | ||
* The edit function describes the structure of your block in the context of the | ||
* editor. This represents what the editor will render when the block is used. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function Edit() { | ||
return ( | ||
<p {...useBlockProps()}> | ||
{ __('Block Title – hello from the editor!', 'create-wordpress-plugin') } | ||
</p> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Registers a new block provided a unique name and an object defining its behavior. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* All files containing `style` keyword are bundled together. The code used | ||
* gets applied both to the front of your site and to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './style.scss'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
{{#isStaticVariant}} | ||
import save from './save'; | ||
{{/isStaticVariant}} | ||
import metadata from './block.json'; | ||
{{#isAnotherVariant}} | ||
console.log('it worked'); | ||
{{/isAnotherVariant}} | ||
|
||
/** | ||
* Every block starts by registering a new block type definition. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
registerBlockType( | ||
metadata.name, | ||
{ | ||
edit, | ||
{{#isStaticVariant}} | ||
save, | ||
{{/isStaticVariant}} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* Block Name: {{title}}. | ||
* | ||
* @package create-wordpress-plugin | ||
*/ | ||
|
||
/** | ||
* Registers the block using the metadata loaded from the `block.json` file. | ||
* Behind the scenes, it registers also all assets so they can be enqueued | ||
* through the block editor in the corresponding context. | ||
* | ||
* @see https://developer.wordpress.org/reference/functions/register_block_type/ | ||
*/ | ||
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() { | ||
// Register the block by passing the location of block.json. | ||
register_block_type( | ||
__DIR__ | ||
); | ||
|
||
} | ||
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* The following styles get applied inside the editor only. | ||
* | ||
* All imported CSS files are bundled into one chunk named after the entry point, | ||
* which defaults to index.js, and thus the file created becomes index.css. | ||
* This is for styles used only in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
border: 1px dotted #f00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{#isDynamicVariant}} | ||
<?php | ||
/** | ||
* All of the parameters passed to the function where this file is being required are accessible in this scope: | ||
* | ||
* @param array $attributes The array of attributes for this block. | ||
* @param string $content Rendered block output. ie. <InnerBlocks.Content />. | ||
* @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. | ||
* | ||
* @package create-wordpress-plugin | ||
*/ | ||
|
||
?> | ||
<p <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>> | ||
<?php esc_html_e( '{{title}} – hello from a dynamic block!', 'create-wordpress-plugin' ); ?> | ||
</p> | ||
{{/isDynamicVariant}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{#isStaticVariant}} | ||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* The save function defines the way in which the different attributes should | ||
* be combined into the final markup, which is then serialized by the block | ||
* editor into `post_content`. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function save() { | ||
return ( | ||
<p { ...useBlockProps.save() }> | ||
{ '{{title}} – hello from the saved content!' } | ||
</p> | ||
); | ||
} | ||
{{/isStaticVariant}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* The following styles get applied both on the front of your site | ||
* and in the editor. | ||
* | ||
* Imported style.css file(s) (applies to SASS and SCSS extensions) | ||
* get bundled into one style-index.css file that is meant to be | ||
* used both on the front-end and in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#block-styles | ||
*/ | ||
|
||
.wp-block-{{namespace}}-{{slug}} { | ||
background-color: #21759b; | ||
color: #fff; | ||
padding: 2px; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should split out a ticket to make these
.tsx
files that are generated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue for this: #90