diff --git a/packages/create-block/CHANGELOG.md b/packages/create-block/CHANGELOG.md index ff9d8a371576f..2adea266a25d4 100644 --- a/packages/create-block/CHANGELOG.md +++ b/packages/create-block/CHANGELOG.md @@ -1,5 +1,15 @@ ## Master +### New Features + +- Added readme.txt file to the existing templates to make your entry in the plugin browser most useful ([#20694](https://github.com/WordPress/gutenberg/pull/20694)). +- Added prompts for the `author`, `license` and `version` of the plugin ([#20694](https://github.com/WordPress/gutenberg/pull/20694)). + +### Bug Fixes + +- Make `version` prompt mandatory and provide validation against semantic versioning ([#20756](https://github.com/WordPress/gutenberg/pull/20756)). +- Omit optional values in the scaffolded files when they aren't provided ([#20756](https://github.com/WordPress/gutenberg/pull/20756)). + ## 0.8.3 (2020-02-26) ### Bug Fixes diff --git a/packages/create-block/lib/init-wp-scripts.js b/packages/create-block/lib/init-wp-scripts.js index 77acd4b90cd66..5ac01ea1733b0 100644 --- a/packages/create-block/lib/init-wp-scripts.js +++ b/packages/create-block/lib/init-wp-scripts.js @@ -2,6 +2,7 @@ * External dependencies */ const { command } = require( 'execa' ); +const { isEmpty, omitBy } = require( 'lodash' ); const { join } = require( 'path' ); const writePkg = require( 'write-pkg' ); @@ -21,22 +22,28 @@ module.exports = async function( { info( '' ); info( 'Creating a "package.json" file.' ); - await writePkg( cwd, { - name: slug, - version, - description, - author, - license, - main: 'build/index.js', - scripts: { - build: 'wp-scripts build', - 'format:js': 'wp-scripts format-js', - 'lint:css': 'wp-scripts lint-style', - 'lint:js': 'wp-scripts lint-js', - start: 'wp-scripts start', - 'packages-update': 'wp-scripts packages-update', - }, - } ); + await writePkg( + cwd, + omitBy( + { + name: slug, + version, + description, + author, + license, + main: 'build/index.js', + scripts: { + build: 'wp-scripts build', + 'format:js': 'wp-scripts format-js', + 'lint:css': 'wp-scripts lint-style', + 'lint:js': 'wp-scripts lint-js', + start: 'wp-scripts start', + 'packages-update': 'wp-scripts packages-update', + }, + }, + isEmpty + ) + ); info( '' ); info( 'Installing packages. It might take a couple of minutes.' ); diff --git a/packages/create-block/lib/prompts.js b/packages/create-block/lib/prompts.js index e891331dbc20b..5624f984f8292 100644 --- a/packages/create-block/lib/prompts.js +++ b/packages/create-block/lib/prompts.js @@ -1,7 +1,7 @@ /** * External dependencies */ -const { upperFirst } = require( 'lodash' ); +const { isEmpty, upperFirst } = require( 'lodash' ); const slug = { type: 'input', @@ -55,7 +55,7 @@ const dashicon = { message: 'The dashicon to make it easier to identify your block (optional):', validate( input ) { - if ( ! /^[a-z][a-z0-9\-]*$/.test( input ) ) { + if ( ! isEmpty( input ) && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) { return 'Invalid dashicon name specified. Visit https://developer.wordpress.org/resource/dashicons/ to discover available names.'; } @@ -77,25 +77,34 @@ const author = { type: 'input', name: 'author', message: - 'The list of contributors containing only WordPress.org usernames (optional):', + 'The name of the plugin author (optional). Multiple authors may be listed using commas:', }; const license = { type: 'input', name: 'license', - message: 'The plugin license (optional):', + message: 'The short name of the plugin’s license (optional):', }; const licenseURI = { type: 'input', name: 'licenseURI', - message: 'The plugin license URI (optional):', + message: 'A link to the full text of the license (optional):', }; const version = { type: 'input', name: 'version', - message: 'The plugin version (optional):', + message: 'The current version number of the plugin:', + validate( input ) { + // Regular expression was copied from https://semver.org. + const validSemVerPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; + if ( ! validSemVerPattern.test( input ) ) { + return 'Invalid Semantic Version provided. Visit https://regex101.com/r/vkijKf/1/ to discover all valid patterns.'; + } + + return true; + }, }; module.exports = { diff --git a/packages/create-block/lib/templates/es5/$slug.php.mustache b/packages/create-block/lib/templates/es5/$slug.php.mustache index 4a9a0c6bceaa6..b46e0b8e9ec04 100644 --- a/packages/create-block/lib/templates/es5/$slug.php.mustache +++ b/packages/create-block/lib/templates/es5/$slug.php.mustache @@ -1,10 +1,19 @@