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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/create-block/lib/init-block-json.js
Original file line number Diff line number Diff line change
@@ -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,
gziolo marked this conversation as resolved.
Show resolved Hide resolved
style,
},
isEmpty
),
null,
'\t'
)
);
};
8 changes: 8 additions & 0 deletions packages/create-block/lib/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -28,6 +29,9 @@ module.exports = async (
licenseURI,
version,
wpScripts,
editorScript,
editorStyle,
style,
}
) => {
slug = slug.toLowerCase();
Expand All @@ -51,6 +55,9 @@ module.exports = async (
license,
licenseURI,
textdomain: namespace,
editorScript,
editorStyle,
style,
};
await Promise.all(
Object.keys( outputTemplates ).map( async ( outputFile ) => {
Expand All @@ -67,6 +74,7 @@ module.exports = async (
} )
);

await initBlockJSON( view );
await initPackageJSON( view );

if ( wpScripts ) {
Expand Down
6 changes: 6 additions & 0 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
};
};
Expand Down