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

cmd chaining in -cmd flag or run scripts #1082

Open
kynrai opened this issue Feb 27, 2025 · 1 comment
Open

cmd chaining in -cmd flag or run scripts #1082

kynrai opened this issue Feb 27, 2025 · 1 comment

Comments

@kynrai
Copy link

kynrai commented Feb 27, 2025

Im looking for a way to chain commands with the templ generate proxy watch. Im considering altering https://github.com/a-h/templ/blob/main/cmd/templ/generatecmd/run/run_unix.go#L55 if it makes sense to do so, or maybe allow multiple commands to be specified,

Im ultimately just looking for a clean way to have templ run al the tools i need instead of relying on extra tools

Lets say I have a script in scripts/build.sh which runs something like tailwind and a bundler

something like the following as a makefile command should in theory work

templ generate -watch -proxy="http://localhost:8080" \
		-watch-pattern="(.+\\.go$$)|(.+\\.templ$$)|(.+_templ\\.txt$$)|(.+\\.css$$)|(.+\\.ts$$)" \
		-cmd="scripts/build.sh" -v

I will always get Error executing command [ error=fork/exec scripts/build.sh: no such file or directory ]

I could also try something like

templ generate -watch -proxy="http://localhost:8080" \
		-watch-pattern="(.+\\.go$$)|(.+\\.templ$$)|(.+_templ\\.txt$$)|(.+\\.css$$)|(.+\\.ts$$)" \
		-cmd="cmd1 && cmd2" -v

Or

templ generate -watch -proxy="http://localhost:8080" \
		-watch-pattern="(.+\\.go$$)|(.+\\.templ$$)|(.+_templ\\.txt$$)|(.+\\.css$$)|(.+\\.ts$$)" \
		-cmd="cmd1; cmd2;" -v

But i think this fails due to the way go executes commands,

possibly similar to this issue

https://stackoverflow.com/questions/34458625/run-multiple-exec-commands-in-the-same-shell-golang

even trying simple commands in the -cmd input causes odd outputs, like pwd; pwd; or pwd && pwd

@kynrai
Copy link
Author

kynrai commented Feb 27, 2025

side note, my original code, the commands are run in a Makefile hence the regex has $$ escapes

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

1 participant