-
Notifications
You must be signed in to change notification settings - Fork 4k
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] Adds --target-dir flag to allow the tool to target where to scaffold. #53781
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: 0 B Total Size: 1.51 MB ℹ️ View Unchanged
|
@@ -59,6 +59,7 @@ program | |||
.option( '--wp-env', 'enable integration with `@wordpress/env` package' ) | |||
.option( '--no-plugin', 'scaffold only block files' ) | |||
.option( '--variant <variant>', 'the variant of the template to use' ) | |||
.option( '--target-dir <directory>', 'the variant of the template to use' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this description still needs to be updated.
I just tested this and noticed that if you combine it with the Running
but instead it just puts it in the root. I'm not sure the best choice is but I'd lean towards the first one. |
? join( process.cwd(), slug, folderName, 'block.json' ) | ||
: join( process.cwd(), slug, 'block.json' ); | ||
? join( process.cwd(), targetDir, slug, folderName, 'block.json' ) | ||
: join( process.cwd(), folderName, slug, 'block.json' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #53781 (comment):
I just tested this and noticed that if you combine it with the --no-plugin argument, it seems to ignore the --target-dir argument.
It looks like targetDir
should be used here as well.
Thank you for testing @bacoords!
We could replicate
When using Aside: I'm wondering how much we could read from the plugin when scaffolding another block. It could be useful to read the |
True, although sometimes blocks are created in themes as well. I was hoping that once this was merged it would be easy to include a script like this in any project's package.json file: "create-block": "npx @wordpress/create-block --namespace=my-namespace --no-plugin --target-dir=src/blocks" so that in the future you could run something like this from your project's root directory:
or
and it would generate it for you. So you could put the namespace and target-dir in your package.json. |
@ryanwelcher @gziolo and @bacoords thanks for pushing this forward! I feel like I'm missing something here. This PR aims to address this issue: Allow explicit target for block creation. However, after utilizing the Testing Instructions I've merely created two plugins with blocks, and both versions of the plugin have the block stored in the usual |
@colorful-tones Correct - currently this PR just lets you initiate the entire plugin in a different directory. Imagine you're in the root of your WP install, you could pass But I think it becomes more useful if we could combine it with Happy to contribute/test here as needed. |
This is all great feedback. I need to look at this PR again to resolve the conflicts but now I think the target should absolutely work in either mode. |
What?
This PR adds the
--target-dir
flag to allow users to target where the tool should scaffold either the entire plugin or the block files. This flag is not used when the tool is in--no-plugin
modeCloses #44717
Why?
Being able to target where to scaffold the files is something that has been missing from the tool. By adding this flag extenders would be able to incorporate create-block into their scaffolds/workflow much easer.
For example, many projects use
wp-content
as the root directory and keep a package.json there. Currently, anyone wanting to use the create-block tool, would need to move theplugins
directory and run it there. With this change, a script could be created to run the tool in place.Script
Invoke
Another change here is now when running the tool in
--no-plugin
mode, the resulting files are scaffolded into a sub-directory of thefolderName
property (./src
by default ) so now when adding a new block to an existing plugin the user no longer needs to move the thefolderName
directory.How?
I am introducing a
targetDir
variable with the default value of./
and prepending all of the paths with its value.Testing Instructions
cd
into `packages/create-block'node index.js test-no-target
src
directorynode index.js test-with-target --target-dir target-directory
target-directory
folder with the block files in asrc
directory