Closed svoop closed 2 months ago
Thanks for writing this up @svoop. A solution is going to be tricky, because there's a timing problem I hadn't foreseen with the new initializer system. Thor needs to have its available command set registered before it can process the CLI arguments, but the exact point at which a site's initializers are loaded comes after a particular command gets run like build
or start
. Somehow there will need to be a way to register commands earlier in the boot process. Hmm…
Upon further thought, there's a workaround which I think if we document is OK for now. I've been thinking about building a more intuitive system of adding new commands anyway (which would be an improvement over using Rake tasks for commands for site builders), so that's probably something to tackle as a unified feature.
The workaround is to add a config/boot.rb
:
Bundler.setup(:default, Bridgetown.env)
require "some_gem_here" # adds a command to Thor
I'll document this for the 1.2 release so folks aren't left hanging.
Let me know if this makes sense @svoop
@jaredcwhite Yep, makes perfect sense and works! I'll mention it in the README of the bridgetown_credentials
gem I'm working on. Maybe there's a better solution some day, but I guess there are bigger fish to fry at the moment. Thanks a lot for this workaround and Merry Christmas to you!
In a gemified plugin, I've declared Thor-like (as shown in the guides) in
lib/mygem/commands/doit.rb
and require the file inlib/mygem.rb
. For tying, I've pathed in the gem into a Bridgetown site, installed the bundle. I'd expectbridgetown
to include these commands, but it doesn't. Maybe something has to be added to the initializer block? I couldn't find another plugin with commands, but it certainly feels as if some reference is missing... or something broken.(Transferred from Discord to this issue as per your request.)
Update: Just tried it as a not-gemified, in-site plugin, same problem.
As a side note: The guides are not very clear as how to declare the commands. In
.rb
and require them in the rootmygem.rb
entry point? Or not require them but make them.thor
files?Bridgetown Version: 1.2.0.beta4
To Reproduce
Current behavior Commands from plugins are not listed with
bridgetown
orbt
, nor are they executable withbt NAMESPACE COMMAND
.Computing environment (please complete the following information):
Thanks for your help... and your great work with Brigetown!