Skip to content
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

Create Block: Generate a block.json file #23399

Merged
merged 5 commits into from
Jun 25, 2020

Conversation

coreymckrill
Copy link
Contributor

Description

#22151 suggests auto-generating the block.json file as a way to help block creators be set up for success in getting their blocks added to the block directory.

This adds block.json auto-generation to the create-block script during the scaffolding process. The file is pre-populated with the inputs/defaults from the script. The editorScript/editorStyle properties vary depending on which template is chosen (esnext or es5).

How has this been tested?

Tested with a local checkout of Gutenberg, running node path/to/create-block. Tested with both esnext and es5 values for the template parameter.

Types of changes

  • New feature: auto-generated block.json file

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Writes a block.json file pre-populated with the input parameters from
the script. The `editorScript`/`editorStyle` properties vary depending
on which template is chosen (esnext or es5).
@gziolo gziolo added [Package] Create Block /packages/create-block [Type] Enhancement A suggestion for improvement. labels Jun 23, 2020
@gziolo
Copy link
Member

gziolo commented Jun 23, 2020

Nice one, I'll have a look later this week 👍

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I proposed that we explicitly set values for scripts and styles in the template config. What do you think? Everything else looks good. Thanks for taking care of it.

packages/create-block/lib/init-block-json.js Outdated Show resolved Hide resolved
packages/create-block/lib/init-block-json.js Show resolved Hide resolved
@coreymckrill coreymckrill requested a review from gziolo June 24, 2020 19:19
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to use the syntax similar to what npm uses for local packages:

file:./path/relative/to/block-json/file

I guess we could skip ./ if that helps. Let me know what you think. I will test it with register_block_type_from_metadata helper and merge it tomorrow.

In fact, we could do feature detection in ESNext template and use register_block_type_from_metadata when it's defined. I can open PR proposing that tomorrow.

packages/create-block/lib/templates.js Outdated Show resolved Hide resolved
packages/create-block/lib/templates.js Outdated Show resolved Hide resolved
coreymckrill and others added 2 commits June 24, 2020 15:01
Co-authored-by: Greg Ziółkowski <[email protected]>
Co-authored-by: Greg Ziółkowski <[email protected]>
@coreymckrill
Copy link
Contributor Author

I guess we could skip ./ if that helps.

I don't think it matters much either way, as long as the required syntax is well documented.

@gziolo gziolo merged commit 74771e6 into WordPress:master Jun 25, 2020
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 25, 2020
@github-actions github-actions bot added this to the Gutenberg 8.5 milestone Jun 25, 2020
gziolo added a commit that referenced this pull request Jun 25, 2020
* Create Block: Generate a block.json file

Writes a block.json file pre-populated with the input parameters from
the script. The `editorScript`/`editorStyle` properties vary depending
on which template is chosen (esnext or es5).

* Move script/style values to template config

* Auto-fixed whitespace

* Use npm syntax for file paths

Co-authored-by: Greg Ziółkowski <[email protected]>

* Use npm syntax for file paths

Co-authored-by: Greg Ziółkowski <[email protected]>

Co-authored-by: Greg Ziółkowski <[email protected]>
@gziolo gziolo mentioned this pull request Jun 25, 2020
3 tasks
@mkaz
Copy link
Member

mkaz commented Jul 1, 2020

Should we update the index.js to import the fields from the block.json file?

Right now things like name, title, description, etc.. are duplicated in the two locations.

@gziolo
Copy link
Member

gziolo commented Jul 2, 2020

@mkaz, there are two issues that need to be resolved first:

  • JSON imports work only in Node.js or with webpack. In Gutenberg we use a custom plugin that inlines JSON in JavaScript as a plain object. We would need to add the same plugin to the shared Babel preset.
  • we miss the logic that wraps translatable fields with i18n functions, it still needs to be added.

In the past, I tried to build a Babel macro that would address both points but it wasn’t as straightforward as you would expect. We were afraid it could be a point of bugs when not configured properly. Related PR: #16088.

@gziolo
Copy link
Member

gziolo commented Jul 2, 2020

I opened an issue that tracks i18n support for block.json in #23636.

@mkaz
Copy link
Member

mkaz commented Jul 2, 2020

@gziolo Thanks for the update, I've added info to the Create a Block tutorial with a note for the block.json part.

Can you review here: https://github.com/WordPress/gutenberg/pull/23654/files#diff-c52b6bb71644b3ce80dd15e4a3e42ac4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Create Block /packages/create-block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants