From 5844e0b5b5bf65740daa9260453b8b5db490e4b8 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Wed, 31 Aug 2022 12:51:56 -0400 Subject: [PATCH] [create-block] Split documentation into two sections (#43718) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update getPackageManifest to allow for packages to contain their own toc.json file. * Split documentation into two parts and create a toc.json file. * Regenerate manifest.json * Remove duplicate entry. * Always add the readme and then look for custom toc.json files. * Move extra docs into docs dir * Add link to main readme so it can be reference in npm. * Add link to video on learn.wordpress.org * Change headers/ * Move contributing back to the main README. * Use spread syntax with Array.push to avoid an unnecessary loop. * Update packages/create-block/docs/toc.json * Update docs/manifest.json Co-authored-by: Greg Ziółkowski --- docs/manifest.json | 6 + docs/tool/manifest.js | 18 ++- packages/create-block/README.md | 105 +----------------- .../create-block/docs/external-template.md | 103 +++++++++++++++++ packages/create-block/docs/toc.json | 8 ++ 5 files changed, 134 insertions(+), 106 deletions(-) create mode 100644 packages/create-block/docs/external-template.md create mode 100644 packages/create-block/docs/toc.json diff --git a/docs/manifest.json b/docs/manifest.json index 78a268132d0a7..ce1ddfe68753a 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -1469,6 +1469,12 @@ "markdown_source": "../packages/create-block/README.md", "parent": "packages" }, + { + "title": "@wordpress/create-block External Template", + "slug": "packages-create-block-external-template", + "markdown_source": "../packages/create-block/docs/external-template.md", + "parent": "packages-create-block" + }, { "title": "@wordpress/custom-templated-path-webpack-plugin", "slug": "packages-custom-templated-path-webpack-plugin", diff --git a/docs/tool/manifest.js b/docs/tool/manifest.js index 256ba292de476..344eaf3552170 100644 --- a/docs/tool/manifest.js +++ b/docs/tool/manifest.js @@ -31,15 +31,25 @@ const packagePaths = glob( 'packages/*/package.json' ) * @return {Array} Manifest */ function getPackageManifest( packageFolderNames ) { - return packageFolderNames.map( ( folderName ) => { + return packageFolderNames.reduce( ( manifest, folderName ) => { const path = `${ baseRepoUrl }/packages/${ folderName }/README.md`; - return { + const tocPath = `${ baseRepoUrl }/packages/${ folderName }/docs/toc.json`; + + // First add any README files to the TOC + manifest.push( { title: `@wordpress/${ folderName }`, slug: `packages-${ folderName }`, markdown_source: path, parent: 'packages', - }; - } ); + } ); + + // Next add any items in the docs/toc.json if found. + if ( fs.existsSync( join( __dirname, '..', tocPath ) ) ) { + const toc = require( join( __dirname, '..', tocPath ) ).values(); + manifest.push( ...toc ); + } + return manifest; + }, [] ); } /** diff --git a/packages/create-block/README.md b/packages/create-block/README.md index d622131b62038..36d0d632cc391 100644 --- a/packages/create-block/README.md +++ b/packages/create-block/README.md @@ -24,6 +24,8 @@ _(requires `node` version `14.0.0` or above, and `npm` version `6.14.4` or above It creates a WordPress plugin that you need to [install manually](https://wordpress.org/support/article/managing-plugins/#manual-plugin-installation). +[Watch a video introduction to create-block on Learn.wordpress.org](https://learn.wordpress.org/tutorial/using-the-create-block-tool/) + ## Usage The following command generates a project with PHP, JS, and CSS code for registering a block with a WordPress plugin. @@ -87,7 +89,6 @@ $ npx @wordpress/create-block --help 5. No plugin mode – it is also possible to scaffold only block files into the current directory. - ```bash $ npx @wordpress/create-block --no-plugin ``` @@ -144,107 +145,7 @@ _Note: You don’t need to install or configure tools like [webpack](https://web ## External Project Templates -Are you looking for a way to share your project configuration? Creating an external project template hosted on npm or located in a local directory is possible. These npm packages can provide custom `.mustache` files that replace default files included in the tool for the WordPress plugin or/and the block. It's also possible to override default configuration values used during the scaffolding process. - -### Project Template Configuration - -Providing the main file (`index.js` by default) for the package that returns a configuration object is mandatory. Several options allow customizing the scaffolding process. - -#### `pluginTemplatesPath` - -This optional field allows overriding file templates related to **the WordPress plugin shell**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates. - -_Example:_ - -```js -const { join } = require( 'path' ); - -module.exports = { - pluginTemplatesPath: join( __dirname, 'plugin-templates' ), -}; -``` - -#### `blockTemplatesPath` - -This optional field allows overriding file templates related to **the individual block**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates. - -_Example:_ - -```js -const { join } = require( 'path' ); - -module.exports = { - blockTemplatesPath: join( __dirname, 'block-templates' ), -}; -``` - -#### `assetsPath` - -This setting is useful when your template scaffolds a WordPress plugin that uses static assets like images or fonts, which should not be processed. It provides the path pointing to the location where assets are located. They will be copied to the `assets` subfolder in the generated plugin. - -_Example:_ - -```js -const { join } = require( 'path' ); - -module.exports = { - assetsPath: join( __dirname, 'plugin-assets' ), -}; -``` - -#### `defaultValues` - -It is possible to override the default template configuration using the `defaultValues` field. - -_Example:_ - -```js -module.exports = { - defaultValues: { - slug: 'my-fantastic-block', - title: 'My fantastic block', - dashicon: 'palmtree', - version: '1.2.3', - }, -}; -``` - -The following configurable variables are used with the template files. Template authors can change default values to use when users don't provide their data. - -**Project**: - -- `wpScripts` (default: `true`) – enables integration with the `@wordpress/scripts` package and adds common scripts to the `package.json`. -- `wpEnv` (default: `false`) – enables integration with the `@wordpress/env` package and adds the `env` script to the `package.json`. -- `customScripts` (default: {}) – the list of custom scripts to add to `package.json` . It also allows overriding default scripts. -- `npmDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. -- `npmDevDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install --save-dev`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. - -**Plugin header fields** ([learn more](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/)): - -- `pluginURI` (no default) – the home page of the plugin. -- `version` (default: `'0.1.0'`) – the current version number of the plugin. -- `author` (default: `'The WordPress Contributors'`) – the name of the plugin author(s). -- `license` (default: `'GPL-2.0-or-later'`) – the short name of the plugin’s license. -- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`) – a link to the full text of the license. -- `domainPath` (no default) – a custom domain path for the translations ([more info](https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#domain-path)). -- `updateURI:` (no default) – a custom update URI for the plugin ([related dev note](https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/)). - -**Block metadata** ([learn more](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/)): - -- `folderName` (default: `.`) – the location for the `block.json` file and other optional block files generated from block templates included in the folder set with the `blockTemplatesPath` setting. -- `$schema` (default: `https://schemas.wp.org/trunk/block.json`) – the schema URL used for block validation. -- `apiVersion` (default: `2`) – the block API version ([related dev note](https://make.wordpress.org/core/2020/11/18/block-api-version-2/)). -- `slug` (no default) – the block slug used for identification in the block name. -- `namespace` (default: `'create-block'`) – the internal namespace for the block name. -- `title` (no default) – a display title for your block. -- `description` (no default) – a short description for your block. -- `dashicon` (no default) – an icon property thats makes it easier to identify a block ([available values](https://developer.wordpress.org/resource/dashicons/)). -- `category` (default: `'widgets'`) – blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, `theme`, and `embed`. -- `attributes` (no default) – block attributes ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-attributes/)). -- `supports` (no default) – optional block extended support features ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-supports/). -- `editorScript` (default: `'file:./index.js'`) – an editor script definition. -- `editorStyle` (default: `'file:./index.css'`) – an editor style definition. -- `style` (default: `'file:./style-index.css'`) – a frontend and editor style definition. +[Click here](https://github.com/WordPress/gutenberg/tree/HEAD/packages/create-block/docs/external-template.md) for information on External Project Templates ## Contributing to this package diff --git a/packages/create-block/docs/external-template.md b/packages/create-block/docs/external-template.md new file mode 100644 index 0000000000000..cb06530ee165a --- /dev/null +++ b/packages/create-block/docs/external-template.md @@ -0,0 +1,103 @@ +# External Project Templates + +Are you looking for a way to share your project configuration? Creating an external project template hosted on npm or located in a local directory is possible. These npm packages can provide custom `.mustache` files that replace default files included in the tool for the WordPress plugin or/and the block. It's also possible to override default configuration values used during the scaffolding process. + +## Project Template Configuration + +Providing the main file (`index.js` by default) for the package that returns a configuration object is mandatory. Several options allow customizing the scaffolding process. + +### `pluginTemplatesPath` + +This optional field allows overriding file templates related to **the WordPress plugin shell**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates. + +_Example:_ + +```js +const { join } = require( 'path' ); + +module.exports = { + pluginTemplatesPath: join( __dirname, 'plugin-templates' ), +}; +``` + +### `blockTemplatesPath` + +This optional field allows overriding file templates related to **the individual block**. The path points to a location with template files ending with the `.mustache` extension (nested folders are also supported). When not set, the tool uses its own set of templates. + +_Example:_ + +```js +const { join } = require( 'path' ); + +module.exports = { + blockTemplatesPath: join( __dirname, 'block-templates' ), +}; +``` + +### `assetsPath` + +This setting is useful when your template scaffolds a WordPress plugin that uses static assets like images or fonts, which should not be processed. It provides the path pointing to the location where assets are located. They will be copied to the `assets` subfolder in the generated plugin. + +_Example:_ + +```js +const { join } = require( 'path' ); + +module.exports = { + assetsPath: join( __dirname, 'plugin-assets' ), +}; +``` + +### `defaultValues` + +It is possible to override the default template configuration using the `defaultValues` field. + +_Example:_ + +```js +module.exports = { + defaultValues: { + slug: 'my-fantastic-block', + title: 'My fantastic block', + dashicon: 'palmtree', + version: '1.2.3', + }, +}; +``` + +The following configurable variables are used with the template files. Template authors can change default values to use when users don't provide their data. + +**Project**: + +- `wpScripts` (default: `true`) – enables integration with the `@wordpress/scripts` package and adds common scripts to the `package.json`. +- `wpEnv` (default: `false`) – enables integration with the `@wordpress/env` package and adds the `env` script to the `package.json`. +- `customScripts` (default: {}) – the list of custom scripts to add to `package.json` . It also allows overriding default scripts. +- `npmDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. +- `npmDevDependencies` (default: `[]`) – the list of remote npm packages to be installed in the project with [`npm install --save-dev`](https://docs.npmjs.com/cli/v8/commands/npm-install) when `wpScripts` is enabled. + +**Plugin header fields** ([learn more](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/)): + +- `pluginURI` (no default) – the home page of the plugin. +- `version` (default: `'0.1.0'`) – the current version number of the plugin. +- `author` (default: `'The WordPress Contributors'`) – the name of the plugin author(s). +- `license` (default: `'GPL-2.0-or-later'`) – the short name of the plugin’s license. +- `licenseURI` (default: `'https://www.gnu.org/licenses/gpl-2.0.html'`) – a link to the full text of the license. +- `domainPath` (no default) – a custom domain path for the translations ([more info](https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#domain-path)). +- `updateURI:` (no default) – a custom update URI for the plugin ([related dev note](https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/)). + +**Block metadata** ([learn more](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/)): + +- `folderName` (default: `.`) – the location for the `block.json` file and other optional block files generated from block templates included in the folder set with the `blockTemplatesPath` setting. +- `$schema` (default: `https://schemas.wp.org/trunk/block.json`) – the schema URL used for block validation. +- `apiVersion` (default: `2`) – the block API version ([related dev note](https://make.wordpress.org/core/2020/11/18/block-api-version-2/)). +- `slug` (no default) – the block slug used for identification in the block name. +- `namespace` (default: `'create-block'`) – the internal namespace for the block name. +- `title` (no default) – a display title for your block. +- `description` (no default) – a short description for your block. +- `dashicon` (no default) – an icon property thats makes it easier to identify a block ([available values](https://developer.wordpress.org/resource/dashicons/)). +- `category` (default: `'widgets'`) – blocks are grouped into categories to help users browse and discover them. The categories provided by core are `text`, `media`, `design`, `widgets`, `theme`, and `embed`. +- `attributes` (no default) – block attributes ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-attributes/)). +- `supports` (no default) – optional block extended support features ([more details](https://developer.wordpress.org/block-editor/developers/block-api/block-supports/). +- `editorScript` (default: `'file:./index.js'`) – an editor script definition. +- `editorStyle` (default: `'file:./index.css'`) – an editor style definition. +- `style` (default: `'file:./style-index.css'`) – a frontend and editor style definition. diff --git a/packages/create-block/docs/toc.json b/packages/create-block/docs/toc.json new file mode 100644 index 0000000000000..ea5faab5ec63a --- /dev/null +++ b/packages/create-block/docs/toc.json @@ -0,0 +1,8 @@ +[ + { + "title": "@wordpress/create-block External Template", + "slug": "packages-create-block-external-template", + "markdown_source": "../packages/create-block/docs/external-template.md", + "parent": "packages-create-block" + } +]