-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Custom Generators #3384
Custom Generators #3384
Conversation
This is awesome! Just a random thought: I was wondering if we can also pass custom variable for these templates? For example, template has ${customPrefix} in use, and then somehow pass variable via CLI |
I love this idea and will attempt to add it! I'm hoping yargs has some kind of "glob" syntax that just scoops up all other variables and provides them...we've only ever used it with named/positional arguments where you have to know all the variable names ahead of time... |
Hey @cannikin not reviewed this properly, but for me the custom templates shouldn't be in src. I think it would be nice to have this structure
|
Hmm, I'm no expert on Javascript directory conventions, but I thought everything that isn't specifically a user-interface for My App should go in a I don't love the folder name just being |
Folder name totally fine with whatever you pick - but I just don't think it should be src, which houses run time code only (typically). |
Okay cool, I'll move then! BRB |
@dac09 Moved! Updated the first comment to reflect new location. |
Looping in @dthyresson @cannikin Nice work on this! Would be great to demo at the next Core Team — I'll add it to the agenda. And TBD as needed. |
I do wanna do this, but I'd like to get this out first and have a followup PR for custom variables. It's gonna take a little more work than I anticipated and don't want to hold this one up! |
Totally! Maybe we can get more feedback from the community before adding the feature. In any case, let me know if I can be of any help. :) |
We're going to move this to a |
Okay we gotta hurry and merge this before CI breaks again. :) |
I thought I'm fine either way. Just sanity check. |
Last thing I heard was @mojombo liked Confirmed from Tom: |
At long last you can customize your generators! This PR adds a new command, the
awesomely named Generator generatorgenerator setup command:Running that generator will create a
lib/generators
directory in eitherweb
orapi
depending on which side the generator applies to. It then copies the template files for that generator into the directory.For example, the above command would create:
Then when the actual generator is run it will look in that location first and if a template is present, use it. Otherwise it'll fall back to the one built into Redwood.
The list of generators you can customize:
Limitations
For all of the generators except scaffold, you can overwrite as many or as few of the templates as you want. You might override the page component file, but not care about stories or tests. You can delete those custom templates in your app directory and be good to go.
But, because of way files are looked up for the Scaffold generator, if you want to customize any of the pages/cells/components, you'll need to have every scaffold template in a single template subdirectory (
assets
,components
,layouts
,pages
) present in your custom directory.Single subdirectory? That means if you want to customize any of the pages generated with a scaffold, you need all of them present in
web/src/lib/generators/scaffold/pages
. You can delete the other directories (assets
,components
,layouts
) if you want, but if you want to customize any single file in one of those dirs you'll need all the templates within.I'm guessing this probably isn't an issue as people that want to customize will probably want to update the UI across all of the scaffold, but we should definitely note it in the release notes/docs (or spend more time changing how the scaffold looks up template files so that it behaves like the others).
Closes #914