Comparing version 0.0.6 to 0.1.0
@@ -0,1 +1,6 @@ | ||
/* | ||
Copyright (c) 2012, Yahoo! Inc. All rights reserved. | ||
Code licensed under the BSD License: | ||
http://yuilibrary.com/license/ | ||
*/ | ||
var fs = require('graceful-fs'); | ||
@@ -16,5 +21,2 @@ var Stack = require('./stack').Stack; | ||
fs.readdir(from, stack.add(function(err, dirs) { | ||
if (err) { | ||
return errors.push(err); | ||
} | ||
dirs.forEach(function (dir) { | ||
@@ -51,2 +53,3 @@ var base = path.join(from, dir); | ||
}); | ||
}; | ||
@@ -75,4 +78,4 @@ | ||
dirs[path.dirname(item)] = true; | ||
options.stats[path.dirname(item)] = fs.statSync(path.dirname(item)); | ||
options.toHash[path.dirname(item)] = path.dirname(to); | ||
options.stats[path.dirname(item)] = fs.statSync(path.dirname(item)); | ||
options.toHash[path.dirname(item)] = path.dirname(to); | ||
}); | ||
@@ -126,36 +129,43 @@ | ||
var createFiles = function(files, to, options, callback) { | ||
var stack = new Stack(), | ||
copy = function(from, to, callback) { | ||
var fromFile = fs.createReadStream(from), | ||
toFile = fs.createWriteStream(to), | ||
bail, | ||
onError = function (err) { | ||
if (/EMFILE/.test(err)) { | ||
bail = true; | ||
setTimeout(function() { | ||
copy(from, to, callback); | ||
}, 50); | ||
} else if (err) { | ||
options.errors.push(err); | ||
var next = process.nextTick, | ||
complete = 0, | ||
count = files.length, | ||
check = function() { | ||
if (count === complete) { | ||
callback(); | ||
} | ||
}, | ||
copy = function() { | ||
var from = files.pop(), | ||
to = options.toHash[from], | ||
dir = path.dirname(to); | ||
if (!from) { | ||
return check(); | ||
} | ||
mkdirp(dir, function() { | ||
var fromFile = fs.createReadStream(from), | ||
toFile = fs.createWriteStream(to), | ||
bail, | ||
onError = function (err) { | ||
if (/EMFILE/.test(err)) { | ||
bail = true; | ||
files.push(from); | ||
} else if (err) { | ||
options.errors.push(err); | ||
} | ||
}; | ||
fromFile.on('error', onError); | ||
toFile.on('error', onError); | ||
fromFile.pipe(toFile); | ||
fromFile.once('end', function() { | ||
if (!bail) { | ||
complete++; | ||
} | ||
}; | ||
fromFile.on('error', onError); | ||
toFile.on('error', onError); | ||
fromFile.pipe(toFile); | ||
fromFile.once('end', function() { | ||
if (!bail) { | ||
callback(); | ||
} | ||
next(copy); | ||
}); | ||
}); | ||
}; | ||
files.forEach(function(file) { | ||
var to = options.toHash[file]; | ||
copy(file, to, stack.add(function() {})); | ||
}); | ||
stack.done(function() { | ||
callback(); | ||
}); | ||
copy(); | ||
}; | ||
@@ -178,3 +188,3 @@ | ||
} | ||
if (filtered.length) { | ||
@@ -181,0 +191,0 @@ filtered.forEach(function(file) { |
@@ -0,1 +1,6 @@ | ||
/* | ||
Copyright (c) 2012, Yahoo! Inc. All rights reserved. | ||
Code licensed under the BSD License: | ||
http://yuilibrary.com/license/ | ||
*/ | ||
var Stack = function () { | ||
@@ -2,0 +7,0 @@ this.errors = []; |
@@ -5,5 +5,5 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"graceful-fs": "~1.1.14", | ||
"graceful-fs": "~1.2.0", | ||
"rimraf": "~2.0.2", | ||
@@ -10,0 +10,0 @@ "mkdirp": "~0.3.4" |
@@ -124,3 +124,3 @@ var vows = require('vows'), | ||
}, | ||
'and should not copy graceful-fs from function': { | ||
'and should not copy minimatch from function': { | ||
topic: function() { | ||
@@ -135,3 +135,3 @@ var out = path.join(to, '3'), | ||
filter: function (item) { | ||
return !(/graceful-fs/.test(item)); | ||
return !(/minimatch/.test(item)); | ||
} | ||
@@ -142,4 +142,4 @@ }, function(err, status) { | ||
dirs: { | ||
from: fs.readdirSync(from).sort(), | ||
to: fs.readdirSync(out).sort() | ||
from: fs.readdirSync(path.join(from, 'jshint/node_modules')).sort(), | ||
to: fs.readdirSync(path.join(out, 'jshint/node_modules')).sort() | ||
} | ||
@@ -157,11 +157,11 @@ }; | ||
}, | ||
'and from directory has graceful-fs dir': function(topic) { | ||
'and from directory has minimatch dir': function(topic) { | ||
var fromHasGFS = topic.dirs.from.some(function(item) { | ||
return (item === 'graceful-fs'); | ||
return (item === 'minimatch'); | ||
}); | ||
assert.isTrue(fromHasGFS); | ||
}, | ||
'and to directory does not have graceful-fs dir': function(topic) { | ||
'and to directory does not have minimatch dir': function(topic) { | ||
var toHasGFS = topic.dirs.to.some(function(item) { | ||
return (item === 'graceful-fs'); | ||
return (item === 'minimatch'); | ||
}); | ||
@@ -168,0 +168,0 @@ assert.isFalse(toHasGFS); |
Sorry, the diff of this file is not supported yet
22376
507
+ Addedgraceful-fs@1.2.3(transitive)
Updatedgraceful-fs@~1.2.0