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 request: Run once, then exit #118

Open
icopp opened this issue Mar 16, 2021 · 5 comments
Open

Feature request: Run once, then exit #118

icopp opened this issue Mar 16, 2021 · 5 comments

Comments

@icopp
Copy link

icopp commented Mar 16, 2021

onchange is very close to being usable as a general-purpose file runner across glob matches in a way I haven't seen with other npm tools.

Here's a quick example of the kind of thing I'm looking at, using https://github.com/drwpow/openapi-typescript to use a schema at docs/whatever.yml to generate src/generated/whatever.ts:

  "dev:openapi": "onchange -a 'docs/*.yml' -- openapi-typescript {{file}} --prettier-config . -o src/generated/{{fileBaseNoExt}}.ts",

If there was a flag to only run that once (without actually watching for further changes), I could use the same functionality in build steps without needing to break out any other script stuff.

@blakeembrey
Copy link
Collaborator

This sounds interesting, could be done. We might be able to use this with chokidar by closing the watcher on ready, otherwise we could make a PR to chokidar or use a different library with the same underlying glob support. I think the flag is only useful in combination with -a in this case, does that sound correct?

@icopp
Copy link
Author

icopp commented Mar 17, 2021

For this I'd think a new self-contained flag, maybe -r for 'run' or something.

@Qard
Copy link
Owner

Qard commented Mar 18, 2021

I'd prefer something a little more obvious like --once, but other than that I like the idea. :)

@forivall
Copy link
Contributor

Yeah, i was just thinking about this feature too -- luckily --outpipe solved the need i had for it.

onchange -v -o 'dot -Tpng | imgcat' *.dot -- cat '{{file}}' (where `cat '{{file}}' is actually a different command that generates graphviz, but nbd)

The alternative solution using once would be

while changed=$(onchange --once *.dot) ; do < dot -Tpng | imgcat ; done

@blakeembrey
Copy link
Collaborator

@forivall Can you help me understand your example a little more? It sounds like a different request from the while loop but maybe I don’t understand. Also not clear to me how outpipe helped you exit on ready, which is what @icopp was trying to do - basically run a command with each file as a glob instead of a file watcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants