scaffold-command
scaffold-command copied to clipboard
Add --github flag to scaffold plugin from a repository
Issue
Currently when using wp scaffold plugin
you are limited to the provided plugin architecture. This is not ideal where you might have your own architecture you would like to use. In most cases this can be solved with other scripts, but it takes you outside of the convenience of wp-cli
.
Proposal
Add a new --github
flag which will allow wp scaffold plugin
to checkout a source that will be used for scaffolding.
Example usage:
# Checkout default branch and use for scaffolding.
wp scaffold plugin --github=myorg/mypluginbase
# Checkout alternate branch to use for scaffolding.
wp scaffold plugin --github=myorg/mypluginbase:alternate-branch
Considerations
-
exec()
vs PHP git library - Replacement patterns for source files (and the methods to do the replacing)
- Alternate method to determine successful checkout and replacement than
log_whether_files_written
I would love to have something like that available!
I think that the use cases for scaffolding have by now outgrown the way this is technically handled, and it needs an overhaul to open it up to more flexible usage.
Refactoring the scaffolding system (in a backward compatible fashion, of course) would be a good overarching target for v2.1. I'll open a new umbrella issue in that regard.
@schlessera do you already have an architecture in mind for a refactored scaffolding system?
Not yet, I haven't spent much time on it, given I'm focusing on the package restructuring for v2.
However, here are some basic goals I'd like to achieve:
- OOP-based main architecture.
- Decouple template source & processing and provide extensible interfaces for both.
- Provide set of default template sources as available objects (Git repo, folder, ZIP file, ...)
- Provide set of default processing mechanisms as available objects (placeholder replacement with Mustache or similar, code generation through PHP-Parser, ...)
- Allow for custom integrations to be added through WP-CLI config files, so that a project can simply add its folder of templates, for example.
I'd like this to be closer to the project-based generation tools like Laravel's artisan
, where you can define custom templates for types of objects for your project once and then have an easy method to add new implementations with one command.