Repository navigation
Gutenpack: Break up the Jetpack preset's view bundle into separate, per-block ones. - #28066
Conversation
2c1e318 to
9a4abb0
Compare
| import 'gutenberg/extensions/markdown/editor'; | ||
| //import 'gutenberg/extensions/publicize/editor'; | ||
| import 'gutenberg/extensions/related-posts/editor'; | ||
| import 'gutenberg/extensions/tiled-gallery/editor'; |
There was a problem hiding this comment.
This preset file is imported in Calypso:
You might want to either keep it (and perhaps rename) or import each extension separately in client/gutenberg/editor/edit-post/editor.js.
| const presetBlocks = require( presetPath ); | ||
|
|
||
| // Helps split up each block into its own folder view script | ||
| viewBlocksPoints = reduce( presetBlocks, (obj, block) => ( { [ block + '/view'] : [path.join( inputDir, '../../'+ block +'/view.js' )] } ) ); |
There was a problem hiding this comment.
What is this reduce supposed to do? obj is never used, so the whole call will return the returned value for the last block?
Maybe you want this?
fromPairs( map(
blocks,
block => [ block + '/view', path.join( ..., block, 'view.js' ) ]
) );| @@ -0,0 +1 @@ | |||
| [ "markdown", "related-posts","tiled-gallery" ] | |||
There was a problem hiding this comment.
Remember to rebase, publicize extension is now enabled in Jetpack preset as well.
Nit; that missing space. :-)
| editorScripts = presetBlocks.map( block => path.join( inputDir, '../../'+ block +'/editor.js' ) ).filter( fs.existsSync ); | ||
| viewScripts = presetBlocks.map( block => path.join( inputDir, '../../'+ block +'/view.js' ) ).filter( fs.existsSync ); | ||
| // Combines all the different blocks into one Edit script | ||
| editorScript = utilScripts.concat( editorScripts ).concat( viewScripts ); |
There was a problem hiding this comment.
Note that view scripts in client/gutenberg/extensions/presets/jetpack/view.js depend on utils/public-path.js as well.
633d660 to
602d5f2
Compare
|
To provide a bit of rationale here (mostly discussed with @enejb and @lezama on a video call and screenshare): The goal here is to break up the Jetpack preset's To reach this goal, I suggested using separate webpack entry points for each block's `view. We're now tasked with producing the list of those files from a given preset configuration. We discussed that our current preset format -- Javascript files that simply We also observed that our current presets configuration is somewhat redundant -- both a preset's The solution that we came up with is what started this PR: Use a JSON file that only contains an array of block directory names. Iterate over this list to create both the list of view file entry points, and dynamically create an There are two tradeoffs AFAICS:
|
|
Noting that while the title mentions tiled gallery, the solution is built for all the blocks. The tiled gallery just happens to be the only one with view+editor side scripts and styles right now. |
tyxla
left a comment
There was a problem hiding this comment.
This seems to be testing well, nice work 💯
I've left some comments, mostly regarding code style - nothing major.
Also, I've noticed that I don't get any view scripts/styles in the root build directory - is that because tiled galleries is the only use case we have right now?
| 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 an array of the extensions folder names that you want to bundle together. |
There was a problem hiding this comment.
We seem to have written an array twice.
| if ( fs.existsSync( presetPath ) ) { | ||
| const presetBlocks = require( presetPath ); | ||
| // Find all the utils scripts | ||
| utilScripts = fs.readdirSync( utilsPath ).map( utilFile => path.join( utilsPath, utilFile ) ).filter( fs.existsSync ); |
There was a problem hiding this comment.
Note that in #28088 we introduced gutenberg/extensions/presets/jetpack/utils/i18n which is imported from each block separately, instead just once in the preset file. Remember to rebase this PR to see how it affects things.
Should we refactor utility-files by moving them to /shared and import them in each block that depends on them? That way it'll be easier to build each block separately with the SDK without relying on preset importing things such as jetpack category for us.
The purpose of the preset would thus be only to define combination of extensions; not new functionality per-se.
See also #27836 which adds /shared utility folder.
There was a problem hiding this comment.
Ohh funny, looks like I commented almost identical thing in resolved convo above this line 😆 https://github.com/Automattic/wp-calypso/pull/28066/files#r228319972 — sorry I missed that.
Introduction of utils/i18n changes the situation again quite a bit, though.
| } ); | ||
|
|
||
| editorScripts = presetBlocks.map( block => path.join( inputDir, '../../'+ block +'/editor.js' ) ).filter( fs.existsSync ); | ||
| viewScripts = presetBlocks.map( block => path.join( inputDir, '../../'+ block +'/view.js' ) ).filter( fs.existsSync ); |
There was a problem hiding this comment.
Note that utilScripts, editorScripts, viewScripts and editorScript seem to be missing const
|
Many of the styling issues seem to be coming from the fact that Line 3 in ba89961 You might want to run |
|
By running: I'm getting: While current Jetpack Heads up @oskosk that Jurassic Ninja might need |
simison
left a comment
There was a problem hiding this comment.
Building the o2 preset seems to be broken right now:
npm run sdk -- gutenberg client/gutenberg/extensions/presets/o2 --output-dir=~/testAs well as building individual blocks:
npm run sdk -- gutenberg client/gutenberg/extensions/tiled-gallery --output-dir=~/testBuilding via bin script seems to work well — to test, type npm link in Calypso folder and then from Jetpack folder run:
calypso-sdk gutenberg ~/wp-calypso/client/gutenberg/extensions/presets/jetpack --output-dir=./_inc/blocks
We are not combining all the files based on the index.json file.
ba89961 to
0fe6f77
Compare
Fixed the code so that it runs with all 3 commands as expected
|
@tyxla and @simison Since view.css and js files should just be included in the editor. (js and css) files. No need to load them separately. I also created a |
``` npx prettier --write \ bin/sdk/gutenberg.js \ docs/sdk.md \ client/gutenberg/extensions/presets/jetpack/utils/README.md ```
simison
left a comment
There was a problem hiding this comment.
I tested different ways to use the SDK (building all different presets, building a single block, building using the npm script and the bin command) and everything worked as expected.
Nice job driving this pretty big change through while keeping backwards compatibility! 👍
tyxla
left a comment
There was a problem hiding this comment.
Test well for me 👍 Left a couple of minor suggestions, other than that LGTM 🚢
Changes proposed in this Pull Request
Testing instructions
run the usual command that builds the bundle.
npm run sdk gutenberg client/gutenberg/extensions/presets/jetpack -- --output-dir="../jetpack/_inc/blocks"it should produce the following files.