tree-sync
Advanced tools
Comparing version 1.2.2 to 1.3.0
16
index.js
@@ -11,8 +11,18 @@ 'use strict'; | ||
function TreeSync(input, output) { | ||
function TreeSync(input, output, options) { | ||
this._input = input; | ||
this._output = output; | ||
this._options = options || {}; | ||
this._walkSyncOpts = {}; | ||
this._hasSynced = false; | ||
this._lastInput = FSTree.fromEntries([]); | ||
// Pass through whitelisted options to walk-sync. | ||
if (this._options.globs) { | ||
this._walkSyncOpts.globs = options.globs; | ||
} | ||
if (this._options.ignore) { | ||
this._walkSyncOpts.ignore = options.ignore; | ||
} | ||
debug('initializing TreeSync: %s -> %s', this._input, this._output); | ||
@@ -27,4 +37,4 @@ } | ||
var input = FSTree.fromEntries(walkSync.entries(this._input)); | ||
var output = FSTree.fromEntries(walkSync.entries(this._output)); | ||
var input = FSTree.fromEntries(walkSync.entries(this._input, this._walkSyncOpts)); | ||
var output = FSTree.fromEntries(walkSync.entries(this._output, this._walkSyncOpts)); | ||
@@ -31,0 +41,0 @@ debug('walked %s %dms and %s %dms', this._input, input.size, this._output, output.size); |
{ | ||
"name": "tree-sync", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -23,7 +23,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"fs-tree-diff": "^0.5.6", | ||
"debug": "^2.2.0", | ||
"mkdirp": "^0.5.1", | ||
"quick-temp": "^0.1.5", | ||
"walk-sync": "^0.2.7" | ||
"walk-sync": "^0.3.3" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -9,7 +9,7 @@ # TreeSync [![Build Status](https://travis-ci.org/stefanpenner/tree-sync.svg?branch=master)](https://travis-ci.org/stefanpenner/tree-sync) [![Build status](https://ci.appveyor.com/api/projects/status/7136sbfmybx6q7w2?svg=true)](https://ci.appveyor.com/project/embercli/tree-sync) | ||
var tree = new TreeSync('input', 'output') | ||
var tree = new TreeSync('input', 'output'); | ||
tree.sync(); | ||
// output is now contains copies of everything that is in input | ||
fs.unlink('/input/a/b/js'); | ||
fs.unlink('/input/a/b.js'); | ||
@@ -22,1 +22,40 @@ // input / output have diverged | ||
``` | ||
Under the hood, this library uses [walk-sync](https://github.com/joliss/node-walk-sync) to traverse files and folders. You may optionally pass in options to selectively include or ignore files and directories. These whitelisted properties (`ignore` and `globs`) will be passed to walk-sync. | ||
```js | ||
// Assume the following folder structure... | ||
// input/ | ||
// foo/ | ||
// foo.js | ||
// bar.js | ||
// bar/ | ||
// foo-bar.js | ||
var tree = new TreeSync('input', 'output', { | ||
ignore: ['**/b'] | ||
}); | ||
tree.sync(); | ||
// We now expect output to contain foo/, but not bar/. | ||
// Any changes made to bar/ won't be synced to output, and the contents of bar/ won't be traversed. | ||
``` | ||
```js | ||
// Assume the following folder structure... | ||
// input/ | ||
// foo/ | ||
// foo.js | ||
// bar.js | ||
// bar/ | ||
// foo-bar.js | ||
var tree = new TreeSync('input', 'output', { | ||
globs: ['foo', 'foo/bar.js'] | ||
}); | ||
tree.sync(); | ||
// We now expect output to contain foo/bar.js, but nothing else. | ||
// Be careful when using this property! You'll need to make sure that if you're including a file, it's parent | ||
// path is also included, or you'll get an error when tree-sync tries to copy the file over. | ||
``` |
5509
84
59
+ Addedwalk-sync@0.3.4(transitive)
- Removedwalk-sync@0.2.7(transitive)
Updatedwalk-sync@^0.3.3