7.1.0 • Published 4 years ago

onchange v7.1.0

Weekly downloads
114,700
License
MIT
Repository
github
Last release
4 years ago

onchange

Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.

Install

npm install onchange

Usage

# On every change run `npm test`.
onchange 'app/**/*.js' 'test/**/*.js' -- npm test

# On every change restart `server.js` (by killing the running process).
onchange -i -k '**/*.js' -- node server.js

# On every change `echo` file change.
onchange '**/*.js' -- echo '{{event}} to {{file}}'

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

Add (-a, --add)

To execute the command for all initially added paths:

onchange -a 'config.json' -- microservice-proxy -c {{file}} -p 9000

Initial (-i, --initial)

To execute the command once on load without any event:

onchange -i '**/*.js' -- npm start

Exclude (-e, --exclude)

To exclude matches:

onchange '**/*.ts' -e 'dist/**/*.js' -- tslint

No Exclude (--no-exclude)

**/node_modules/** and **/.git/** are excluded by default, use --no-exclude to disable:

onchange 'node_modules/**' --no-exclude -- tslint

Exclude Path (--exclude-path)

Excludes all paths in a file following the .gitignore specification.

onchange '**' --exclude-path .gitignore -- prettier

Kill (-k, --kill)

To kill current and pending processes between changes:

onchange -k '**/*.js' -- npm test

Jobs (-j <n>, --jobs <n>)

Set the maximum concurrent processes to run (default is 1):

onchange -j2 '**/*.js' -- cp -v -r '{{file}}' 'test/{{file}}'

Delay (-d, --delay)

To set the amount of delay (in ms) between process changes:

onchange -d 1000 '**/*.js' -- npm start

Await Write Finish (--await-write-finish <ms>)

To hold the events until the size does not change for a configurable amount of time (in ms, default is 2000):

onchange --await-write-finish 1500 '**/*.js' -- npm test

Poll (-p <ms>, --poll <ms>)

Use polling to monitor for changes. This option is useful if you're watching an NFS volume.

onchange -p 100 '**/*.js' -- npm test

Outpipe (-o, --outpipe)

Shell command to execute every change:

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.

Filter (-f, --filter)

By default, onchange watches for all events from chokidar. Use this option to watch only for events you need:

onchange -f add -f change '**/*.js' -- npm start

Verbose (-v, --verbose)

Enable if you want verbose logging from onchange (useful for debugging). For example:

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.

License

MIT

atom-acs-timesheet-serve@imflavio/clischockypoc-shared-serveryp-mdlinksyp-.mdlinksconnexstyleguide@ymatuhin/buildrns-chatbotmjml-browsersync-boilerplatesvelte-simple-progressbarwmm-package-cli-testwoo-to-vuewm-cli-testwm-cli-webpack5wm-hosp-wm-cli-testweb-vitals-google-analytics-shopifywx-coolws-ewheels-reactsgmf-scriptsshocky-clireactjs_koansthree-jarvispumpkinheadstupidly-happymjmlhelperlibalibelanimatejsmp-infra-hometask6iqa-chat-botistanbul-middleware-rymoneypal-chatbothey.jshtml-template-skeletonhtmlgoddesshtmlgoddess-webpack-pluginhoseajwtbutlerkieleaflet.tilesextentmanagernavbar-modulemul-sgmf-scriptslusciousontouml-schemap-mdlinksprotobuilderplastticnext-modal-videomodestoreact-simple-chatbotreact-simple-chatbot-iarainylinkreact-modal-video-joseadmreact-modal-video-newredux-middleware-fetch-apisrbjsloggerspringerubuntu-designui-crmturbo-git-configtradera-themetorfs-sgmf-scripts@alanpaulprice/prettier@bloomreach/frontend-build@choleski/abacus@clearmetrics/scripts1000-packages@abdt/ornament@dgg32/react-simple-chatbotypp-mdlinksvhug-tasksuse-dpr@ed-g/sgmf-scripts@htmlgoddess/cli@htmlgoddess/webpack-plugin@frontiersusa/press-css@ginterdev/next-showcase@gohai/ml5@kylebmeredith/ml5@maggiben/duration-format@ndustrial/nd-react-charting@everything-registry/sub-chunk-2376@jvmn/groundzero-taskrunner@jvmn/groundzero-taskrunner-webpack@kcscope/simple-ai-chatbot@scola/lib@stevie-arpanet/hyper-ui@pioneer-sdk/sdk@pioneer-sdk/sdk-v2@pioneer-sdk/tx-builder@palomania/mdlinks@strutfitdev/sf-simple-chatbot@staart/scripts@cyklang/vue3@potch/playouteduardoveiga-chatbotemdia-chatbotendotech-api-nodeeze@tradera/tradera-ui
7.1.0

4 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.1.1

5 years ago

6.1.0

5 years ago

6.0.0

6 years ago

5.2.0

6 years ago

5.1.3

6 years ago

5.1.2

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.1.0

6 years ago

4.0.0

7 years ago

3.3.0

7 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.5.0

9 years ago

2.4.0

9 years ago

2.3.0

9 years ago

2.2.0

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

11 years ago