2.0.0 • Published 7 years ago

@write-for-christ/prophet-samuel v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@write-for-christ/prophet-samuel

In the Bible, prophet Samuel always listen for God's Word before doing something, this module will help us listen for files changed and execute actions in reactive way.

Build Status Coverage Status David David Commitizen friendly Greenkeeper badge

Features

  • Watch for all files changed.
  • Parse file path from changed file.
  • Execute actions based on filtered pattern.
  • Support reactive functional programming.

Installation

npm install @write-for-christ/prophet-samuel

How to use?

  const samuel = require('prophet-samuel');

  // Simple usage, only watch on single directory
  samuel().watch('/path/to/watch').subscribe((data) => {
    console.log(data);
  });

  // Recursive mode
  samuel().watch('/path/to/watch', { recursive: true}).subscribe((data) => {
    console.log(data);
  });
  • Notice: Every time we call samuel() a new instance is allocated.
  • If a file changed at /path/to/watch/sub/of/sub/dir/updated.txt the data should be:
   {
      event: 'update',
      path: '/path/to/watch/sub/of/sub/dir/updated.txt',
      dir: '/path/to/full/file/',
      root: '/',
      base: 'updated.txt',
      name: 'updated',
      ext: '.txt',
      rel: '/sub/of/sub/dir/'
   }