Giter VIP home page Giter VIP logo

fs-util's Introduction

FsUtil

Incremental utilities for NodeJS File System API.

Build Status Dependency Status NPM version

Compatibility

  • Linux
  • MacOSX
  • Windows

Documentation

Setting up


# FS Watcher

Provides the ability to watch an entire tree of dirs and files.

## Usage
fsu = require 'fs-util'
watcher = fsu.watch [desired_path], [regex_pattern], [recursive_notifications]

desired_path

The path to the dir or file you wanna watch.

regex_pattern

The regex to filter only the files you wanna watch.

recursive_notifications

If true notifications will be fired for all files. If you delete a dir that has many sub dirs and files, an unwatch and delete events will be dispatched for all the children dirs and files as well.

If false, only one event will be dispatched for the dir that was actually deleted. It can save you an overhead of events popping up when a dir with big ammount of subdirs and files is deleted.

## Events * watch * unwatch * create * change * delete ## Example

Bellow is a very basic usage example that can be found in the examples folder.

fsu = require 'fs-util'
watcher = fsu.watch 'desired/path', /.coffee$/m, true
watcher.on 'watch', (f)-> console.log 'WATCHED ' + [f.type, f.location]
watcher.on 'unwatch', (f)-> console.log 'UNWATCHED ' + [f.type, f.location]
watcher.on 'create', (f)-> console.log 'CREATED ' + [f.type, f.location]
watcher.on 'change', (f)-> console.log 'CHANGED ' + [f.type, f.location]
watcher.on 'delete', (f)-> console.log 'DELETED ' + [f.type, f.location]

watcher.close()
### Callback's argument

All callbacks receives only one argument which is the related [f]ile to the event.

It has the following properties:

[f].location

Fullpath location of the item.

[f].type

Item type, can be dir or file.

[f].prev

Last stat of the file, it's an instance of fs.Stats.

[f].curr

Current stat of the file, it's an instance of fs.Stats.

[f].tree

The complete tree of subitems (files and dirs) under that point.

  • Applies only when f.type is dir
### Watcher's method

Besides all the Event Emiter inherited methods, the watcher class has one more:

[watcher].close()

When called, this method will forcely close all persistent watcher's process and removes all previously added listeners. Every file and folder is unwatched, events will pop normally for them, and after that the instance becomes useless.


# FS Tools

Provides functionalities such as rm_rf, cp_r, mkdir_p, find and ls.

## Usage
fsu = require 'fs-util'
fsu.mkdirp [dir_path]
fsu.touch [file_path], [encoding='utf-8']
fsu.copy [from_path], [to_path]
fsu.find [path], [regex_pattern], [include_dirs]
fsu.ls [path]
fsu.rm_rm [path]

*path

Absolute or relative paths are accepted, you take care of your things.

encoding

The file encoding when touching it.

regex_pattern

Your search pattern, i.e. /.coffee$/m.

include_dirs

When true will include the dirs in the search, otherwise only files.


# Installing

Remembers that you need to install fs-util locally in order to use it as a LIB. You will need to require 'fs-util in you script, there's no reason to install it globally with -g, fs-util won't work directly in the command line.

At least for now.

npm install fs-util
## Developing

In order to contribute you will need to fork, clone and initialize the env.

git clone [email protected]:[username]/fs-util
cd fs-util && npm install
### Building

Build the src/*.coffee files to lib/*.js.

make build
### Watching

Continuously building in watch mode.

make watch
### Testing

Running tests suite.

make test

fs-util's People

Contributors

arboleya avatar giuliandrimba avatar oancaandrei 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.