-
Notifications
You must be signed in to change notification settings - Fork 994
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
Generators: add ability to destroy generated files #80
Comments
I'd be interested in trying to implement this. At a high level would the work be
Does that seem more or less correct? |
@desa thanks for joining in! Yes that sounds right to me! |
Got a question about the anticipated behavior. If I run |
@thedavidprice yup, super interested in helping. |
@desa I always base my generator behavior decisions on what Rails does. I believe the destroyers just use the list of files that the generator creates and attempts to remove each one. So if you created something with the page generator, then ran the scaffold destroyer, it would remove any files that had the same file name as what the scaffold generator would have created, even if they weren't created with the scaffold generator. Also we have no way of knowing if the scaffold generator created them or the user just happened to create them with the same name, so it would be futile to try and stop them from getting deleted (unless we did a diff between the file's current contents and the content the generator would have created... 🤯) I'm all about providing sharp knives rather than creating additional code to try and anticipate everything a user could possibly do wrong and prevent it from happening. The common use case in the Rails world for using a destroyer is that you just created something and then realize you had a typo in the name, or your model wasn't quite defined right in the schema and you want to undo and redo the generated code so it picks up the change. |
One request: But to @cannikin's point and use case above, if this is primarily to be used as an immediate cleanup for a mistake, then that message feels a bit redundant. Probably not annoyingly so, though. |
Can I help with finishing this up? I've quickly prototyped |
@antonmoiseev That would be amazing |
This is done! 🎉 |
In Rails there is a
destroy
command that acts as the evil twin ofgenerate
:Let's do the same thing in Redwood. The generators themselves just return a list of files/routes so we should be able to use those lists in a
destroy
process to remove the files created and match and remove the routes.The text was updated successfully, but these errors were encountered: