1 | Incremental utilities for NodeJS File System API.
|
2 |
|
3 | [![Build Status](https://secure.travis-ci.org/serpentem/fs-util.png)](http://travis-ci.org/serpentem/fs-util)
|
4 | > Version 0.3.1
|
5 |
|
6 | ## Compatibility
|
7 |
|
8 | It just works.
|
9 |
|
10 | * Linux
|
11 | * MacOSX
|
12 | * Windows
|
13 |
|
14 | # Documentation
|
15 |
|
16 | - [FS Watcher](#watcher)
|
17 | - [FS Tools](#tools)
|
18 |
|
19 | <a name="watcher"/>
|
20 | # FS Watcher
|
21 |
|
22 | Provides the ability to watch an entire _*tree*_ of `dirs` and `files`.
|
23 |
|
24 | ## Usage
|
25 |
|
26 | ````coffeescript
|
27 | fsu = require 'fs-util'
|
28 | watcher = fsu.watch [desired_path], [regex_pattern], [recursive_notifications]
|
29 | ````
|
30 |
|
31 | > `desired_path`
|
32 |
|
33 | The path to the `dir` you wanna watch (ie. 'my/path'), `file` is not accept.
|
34 |
|
35 | > `regex_pattern`
|
36 |
|
37 | The regex to filter only the files you wanna watch, i.e. `/.coffee$/m`.
|
38 |
|
39 | > `recursive_notifications`
|
40 |
|
41 | If `true` notifications will be fired for all files. If you delete a `dir`
|
42 | that has many `sub dirs` and `files`, an `unwatch` and `delete` events will be
|
43 | ispatched for all the children `dirs` and `files` as well.
|
44 |
|
45 | If `false`, only one event will be dispatched for the `dir` that was actually
|
46 | deleted. It can save you an overhead of events popping up when a `dir` with
|
47 | big ammount of `subdirs` and `files` is deleted.
|
48 |
|
49 | ## Events
|
50 | * watch
|
51 | * unwatch
|
52 | * create
|
53 | * change
|
54 | * delete
|
55 |
|
56 | ## Example
|
57 |
|
58 | ````coffeescript
|
59 | fsu = require 'fs-util'
|
60 | watcher = fsu.watch 'desired/path', /.coffee$/m, true
|
61 | watcher.on 'watch', (f)-> console.log 'WATCHED ' + [f.type, f.location]
|
62 | watcher.on 'unwatch', (f)-> console.log 'UNWATCHED ' + [f.type, f.location]
|
63 | watcher.on 'create', (f)-> console.log 'CREATED ' + [f.type, f.location]
|
64 | watcher.on 'change', (f)-> console.log 'CHANGED ' + [f.type, f.location]
|
65 | watcher.on 'delete', (f)-> console.log 'DELETED ' + [f.type, f.location]
|
66 | ````
|
67 |
|
68 | ### Callback's argument
|
69 |
|
70 | All callbacks receives only *one* argument which is the related `[f]ile` to
|
71 | the event.
|
72 |
|
73 | It has the following properties:
|
74 |
|
75 | > [f].location
|
76 |
|
77 | Fullpath `location` of the item.
|
78 |
|
79 | > [f].type
|
80 |
|
81 | Item `type`, can be `dir` or `file`.
|
82 |
|
83 | > [f].prev
|
84 |
|
85 | Last stat of the file, it's an instance of [fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats).
|
86 |
|
87 | > [f].curr
|
88 |
|
89 | Current stat of the file, it's an instance of [fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats).
|
90 |
|
91 | > [f].tree
|
92 |
|
93 | The complete `tree` of subitems (`files` and `dirs`) under that point.
|
94 |
|
95 | * _Applies only when `f.type` is `dir`_
|
96 |
|
97 | <a name="tools"/>
|
98 | # FS Tools
|
99 |
|
100 | Provides functionalities such as `rm_rf`, `cp_r`, `mkdir_p`, `find` and `ls`.
|
101 |
|
102 | ## Usage
|
103 |
|
104 | ````coffeescript
|
105 | fsu = require 'fs-util'
|
106 | fsu.mkdirp [dir_path]
|
107 | fsu.touch [file_path], [encoding='utf-8']
|
108 | fsu.copy [from_path], [to_path]
|
109 | fsu.find [path], [regex_pattern], [include_dirs]
|
110 | fsu.ls [path]
|
111 | fsu.rm_rm [path]
|
112 | ````
|
113 |
|
114 | > `*path`
|
115 |
|
116 | Absolute or relative `paths` are accepted, you take care of your things.
|
117 |
|
118 | > `encoding`
|
119 |
|
120 | The `file` encoding when `touching` it.
|
121 |
|
122 | > `regex_pattern`
|
123 |
|
124 | Your search pattern, i.e. `/.coffee$/m`.
|
125 |
|
126 | > `include_dirs`
|
127 |
|
128 | When `true` will include the `dirs` in the search, otherwise only `files`.
|
129 |
|
130 | # Installing
|
131 |
|
132 | ````bash
|
133 | npm install fs-util
|
134 | ````
|
135 |
|
136 | ## Resolving dependencies
|
137 |
|
138 | ````bash
|
139 | cd fs-util && npm install
|
140 | ````
|
141 |
|
142 | ### Building
|
143 |
|
144 | ````bash
|
145 | make build
|
146 | ````
|
147 |
|
148 | ### Testing
|
149 |
|
150 | ````bash
|
151 | make test
|
152 | ````
|
153 |
|
154 | * Current [output](https://raw.github.com/serpentem/fs-util/master/imgs/tests-passing.png):
|
155 |
|
156 | ````bash
|
157 | Current version is: 0.3.1
|
158 |
|
159 | • FS Tools
|
160 | When making a deep-dir structure
|
161 | ✓ the structure must to be created
|
162 | When touching a file
|
163 | ✓ the file must be touched
|
164 | When copying a structure
|
165 | ✓ the structure must to be copied
|
166 | When searching a file
|
167 | ✓ the search must to return the proper results
|
168 | When searching a directory
|
169 | ✓ the search must to return the proper results
|
170 | When listing a directory
|
171 | ✓ the list must to return the dir contents
|
172 | When removing a strucuture recursively
|
173 | ✓ the structure must to removed recursively
|
174 |
|
175 | • FS Watcher
|
176 | When watching a directory tree
|
177 | ✓ the `watch` event should be emitted properly
|
178 | When creating a dir inside that tree
|
179 | ✓ the `watch` and `create` event should be emitted properly
|
180 | When deleting this dir
|
181 | ✓ the `unwatch` and `delete` events should be emitted properly
|
182 | When creating a file inside the watched dir
|
183 | ✓ the `created` and `watch` events should be emitted properly
|
184 | When updating this file (a little delay needed here, pay no mind)
|
185 | ✓ the `change` event should be emitted properly (1001ms)
|
186 | When deleting this file
|
187 | ✓ the `unwatch` and `delete` events should be emitted properly
|
188 | When moving an existent structure inside the watched tree
|
189 | ✓ the `create` and `watch` events should be emitted properly for all files and dirs
|
190 | When deleting this structure
|
191 | ✓ the `delete` and `unwatch` events should be emitted properly for all files and dirs
|
192 |
|
193 | 15 tests complete (1 seconds)
|
194 | ```` |
\ | No newline at end of file |