Package Exports
- dir_comparator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dir_comparator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
---------------------------
T E R M I N O L O G Y
---------------------------
Dir,
is used as the short form for the word Directory.
DTN,
is used as the acronym of Dir Tree Node.
DirTreeNode is a Class whose properties & methods can be found
documented at,
git: https://github.com/DandechaAnkur/NodeJS-Directory-Tree
npm: https://www.npmjs.com/package/dir_tree
-----------------------------
I N T R O D U C T I O N
-----------------------------
This is a NodeJS module.
It can find the difference between two directories in terms of files.
The module exports an EventEmitter Class.
Its constructor takes the 2 target dir paths as its arguments.
Its object will emit either an error event or a data event depending
on whether it failed or succeeded.
---------------
U S A G E
---------------
var Dir_Comparator = require('dir_comparator')
var dir_comparator_obj =
new Dir_Comparator(dir_1, dir_2, filter_1, filter_2)
// These parameters are discussed further below.
dir_comparator_obj.on('error', function(error) {
// The error is an Error Object.
// The error handling can be done here.
})
dir_comparator_obj.on('data', function(dtn_1, dtn_2) {
// dtn_1 & dtn_2 are DirTreeNode Objects.
// They themselves contain the mutually exclusive files.
// dtn_1 corresponds to the dir_1 &
// dtn_2 corresponds to the dir_2.
// dtn_1 will have the files missing in dtn_2 & vice versa.
})
-------------------------
P A R A M E T E R S
-------------------------
[01] dir_1 & dir_2
----- -----
Both of them can be either strings or DirTreeNode Objects.
They correspond to the two target dirs paths.
In the case that they are strings will the filters be applied.
[02] filter_1 & filter_2
-------- --------
When the dir_1 & dir_2 are strings, filters can be used to filter
the files & the dirs using patterns.
Specifying a filter is optional.
A filter should have the following structure:
{
'idr': RegExp_Object,
'edr': RegExp_Object,
'ifr': RegExp_Object,
'efr': RegExp_Object
}
Let's call,
idr - include dir regex
edr - exclude dir regex
ifr - include file regex
efr - exclude file regex
File filtering logic:
--------------------
A dir will be searched only if it's not excluded. (its path isnt
like edr)
An excluded dir will not be searched at all.
After that, if the dir is not included (path isnt like idr),
then the "files of this dir" will be skipped.
Though the "dirs of this dir" will be considered for search.
Whenever a compatible dir is found (path is idr-edr passed),
each of the "files of this dir" is tested:
to be not excluded (path isn't like efr) and
to be included (path is like ifr).
If so then the file is considered a successful match.
If you do not want to utilize any of the idr, edr, ifr, efr, then
pass null or undefined instead; or even simpler, just omit that
property in the filter itself.
Note:
----
Do mind that when one filter disjoins a node (file | dir) from
one dir tree, that node becomes exclusive to the other dir tree.
Thus in case you wish to ignore some sort of nodes in both the
target dirs, ensure you realize you have to apply same filters
on both the dir trees.
----------------------------
A C.L.I. T H I N G Y
----------------------------
There's also a CLI tool in the package, named:
c2d | compare_2_dirs
It can find out for you the mutually exclusive files in the stated
two dir paths.
Use:
---
It can show you the mutually exclusive files - as embedded
inside the two dir trees corresponding to your two stated dirs.
It can tell you the total size & the total count of those
files & list them too.
Finally, you may want to have a look at the demo example packaged
inside.