Skip to content
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

Feature proposal: new CLI command / argument to remove old generated _templ.go files #324

Closed
YiumPotato opened this issue Dec 12, 2023 · 3 comments

Comments

@YiumPotato
Copy link
Contributor

Context, I'm currently using Air for hot reload, and thus on file changes I make it run templ generate.

Say you create a .templ file (say, "foo.templ"), and eventually rename it (say "bar.templ"). foo_templ.go is still there.
Could lead to bugs or wasted time (specially for me since I was hiding all *_templ.go files in my ide)

Thus propose: templ generate --remove-old or a new templ remove-old to delete such old generated files would be nice. I suppose not by default to keep it backwards compatible.

If it sounds like a good idea lmk I could try make it and submit a PR.
[currently doing a weird unnessary regex rm hack deleting all _templ.go file in my templates before tmpl generate ls -d -1 "$PWD/internal/templates/"*.* | grep -P "^.*_templ\.go$" | xargs -d "\n" rm]

Love the project!

@a-h
Copy link
Owner

a-h commented Dec 12, 2023

Glad you like templ! I see your point, it's confusing to rename a file, and then have the old Go code stuck around.

I think it would be best to make removing _templ.go files that don't have a corresponding .templ file the default, and add a command line flag to not remove "orphaned" generated files. So, the CLI flag would be templ generate --keep-orphaned-files.

Probably best to wait until #299 is merged before starting, because it changes the generate command a little.

@YiumPotato
Copy link
Contributor Author

Done! #325

@a-h
Copy link
Owner

a-h commented Dec 17, 2023

Thanks, for that, great job. It's merged in 13b1f8a

@a-h a-h closed this as completed Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants