diff --git a/packages/create-block/lib/init-block-json.js b/packages/create-block/lib/init-block-json.js new file mode 100644 index 00000000000000..87905ea55bc43c --- /dev/null +++ b/packages/create-block/lib/init-block-json.js @@ -0,0 +1,53 @@ +/** + * External dependencies + */ +const { isEmpty, omitBy } = require( 'lodash' ); +const { join } = require( 'path' ); +const { writeFile } = require( 'fs' ).promises; + +/** + * Internal dependencies + */ +const { info } = require( './log' ); + +module.exports = async ( { + slug, + namespace, + title, + description, + category, + dashicon, + textdomain, + editorScript, + editorStyle, + style, +} ) => { + const outputFile = join( process.cwd(), slug, 'block.json' ); + + info( '' ); + info( 'Creating a "block.json" file.' ); + await writeFile( + outputFile, + JSON.stringify( + omitBy( + { + name: namespace + '/' + slug, + title, + category, + icon: dashicon, + description, + textdomain, + supports: { + html: false, + }, + editorScript, + editorStyle, + style, + }, + isEmpty + ), + null, + '\t' + ) + ); +}; diff --git a/packages/create-block/lib/scaffold.js b/packages/create-block/lib/scaffold.js index b6bf18921edee7..70774b381354f1 100644 --- a/packages/create-block/lib/scaffold.js +++ b/packages/create-block/lib/scaffold.js @@ -10,6 +10,7 @@ const { dirname } = require( 'path' ); /** * Internal dependencies */ +const initBlockJSON = require( './init-block-json' ); const initPackageJSON = require( './init-package-json' ); const initWPScripts = require( './init-wp-scripts' ); const { code, info, success } = require( './log' ); @@ -28,6 +29,9 @@ module.exports = async ( licenseURI, version, wpScripts, + editorScript, + editorStyle, + style, } ) => { slug = slug.toLowerCase(); @@ -51,6 +55,9 @@ module.exports = async ( license, licenseURI, textdomain: namespace, + editorScript, + editorStyle, + style, }; await Promise.all( Object.keys( outputTemplates ).map( async ( outputFile ) => { @@ -67,6 +74,7 @@ module.exports = async ( } ) ); + await initBlockJSON( view ); await initPackageJSON( view ); if ( wpScripts ) { diff --git a/packages/create-block/lib/templates.js b/packages/create-block/lib/templates.js index 31cfc52c7028f8..b570ab73d1144f 100644 --- a/packages/create-block/lib/templates.js +++ b/packages/create-block/lib/templates.js @@ -20,6 +20,9 @@ const predefinedBlockTemplates = { description: 'Example block written with ES5 standard and no JSX – no build step required.', wpScripts: false, + editorScript: 'file:./index.js', + editorStyle: 'file:./editor.css', + style: 'file:./style.css', }, }, esnext: { @@ -79,6 +82,9 @@ const getDefaultValues = ( blockTemplate ) => { licenseURI: 'https://www.gnu.org/licenses/gpl-2.0.html', version: '0.1.0', wpScripts: true, + editorScript: 'file:./build/index.js', + editorStyle: 'file:./build/index.css', + style: 'file:./build/style-index.css', ...blockTemplate.defaultValues, }; };