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: Allow templates to pass custom block.json keys #44626

Closed
colorful-tones opened this issue Sep 30, 2022 · 5 comments · Fixed by #44649
Closed

Create Block: Allow templates to pass custom block.json keys #44626

colorful-tones opened this issue Sep 30, 2022 · 5 comments · Fixed by #44649
Assignees
Labels
Developer Experience Ideas about improving block and theme developer experience Needs Dev Ready for, and needs developer efforts [Tool] Create Block /packages/create-block [Type] Enhancement A suggestion for improvement.

Comments

@colorful-tones
Copy link
Member

What problem does this address?

It is currently difficult to create a custom Create Block Template for ACF Pro 6.0, because ACF requires there to be a custom key in the block.json, e.g.

{
    "name": "acf-example-block",
    "title": "ACF Example Block",
    "description": "ACF example block",
    "apiVersion": 2,
    "acf": {
        "mode": "preview"
    }
}

What is your proposed solution?

Allow the default values passed through to have an optional custom key. I'm not sure the extent of the updates that would needed to be done for Create Block, but imagine the entry point would be somewhere around here: https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/templates.js#L44

Ultimately, I would love to be able to write a custom Create Block Template with something like this:

const { join } = require( "path" );

/**
 * @link https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/init-block.js#L14
 */
module.exports = {
	pluginTemplatesPath: join(__dirname, 'plugin-templates'),
	blockTemplatesPath: join( __dirname, 'block-templates' ),
	defaultValues: {
		namespace: 'acf-blocks-starter',
		version: '0.1.0',
		category: 'acf-blocks-starter',
		editorStyle: 'file:./index.css',
		editorScript: 'file:./index.js',
		style: 'file:./style-index.css'
	},
	variants: {
		static: {},
		dynamic: {
			_acf: {
				mode: 'preview'
			}
		}
	}
};

Note the _acf key. I'm prefixing because I'm not sure what type of nomenclature or nesting we would want to help Create Block Templates core parse through custom keys and objects and _ was the best I could come up with. I'm open to ideas and implementation.

Then a user could scaffold out a custom ACF block with a custom Create Block Template ACF package and run something like: npx @wordpress/create-block --template acf --variant dynamic --no-plugin --no-wp-scripts --category acf

@colorful-tones colorful-tones added [Tool] Create Block /packages/create-block Developer Experience Ideas about improving block and theme developer experience [Type] Enhancement A suggestion for improvement. labels Sep 30, 2022
@colorful-tones
Copy link
Member Author

Tagging @ryanwelcher @gziolo for consideration and visibility. 🙇

@colorful-tones colorful-tones self-assigned this Sep 30, 2022
@gziolo
Copy link
Member

gziolo commented Oct 1, 2022

Great idea, @colorful-tones!

It requires some planning how to pass those custom values to block.json in addition to all that is supported today in https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/init-block.js.

It might also be useful to add a similar capability for package.json file in https://github.com/WordPress/gutenberg/blob/trunk/packages/create-block/lib/init-package-json.js.

@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Oct 1, 2022
@ryanwelcher
Copy link
Contributor

I love this idea as well! It would allow this tool to support any keys that are added without needing to also create a PR for it ( see #44185 ). I'm going to take a crack at it today.

@colorful-tones
Copy link
Member Author

I'm more than happy to test anything @ryanwelcher

Thanks! 👍

@ryanwelcher
Copy link
Contributor

@colorful-tones I just pushed up #44649 if you have the time to test.

@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience Needs Dev Ready for, and needs developer efforts [Tool] Create Block /packages/create-block [Type] Enhancement A suggestion for improvement.
Projects
None yet
4 participants