Giter Club home page Giter Club logo

watchlist's Introduction

watchlist
Recursively watch a list of directories & run a command on any file system changes

Features

  • Extremely lightweight
  • Simple fs.watch wrapper
  • Runs on OSX, Linux, and Windows
  • Recursively monitors all subdirectories
  • Optional ignore patterns

While fs.watch has its inconsistencies, efforts are made to normalize behavior across platforms.

Install

$ npm install --save-dev watchlist

Usage

CLI

# Run `npm test` on changes within "src" and "test" contents change
$ watchlist src test -- npm test

# Run `npm test` on changes within "packages", ignoring /fixtures/i
$ watchlist packages --ignore fixtures -- npm test

# Run `lint` script on ANY change
$ watchlist -- npm run lint

API

import { watch } from 'watchlist';

async function task() {
  console.log('~> something updated!');
  await execute_example(); // linter, tests, build, etc
}

// Run `task()` when "{src,test}/**/*" changes
// Must also ignore changes to any `/fixture/i` match
await watch(['src', 'test'], task, {
  ignore: 'fixtures'
});

CLI

The watchlist binary expects the following usage:

$ watchlist [...directory] [options] -- <command>

Important: The -- is required! It separates your command from your watchlist arguments.

Please run watchlist --help for additional information.

API

watch(dirs: string[], handler: Function, options?: Options)

Returns: Promise<void>

Watch a list of directories recursively, calling handler whenever their contents are modified.

dirs

Type: Array<String>

The list of directories to watch.

May be relative or absolute paths.
All paths are resolved from the opts.cwd location.

handler

Type: Function

The callback function to run.

Note: This may be a Promise/async function. Return values are ignored.

options.cwd

Type: String
Default: .

The current working directory. All paths are resolved from this location.
Defaults to process.cwd().

options.ignore

Type: String or RegExp or Array<String | RegExp>

A list of patterns that should not be watched nor should trigger a handler execution.
Ignore patterns are applied to file and directory paths alike.

Note: Any String values will be converted into a RegExp automatically.

options.clear

Type: Boolean
Default: false

Whether or not the console should be cleared before re-running your handler function.

Note: Defaults to true for the CLI! Pass --no-clear to disable.

run(command: string, ...args)

Returns: Promise<void>

All arguments to watchlist.run are passed to child_process.exec directly.

Note: Any stdout or stderr content will be piped/forwarded to your console.

command

Type: String

The command string to execute.
View child_process.exec for more information.

args

Type: String

Additional child_process.exec arguments.

Important: The callback argument is not available!

License

MIT © Luke Edwards

watchlist's People

Contributors

lukeed avatar

Watchers

James Cloos avatar

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.