ahmadawais / create-guten-block

šŸ“¦ A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.
https://Awais.dev/cgb-post
MIT License
3.16k stars 327 forks source link

šŸ“¦ Create New Block Command #18

Open ahmadawais opened 6 years ago

ahmadawais commented 6 years ago

Let's talk a little about how and if we are going to add a command that creates a new block inside of a previously created #GutenBlock via create-guten-block.


image

WHY THE NEED?!

Now after working with this block for a while, you think, hey I think I need to create a new block inside this same single WordPress plugin. How do I do that?

OPTION # 1

And then you study or try to recreate a new block via looking at these steps

This as you can see is less than desireable

OPTION # 2

Well, that's what we are here to discuss.

āœ… IDEAL CASE In an ideal world, we should be able to do this:

šŸ¤” REAL WORLD PROBLEMS

The problems in implementing this approach are

So, that's where I am right now and would love any suggestions you have for me.

Before you go and suggest that we add this inside the create-guten-block CLI ā€” well, that's never going to happen. Why? Two reasons!

šŸ“£ Floor is open to your suggestions now!

zgordon commented 6 years ago

Okay! Very excited you are exploring this into you're already great work.

I haven't looked at how this would work specifically, but could we add one command in the initial package.json file like "add" that takes a single parameter of block-name and passes it executes code you identified.

It may also require a main index file that is automatically updated to import in the new block. If just one block was created then the index would only import that one block and there could be a comment not to edit this file since it is updated via the command prompt.

I'm happy to try to contribute to this, but let me know at a high level if you think that even makes sense or would be possible :)

Great work!!

ahmadawais commented 6 years ago

@zgordon Thank you! šŸŽ‰

šŸ”° Nice to have you here, and yes that makes sense. But I'd ask you to read the above content again since that's what I proposed, especially the content after OPTION # 2 where I explain how it can be done and what problems I am facing there.

āœ… TL;DR the command becomes quite big and complex whereas I want to keep this as easy as possible. It becomes something like this npm run create-block -- --name='my-new-block

Looking forward!

zgordon commented 6 years ago

Mmm, okay, good clarifications, thank you.

Okay, thought in a completely different direction that may be too complex, but what if there was a sort of index.html page generated with a very simple form interface to add a block so they don't see anything running on the backend?

That said, I am not sure how to resolve some of the path issues you outline, so copy, paste, edit may be the "easiest" approach?

I do like though having an index.js that imports individual blocks and then that being enqueued as a pattern that may be more scalable for multiple block plugins?

westonruter commented 6 years ago

What about WP-CLI's wp scaffold block? Shouldn't WP-CLI be part of the discussion here?

ahmadawais commented 6 years ago

@westonruter thanks for dropping by. šŸ™Œ

Honestly, I haven't had a chance to dig deeper in the code base of WP CLI, and it's already doing pretty great. This here is a JavaScript alternate if you will ā€” I strongly think that having it all based on JS puts it in a better position of getting more adoption in the JavaScript community to attract them to WordPress as compared to a PHP solution.

But I like the idea of building integration between these two tools. Not sure how that will pan out. You see, this is a complete opposite of what WP CLI stands for. At create-guten-block we're trying to follow Zero-Configuration setup. āœ…

The tradeoff is that these tools are preconfigured to work in a specific way. If your project needs more customization, you can "eject" and customize it, but then you will need to maintain this configuration. šŸ”°

Shelob9 commented 6 years ago

Just a note, I think it would be really cool if the create block command had a copy block option. Given command create-guten-block --clone=book-block --name=magazine-block a new block called "magazine-block" would be created that was a copy of existing block "book-block".

If I had a book block created already, and I was asked for a magazine block with similar features, I totally start by copypastaing my book block.

zgordon commented 6 years ago

I like this. Might be a good way to get around creating multiple blocks

covertnine commented 6 years ago

I'm getting an error when setting this up for the first time with the create-guten-block command that I can't get through. (Full disclosure I'm a little new to Node.js & NPM) We're using Node v8.9.4 and NPM v5.6.0. Just installed the create-gluten-block with no problem on a fresh linode server we use, and I'm getting some errors I'm not sure how to fix.

The error is related to a maxBuffer exceeded:

ā  2. Installing npm packages.../usr/lib/node_modules/create-guten-block/index.js:60 throw err; ^

Error: stderr maxBuffer exceeded at PassThrough.stream.on (/usr/lib/node_modules/create-guten-block/node_modules/get-stream/index.js:30:12) at emitOne (events.js:121:20) at PassThrough.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:246:13) at PassThrough.Readable.push (_stream_readable.js:208:10) at PassThrough.Transform.push (_stream_transform.js:147:32) at PassThrough.afterTransform (_stream_transform.js:88:10) at PassThrough._transform (_stream_passthrough.js:42:3) at PassThrough.Transform._read (_stream_transform.js:186:10)

Any ideas? Wasn't able to come up with much via google.

braginteractive commented 5 years ago

Love this project!

Just wanted to mention your link is broken to your multi-block example in your instructions above. Should be: https://github.com/ahmadawais/create-guten-block/tree/master/examples/03-multi-block

ahmadawais commented 5 years ago

@braginteractive thanks for the kind words and for letting me know. It's fixed now. šŸ‘ I have a working solution for this now, plan to open source it soon.

tsdexter commented 5 years ago

any updates on this?

ivandurst commented 4 years ago

Bump, is this fixed?

Julianoe commented 4 years ago

is this still in the works?