GithubHelp home page GithubHelp logo

tiye / monocle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samccone/monocle

0.0 1.0 0.0 165 KB

a tool for watching things

License: BSD 2-Clause "Simplified" License

JavaScript 97.31% Shell 2.69%

monocle's Introduction

Build Status

Monocle -- a tool for watching things

logo

Have you ever wanted to watch a folder and all of its files/nested folders for changes. well now you can!

Installation

npm install monocle

Usage

Watch a directory:

var monocle = require('monocle')()
monocle.watchDirectory({
  root: <root directory>,
  fileFilter: <optional>,
  directoryFilter: <optional>,
  listener: fn(fs.stat+ object), //triggered on file change / addition
  complete: <fn> //file watching all set up
});

The listener will recive an object with the following

  name: <filename>,
  path: <filepath-relative>,
  fullPath: <filepath-absolute>,
  parentDir: <parentDir-relative>,
  fullParentDir: <parentDir-absolute>,
  stat: <see fs.stats>

fs.stats

When a new file is added to the directoy it triggers a file change and thus will be passed to your specified listener.

The two filters are passed through to readdirp. More documentation can be found here

Watch a list of files:

Monocle.watchFiles({
  files: [], //path of file(s)
  listener: <fn(fs.stat+ object)>, //triggered on file / addition
  complete: <fn> //file watching all set up
});

Just watch path

Just an alias of watchFiles and watchDirectory so you don't need to tell if that's a file or a directory by yourself. Parameter passed to path can be a string or a array of string.

Monocle.watchPathes({
  path: [], //list of pathes, or a string of path
  fileFilter: <optional>, // `*.js` for example
  listener: <fn(fs.stat+ object)>, //triggered on file / addition
  complete: <fn> //file watching all set up
});

Why not just use fs.watch ?

  • file watching is really bad cross platforms in node
  • you need to be smart when using fs.watch as compared to fs.watchFile
  • Monocle takes care of this logic for you!
  • windows systems use fs.watch
  • osx and linux uses fs.watchFile

License

BSD

monocle's People

Contributors

forbeslindesay avatar mattyod avatar samccone avatar tiye avatar

Watchers

 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.