Skip to content

Commit

Permalink
Jetpack Preset: Just have one file that has all the preset info (#29295)
Browse files Browse the repository at this point in the history
* Jetpack Preset: Just have one file that has all the preset info
instead of heaving multiple preset indexes lets just have a single index.json
  • Loading branch information
enejb authored and ockham committed Dec 11, 2018
1 parent b9aaa25 commit a6aa39e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
8 changes: 4 additions & 4 deletions bin/sdk/gutenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const fs = require( 'fs' );
const GenerateJsonFile = require( 'generate-json-file-webpack-plugin' );
const path = require( 'path' );
const { compact } = require( 'lodash' );
const { compact, get } = require( 'lodash' );

const DIRECTORY_DEPTH = '../../'; // Relative path of the extensions to preset directory

Expand All @@ -31,7 +31,6 @@ exports.config = ( { argv: { inputDir, outputDir }, getBaseConfig } ) => {
} );

const presetPath = path.join( inputDir, 'index.json' );
const presetBetaPath = path.join( inputDir, 'index-beta.json' ); // beta blocks live here

let editorScript;
let editorBetaScript;
Expand All @@ -41,8 +40,9 @@ exports.config = ( { argv: { inputDir, outputDir }, getBaseConfig } ) => {
let presetBetaBlocks;

if ( fs.existsSync( presetPath ) ) {
presetBlocks = require( presetPath );
presetBetaBlocks = fs.existsSync( presetBetaPath ) ? require( presetBetaPath ) : [];
const presetIndex = require( presetPath );
presetBlocks = get( presetIndex, [ 'production' ], [] );
presetBetaBlocks = get( presetIndex, [ 'beta' ], [] );
const allPresetBlocks = [ ...presetBlocks, ...presetBetaBlocks ];

// Find all the shared scripts
Expand Down
5 changes: 0 additions & 5 deletions client/gutenberg/extensions/presets/jetpack/index-beta.json

This file was deleted.

21 changes: 14 additions & 7 deletions client/gutenberg/extensions/presets/jetpack/index.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[
"contact-form",
"map",
"markdown",
"publicize",
"simple-payments"
]
{
"production": [
"contact-form",
"map",
"markdown",
"publicize",
"simple-payments"
],
"beta": [
"related-posts",
"tiled-gallery",
"vr"
]
}
19 changes: 17 additions & 2 deletions docs/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,24 @@ Presets are bundles of multiple extensions or blocks that live in a particular p
They can be found in `client/gutenberg/extensions/presets` directory.

To create a new preset, create a new folder in that directory and add an `index.json` file.
The file should be an array of the extensions folder names that you want to bundle together.
The file should be an object of arrays of the extensions folder names that you want to bundle together
for different environments.

```js
["markdown", "tiled-gallery"]
{
"production": [
"contact-form",
"map",
"markdown",
"publicize",
"simple-payments"
],
"beta": [
"related-posts",
"tiled-gallery",
"vr"
]
}
```

When you run the sdk command `npm run sdk -- gutenberg client/gutenberg/extensions/presets/your-new-preset`
Expand Down Expand Up @@ -105,6 +119,7 @@ Each built bundle is limited to a single bundle with no code-splitting.
If you find yourself needing more advanced functionality it's probably worth checking if a new module is warranted.

See usage instructions:

```bash
npm run sdk -- generic /path/to/entry-point.js /path/to/built-bundle.js
```
Expand Down

0 comments on commit a6aa39e

Please sign in to comment.