Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.
npm install onchangeUse glob patterns to watch file sets and run a command when anything is added, changed or deleted.
``sh`
npm install onchange
`shnpm testOn every change run
.
onchange 'app//.js' 'test//.js' -- npm test
(by killing the running process). file change.NOTE: Windows users may need to use double quotes rather than single quotes. If used in an npm script, remember to escape the double quotes.
You can match as many glob patterns as you like, just put the command you want to run after the
-- and it will run any time a file matching any of the globs is added changed or deleted.Other available replacement variables are
fileExt
(path.extname(file)), fileBase (path.basename(file)),
fileBaseNoExt (basename, without extension), and fileDir
(path.dirname(file)).Options
$3
To execute the command for all initially added paths:
`sh
onchange -a 'config.json' -- microservice-proxy -c {{file}} -p 9000
`$3
To execute the command once on load without any event:
`sh
onchange -i '*/.js' -- npm start
`$3
To exclude matches:
`sh
onchange '/.ts' -e 'dist//.js' -- tslint
`$3
/node_modules/ and /.git/ are excluded by default, use --no-exclude to disable:`sh
onchange 'node_modules/**' --no-exclude -- tslint
`$3
.gitignore specification.`sh
onchange '**' --exclude-path .gitignore -- prettier
`$3
To kill current and pending processes between changes:
`sh
onchange -k '*/.js' -- npm test
`$3
Set the maximum concurrent processes to run (default is
1):`sh
onchange -j2 '*/.js' -- cp -v -r '{{file}}' 'test/{{file}}'
`$3
To set the amount of delay (in ms) between process changes:
`sh
onchange -d 1000 '*/.js' -- npm start
`$3
To hold the events until the size does not change for a configurable amount of time (in ms, default is
2000):`sh
onchange --await-write-finish 1500 '*/.js' -- npm test
`$3
Use polling to monitor for changes. This option is useful if you're watching an NFS volume.
`sh
onchange -p 100 '*/.js' -- npm test
`$3
Shell command to execute every change:
`sh
onchange -o '> .changelog' 'src/*/.js' -- echo '{{event}} to {{file}}'
`P.S. When a command is used with
--outpipe, the stdout from the command will be piped into outpipe.$3
By default, onchange watches for all events from chokidar. Use
this option to watch only for events you need:
`sh
onchange -f add -f change '*/.js' -- npm start
`$3
Enable if you want verbose logging from
onchange (useful for debugging). For example:`sh
onchange -v 'app//.js' 'test//.js' -- npm test
`TypeScript
Includes types for TypeScript users.
Related
- cli-error-notifier - Send native desktop notifications if a command exits with an exit code other than
0`.MIT