Skip to content

Commit

Permalink
Update the 01-basic-esnext block to use block.json (#149)
Browse files Browse the repository at this point in the history
* Update @wordpress/scripts

* Update 01-basic-esnext to use block.json

* Add .nvmrc file.

* Add .editorconfig file.

* Add dependencies and package-json.lock

* Add common eslintrc file.

* Remove js map files

* Ignore dev js mapping files.

* Update main package.json to use latest version of the @wordpress/scripts package.

* Split out files and linting fixes.

* Inline comments to explain the loading process.

* Add build files.

* Add manual linting to avoid error with prettier not being found.

* Remove linting from ci due error with prettier not being found. See WordPress/gutenberg#21872

* Remove npm test command in CI

* Add node 14 to versions in CI
  • Loading branch information
ryanwelcher authored Sep 24, 2021
1 parent 49892fe commit 710e5ad
Show file tree
Hide file tree
Showing 16 changed files with 23,368 additions and 7,371 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ]
}
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v1
Expand All @@ -20,8 +20,8 @@ jobs:
- name: npm install, build, and test
run: |
npm ci
npm run lint:js
# npm run lint:js
npm run lint:pkg-json
npm test
# npm test
env:
CI: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Directories/files that may be generated by this project
node_modules
index.js.map

# Directories/files that may appear in your environment
.DS_Store
*.log
/yarn.lock
/yarn.lock
.vscode
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
10 changes: 10 additions & 0 deletions 01-basic-esnext/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiVersion": 2,
"name": "gutenberg-examples/example-01-basic-esnext",
"title":"Example: Basic (ESNext)",
"textdomain": "gutenberg-examples",
"icon": "universal-access-alt",
"category": "layout",
"example": {},
"editorScript": "file:./build/index.js"
}
2 changes: 1 addition & 1 deletion 01-basic-esnext/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-blocks', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => 'a35cc1c098b69994c9c6d6dc1416bb90');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => 'd03b1c932e40e0ab9ea5054ddeec54c2');
2 changes: 1 addition & 1 deletion 01-basic-esnext/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 11 additions & 22 deletions 01-basic-esnext/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,17 @@ function gutenberg_examples_01_esnext_load_textdomain() {
*/
function gutenberg_examples_01_esnext_register_block() {

// automatically load dependencies and version
$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php');

wp_register_script(
'gutenberg-examples-01-esnext',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);

register_block_type( 'gutenberg-examples/example-01-basic-esnext', array(
'editor_script' => 'gutenberg-examples-01-esnext',
) );

if ( function_exists( 'wp_set_script_translations' ) ) {
/**
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain',
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
*/
wp_set_script_translations( 'gutenberg-examples-01-esnext', 'gutenberg-examples' );
}
// Register the block by passing the location of block.json to register_block_type.
register_block_type( __DIR__);

if ( function_exists( 'wp_set_script_translations' ) ) {
/**
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain',
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
*/
wp_set_script_translations( 'gutenberg-examples-01-esnext', 'gutenberg-examples' );
}

}
add_action( 'init', 'gutenberg_examples_01_esnext_register_block' );
Loading

0 comments on commit 710e5ad

Please sign in to comment.