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] Adding a --no-plugin flag to scaffold only block files. #41642

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6438856
Add npmDevDependencies as a template variable. Update messaging to sh…
ryanwelcher Mar 24, 2022
6f24eb8
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Mar 25, 2022
0b691cc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 4, 2022
c847911
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 9, 2022
b0b836e
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 22, 2022
cdb77bc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher May 19, 2022
8a59dff
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher May 24, 2022
505db7d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 1, 2022
85af639
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher Jun 1, 2022
a6ecbe4
Adding --block-only to available flags.
ryanwelcher Jun 2, 2022
c69e955
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 8, 2022
a635340
Adding --block-only to available flags
ryanwelcher Jun 8, 2022
3fed29f
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Jun 9, 2022
567a22c
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 9, 2022
16c3242
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Jun 9, 2022
0f2a9d6
Remove extra dependeny loop.
ryanwelcher Jun 14, 2022
c3de411
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 14, 2022
304eee6
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Jun 14, 2022
1b753f3
Apply suggestions from code review
gziolo Jun 15, 2022
9d61058
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 22, 2022
ffc4a63
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 23, 2022
ce4613d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 28, 2022
614bb81
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 29, 2022
7d39306
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher Jun 29, 2022
5b079b5
Remove extra code block added in error.
ryanwelcher Jun 29, 2022
c809657
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 30, 2022
7f680ab
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jul 22, 2022
a729ae0
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Aug 8, 2022
330eae8
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Aug 8, 2022
5d27273
Add correct messaging based on existence of --block-only flag.
ryanwelcher Aug 8, 2022
342443c
Scaffold the block in the directory where the command is run.
ryanwelcher Aug 8, 2022
3d75b55
Add changelog and readme entries for the new flag.
ryanwelcher Aug 8, 2022
ecab102
Change the flag to --no-plugin and adjust internal logic accordingly.
ryanwelcher Aug 9, 2022
e7d24cc
Abstract messaging out.
ryanwelcher Aug 9, 2022
286f9df
Add new customize message for blocks
ryanwelcher Aug 9, 2022
30be383
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Aug 10, 2022
8afb712
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Aug 10, 2022
85ab74f
Use lodash get instead of optional chaining as Node 12 doesn't suppor…
ryanwelcher Aug 10, 2022
cf7c12e
Update packages/create-block/CHANGELOG.md
ryanwelcher Aug 11, 2022
d87849c
Remove the messaging helper
ryanwelcher Aug 11, 2022
08488a0
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Aug 11, 2022
f006e4e
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Aug 11, 2022
3613d68
Remove negation logic in order to more clear.
ryanwelcher Aug 11, 2022
58cfb3a
Adding process.cwd() back as per code review.
ryanwelcher Aug 11, 2022
702362f
Check to ensure that a template supports the blockTemplatesPath prope…
ryanwelcher Aug 11, 2022
462af8a
Revert adding process.cwd() back.
ryanwelcher Aug 11, 2022
0fadb61
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher Aug 12, 2022
0b05ac4
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Aug 12, 2022
004e24a
Merge branch 'trunk' into try/add-per-block-scaffolding-create-block
ryanwelcher Aug 12, 2022
9781f6f
Adds example to README.
ryanwelcher Aug 12, 2022
a64917a
Make the slug prompt for universal
ryanwelcher Aug 15, 2022
bd0a91c
Merge branch 'try/add-per-block-scaffolding-create-block' of github.c…
ryanwelcher Aug 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/create-block/lib/index.js
Expand Up @@ -57,10 +57,12 @@ program
'disable integration with `@wordpress/scripts` package'
)
.option( '--wp-env', 'enable integration with `@wordpress/env` package' )
.option( '--block-only', 'scaffold only block files' )
.action(
async (
slug,
{
blockOnly,
category,
namespace,
shortDescription: description,
Expand All @@ -76,6 +78,7 @@ program
const defaultValues = getDefaultValues( pluginTemplate );
const optionsValues = pickBy(
{
blockOnly,
category,
description,
namespace,
Expand Down
25 changes: 15 additions & 10 deletions packages/create-block/lib/init-block.js
Expand Up @@ -15,6 +15,7 @@ const { writeOutputTemplate } = require( './output' );
async function initBlockJSON( {
$schema,
apiVersion,
blockOnly,
slug,
namespace,
title,
Expand All @@ -33,7 +34,9 @@ async function initBlockJSON( {
info( '' );
info( 'Creating a "block.json" file.' );

const outputFile = join( process.cwd(), slug, folderName, 'block.json' );
const outputFile = blockOnly
? join( process.cwd(), folderName, slug, 'block.json' )
: join( process.cwd(), slug, folderName, 'block.json' );
await makeDir( dirname( outputFile ) );
await writeFile(
outputFile,
Expand Down Expand Up @@ -65,15 +68,17 @@ async function initBlockJSON( {

module.exports = async function ( outputTemplates, view ) {
await Promise.all(
Object.keys( outputTemplates ).map(
async ( outputFile ) =>
await writeOutputTemplate(
outputTemplates[ outputFile ],
join( view.folderName, outputFile ),
view
)
)
);
Object.keys( outputTemplates ).map( async ( outputFile ) => {
const pathName = view.blockOnly
? join( process.cwd(), view.folderName, view.slug, outputFile )
gziolo marked this conversation as resolved.
Show resolved Hide resolved
: join( view.folderName, outputFile );
gziolo marked this conversation as resolved.
Show resolved Hide resolved

await writeOutputTemplate(
outputTemplates[ outputFile ],
pathName,
view
);
} )
);
await initBlockJSON( view );
};
8 changes: 3 additions & 5 deletions packages/create-block/lib/output.js
Expand Up @@ -13,11 +13,9 @@ const writeOutputAsset = async ( inputFile, outputFile, view ) => {
};

const writeOutputTemplate = async ( inputFile, outputFile, view ) => {
// Output files can have names that depend on the slug provided.
const outputFilePath = join(
view.slug,
outputFile.replace( /\$slug/g, view.slug )
);
const outputFilePath = view.blockOnly
gziolo marked this conversation as resolved.
Show resolved Hide resolved
? outputFile
: join( view.slug, outputFile.replace( /\$slug/g, view.slug ) );
await makeDir( dirname( outputFilePath ) );
writeFile( outputFilePath, render( inputFile, view ) );
};
Expand Down
47 changes: 27 additions & 20 deletions packages/create-block/lib/scaffold.js
Expand Up @@ -18,6 +18,7 @@ module.exports = async (
{
$schema,
apiVersion,
blockOnly,
namespace,
slug,
title,
Expand Down Expand Up @@ -53,6 +54,7 @@ module.exports = async (
const view = {
$schema,
apiVersion,
blockOnly,
namespace,
namespaceSnakeCase: snakeCase( namespace ),
slug,
Expand Down Expand Up @@ -83,16 +85,19 @@ module.exports = async (
style,
};

await Promise.all(
Object.keys( pluginOutputTemplates ).map(
async ( outputFile ) =>
await writeOutputTemplate(
pluginOutputTemplates[ outputFile ],
outputFile,
view
)
)
);
if ( ! blockOnly ) {
// If blockOnly exists, we don't need to scaffold the plugin files.
await Promise.all(
Object.keys( pluginOutputTemplates ).map(
async ( outputFile ) =>
await writeOutputTemplate(
pluginOutputTemplates[ outputFile ],
outputFile,
view
)
)
);
}

await Promise.all(
Object.keys( outputAssets ).map(
Expand All @@ -107,21 +112,23 @@ module.exports = async (

await initBlock( blockOutputTemplates, view );

await initPackageJSON( view );
if ( ! blockOnly ) {
await initPackageJSON( view );
if ( wpScripts ) {
await initWPScripts( view );
}

if ( wpScripts ) {
await initWPScripts( view );
}

if ( wpEnv ) {
await initWPEnv( view );
if ( wpEnv ) {
await initWPEnv( view );
}
}

info( '' );
success(
`Done: WordPress plugin "${ title }" bootstrapped in the "${ slug }" directory.`
);
if ( wpScripts ) {

if ( ! blockOnly && wpScripts ) {
info( '' );
info( 'You can run several commands inside:' );
info( '' );
Expand Down Expand Up @@ -150,13 +157,13 @@ module.exports = async (
info( 'To enter the directory type:' );
info( '' );
code( ` $ cd ${ slug }` );
if ( wpScripts ) {
if ( ! blockOnly && wpScripts ) {
info( '' );
info( 'You can start development with:' );
info( '' );
code( ' $ npm start' );
}
if ( wpEnv ) {
if ( ! blockOnly && wpEnv ) {
info( '' );
info( 'You can start WordPress with:' );
info( '' );
Expand Down