cms icon indicating copy to clipboard operation
cms copied to clipboard

Allow starter kits to run console commands

Open ryanmitchell opened this issue 2 years ago • 10 comments

Opening this as a draft as you may want an entirely different approach.

This PR allows starter kits to specify an after_install_hook key which is a class name and method (\App\Hooks\MyHook::handle) which receives the console as an argument so further input can be requested.

As requested here: https://github.com/statamic/ideas/issues/863

ryanmitchell avatar Sep 21 '22 08:09 ryanmitchell

I don't really like this syntax \App\Hooks\MyHook::handle. I'd prefer it if it assumed handle and/or allowed it to be overwritten via property/method. The above syntax isn't really used in Laravel land.

edalzell avatar Sep 21 '22 16:09 edalzell

@edalzell what about using @ instead of ::?

ryanmitchell avatar Sep 21 '22 18:09 ryanmitchell

@edalzell what about using @ instead of ::?

Why not make it like middleware and have it assumed?

edalzell avatar Sep 21 '22 18:09 edalzell

@edalzell what about using @ instead of ::?

however, this is better, as at least it's like the old way of doing routing w/ controllers.

edalzell avatar Sep 21 '22 18:09 edalzell

Do we need the method? I kinda like assuming handle, like a middleware. But yeah the @ would be more inline with other class/method references.

jasonvarga avatar Sep 21 '22 18:09 jasonvarga

Ok. It seems handle is the consensus so I will change it to that!

ryanmitchell avatar Sep 21 '22 20:09 ryanmitchell

The weird thing about this is that you won't really want that file to exist once the starter kit is installed.

So you'd need it to be there for the initial composer require, then delete it? 🤔

jasonvarga avatar Sep 21 '22 20:09 jasonvarga

Yeah that’s a good point. We could delete it after running, or we could leave that to the starter kit author?

ryanmitchell avatar Sep 21 '22 20:09 ryanmitchell

Neat. I had actually been messing with this kind of thing on army own branch, though in the form of post-install PHP closures/callbacks (not commands) that would get run. They run from vendor, so there's be no need to delete anything after-the-fact. Would this work from your use case?

PS. I'll jump in more next week though, as I'm in cottage country right now 👍

jesseleite avatar Sep 22 '22 00:09 jesseleite

Yeah that could work for us. Interested to see how you have approached it.

ryanmitchell avatar Sep 22 '22 05:09 ryanmitchell

Just to finish off this approach - I've added a couple of lines to delete the after install hook file once its been run.

ryanmitchell avatar Sep 22 '22 06:09 ryanmitchell

I just tested this and it seems to work perfectly fine. Wonderful!

robdekort avatar Sep 26 '22 10:09 robdekort

@ryanmitchell Just gave it a whirl, awesome! 🤘 I dug up my old closure implementation, and wasn't happy with how I was registering closure-based hooks either. Hacked on it a bit more and combined the best of our ideas into https://github.com/statamic/cms/pull/6792. Curious on your thoughts? (Yours too @robdekort!)

jesseleite avatar Sep 26 '22 22:09 jesseleite