Giter Club home page Giter Club logo

chokidar-cmd's Introduction

chokidar-cmd

โš ๏ธ This package is deprecated! After releasing this package another one called chokidar-cli was made for the same purpose. chokidar-cli is now way more popular than this so I don't see much sense in maintaining this. Please migrate to chokidar-cli.

Command-line wrapper for Chokidar. Run shell command when file or file's in a directory are changed.

Installation

Install globally npm install -g chokidar-cmd or as a project dependency npm install chokidar-cmd.

CLI usage

Usage: chokidar-cmd -c "command" -t file-or-dir-or-glob

Commands:
  chokidar-cmd  Watch directory or file for changes and run given command

Options:
  --command, -c  Command to run on file changes              [string] [required]
  --target, -t   Target file path, directory and its contents or glob pattern to
                 watch. You can provide several targets using several target
                 flags.                                       [array] [required]
  --verbose, -v  Show verbose output                                   [boolean]
  --quiet, -q    Silence normal output from chokidar-cmd               [boolean]
  --initial      Run command immediately after initial scan (when chokidar is
                 ready)                                                [boolean]
  --all          Run command on all file events and not just on changes[boolean]
  --help, -h     Show help                                             [boolean]
  --version      Show version number                                   [boolean]

Examples:
  chokidar-cmd -c "npm run less" -t src/    Run less build on changes to styles
  chokidar-cmd -c "npm run less" -t src/    Run less build on changes to either
  -t vendor/                                styles directory

npm run usage

Use it directly from your package.json for watching without task runners and without installing globally!

{
    "devDependencies": {
        "chokidar-cmd": "^1.0.0"
    },
    "scripts": {
        "less": "lessc src/styles.less public/styles.css",
        "watch:less": "chokidar-cmd -c \"npm run less\" -t src/styles.less"
    }
}
$ npm run watch:less

Changelog

See Releases.

chokidar-cmd's People

Contributors

hilzu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

thomasfl

chokidar-cmd's Issues

Use multiple -c flags

Would be nice if I could provide multiple -c flags to run different commands on different changes. For instance, run the LESS compiler when .less files changes and so on.

wrapping watch commands in single quotes runs as if the quotes themselves are plain string content

Based on #4, the following two cases behave predictably:

  1. chokidar-cmd -c "npm run test:2" -t somedir - runs npm run test:2 on changes
  2. chokidar-cmd -c npm run test:2 -t somedir - runs npm on changes

However, single quotes behave counter-intuitively: chokidar-cmd -c 'npm run test:2' -t somedir, while expected to run the same npm run test:2 as in (1), instead runs 'npm as in (2).

It would be a good idea to make chokidar-cmd treat both double and single quotes as command wrappers, so that when quoted, irrespective of the quote symbols, the full command gets run.

Make the first command line argument the file globs and the second argument the command string

There's not much use running chokidar-cmd without a file-or-dir-or-glob and a command. Instead of having -c and -t options, the first command line argument could be a list of file-or-dir-or-glob the second command line option could be the command to run.

For example, instead of typing this:

  chokidar-cmd -c "npm run less" -t src/styles.less -t vender/styles.less

Users would instead type the shorter:

  chokidar-cmd "src/styles.less vendor/styles.less" "npm run less"

This would make chokidar-cmd a javascript replacement for my rubygem https://github.com/thomasfl/filewatcher

chokidar-cmd cannot run "npm" on windows

There is a lovely quirk around Node for windows that causes npm scripts that involve chokidar like the following to not work on windows:

  ...
  "scripts": {
    ...
    "start:less": "chokidar-cmd -c 'npm run less' -t less",
    ...
  },
  ...

The reason for this is that on windows, the npm command only works because it lets windows autoresolve it from the non-existent npm.exe to npm.cmd - however, when Node's exec or spawn are used, that resolution does not happen, and so calls like npm run less will fail unless they are specifically rewritten to (1) use spawn rather than exec and (2) use npm.cmd instead.

While a very specific problem, having chokidar trigger npm scripts, because it's a node utility, seems high incident enough to warrant checking what the operational call is, and if it's "npm", rewrite it to "npm.cmd" when process.platform === "win32" (which, sadly, but usefully, covers both 32 and 64 bit versions of windows)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.