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

Add command line interface #284

Closed
wants to merge 2 commits into from
Closed

Add command line interface #284

wants to merge 2 commits into from

Conversation

kimmobrunfeldt
Copy link

Add cli too named watch. Argument parsing done with yargs. Adds a few dependencies.

➜  watch --help
Usage: watch <command> <pattern> [options]

<command>:
Command to be executed when a change is detected.
Needs to be surrounded with quotes when command contains spaces

<pattern>:
Glob pattern to specify files to be watched.
Needs to be surrounded with quotes to prevent shell globbing.
Guide to globs: https://github.com/isaacs/node-glob#glob-primer

Options:
  -d, --debounce          Debounce timeout in ms for executing command
                                                                  [default: 400]
  -s, --follow-symlinks   When not set, only the symlinks themselves will be
                          watched for changes instead of following the link
                          references and bubbling events through the links path
                                                     [boolean]  [default: false]
  -i, --ignore            Pattern for files which should be ignored. Needs to
                          be surrounded with quotes to prevent shell globbing.
                          The whole relative or absolute path is tested, not
                          just filename
  -p, --polling           Whether to use fs.watchFile(backed by polling)
                          instead of fs.watch. This might lead to high CPU
                          utilization. It is typically necessary to set this to
                          true to successfully watch files over a network, and
                          it may be necessary to successfully watch files in
                          other non-standard situations
                                                     [boolean]  [default: false]
  --poll-interval         Interval of file system polling. Effective when
                          --polling is set                        [default: 100]
  --poll-interval-binary  Interval of file system polling for binary files.
                          Effective when --polling is set         [default: 300]
  -h, --help              Show help
  -v, --version           Show version number

Examples:
  watch "npm run build-js" "**/*.js"    build when any .js file changes

@paulmillr
Copy link
Owner

watch sounds too generic, chokidar would be better here. You can always do alias watch=chokidar, but you cannot do otherwise if you have bin file conflicts.

But anyway, I think the binary is out of scope for chokidar, an NPM interface. I would suggest to create your own NPM package that'll do the same thing. Maybe name it as rerun-cmd or whatever you'd like. We can mention it in README.

Another reason for this is that some folks would want slightly different CLI. E.g. stream list of changed files instead of re-running the command.

@paulmillr paulmillr closed this Apr 19, 2015
@es128
Copy link
Collaborator

es128 commented Apr 19, 2015

Thanks for the contribution @kimmobrunfeldt, but I agree with @paulmillr that this belongs in a separate package.

Just as a side note, we try to minimize the dependencies in chokidar, so even if we wanted to merge this feature would have needed to be changed to drop the convenience features of the lodash and bluebird utility libs. Minimatch was added without being used, and chokidar uses anymatch for glob matching anyway. I would have been ok with keeping yargs or an alternate argument parsing lib to support this feature though.

Also watch as a node CLI command already exists: https://github.com/mikeal/watch

It's worth noting there are some existing CLI wrappers for chokidar on npm already

https://www.npmjs.com/package/onchange
https://www.npmjs.com/package/node-fwatch
https://www.npmjs.com/package/dirwatch
https://www.npmjs.com/package/fat-watchy
https://www.npmjs.com/package/chokidar-cmd
https://www.npmjs.com/package/chok

@paulmillr if we're going to mention this in the readme we should pick one favorite. Probably the first one. What do you think?

@paulmillr
Copy link
Owner

Let's use the first one.

@kimmobrunfeldt
Copy link
Author

I created a new cli which supports quite a lot of options: https://github.com/kimmobrunfeldt/chokidar-cli
Please take a look. It supports more chokidar features compared to other clis.

@kimmobrunfeldt
Copy link
Author

It is not fully ready yet but will be in the following few days. I'm going to use it my self in my other projects so I'll keep maintaining it.

@kimmobrunfeldt
Copy link
Author

@paulmillr @es128 chokidar-cli is now "ready". https://www.npmjs.com/package/chokidar-cli

I renamed the binary to chokidar.

@kimmobrunfeldt
Copy link
Author

I added support for piping/change streaming and moved "run command on change" under optional -c, --command flag. Now it's more general purpose tool.

@es128
Copy link
Collaborator

es128 commented Apr 19, 2015

@kimmobrunfeldt sounds good. I'm warming up to the idea of recommending your tool in the README.

I think it would be cool if you could add @paulmillr and I as collabs on the repo & npm.

@kimmobrunfeldt
Copy link
Author

@es128 sure, done.

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

Successfully merging this pull request may close these issues.

None yet

3 participants