diff --git a/lib/rmdir.js b/lib/rmdir.js index e263ecf..4c7b04f 100644 --- a/lib/rmdir.js +++ b/lib/rmdir.js @@ -7,7 +7,6 @@ * Remove all files in the given path recursively. */ var fs = require('fs'); -var Flow = require('node.flow'); function rmdir(dir, options, callback) { if (typeof options === 'undefined') { @@ -56,32 +55,30 @@ function rmdir(dir, options, callback) { xfs.lstat(file, function (err, stat) { function rm_all_dirs(callback) { - var flow = new Flow(); - if (!--pending) { if (!_dirs.length) return callback(); - _dirs.forEach(function (dir) { - flow.parallel(function (ready) { + var promises = _dirs.map(function (dir) { + return new Promise(function (resolve, reject) { xfs.exists(dir, function (exists) { - if (!exists) return ready(); + if (!exists) return resolve(); xfs.rmdir(dir, function (err) { - if (err) return ready(err); + if (err) return reject(err); - ready(); + resolve(); }); }); }); }); - flow.join(). - error(function (err) { - if (err) callback(err, _dirs, _files); - }). - end(function () { - callback(null, _dirs, _files); - }); + Promise.all(promises) + .then(function () { + callback(null, _dirs, _files); + }) + .catch(function (err) { + if (err) callback(err, _dirs, _files); + }); } } diff --git a/package.json b/package.json index 4f28bfd..1aed9d0 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,53 @@ { - "name" : "rmdir", - "version" : "1.2.0", + "name": "rmdir", + "version": "1.2.0", "description": "Remove all files in the given path recursively", - "keywords" : [ - "remove", "remove files", "remove all files", "remove path", - "remove dir", "rm -r", "rmdir", "remove files recursively" + "keywords": [ + "remove", + "remove files", + "remove all files", + "remove path", + "remove dir", + "rm -r", + "rmdir", + "remove files recursively" ], - "author" : "dreamerslab <ben@dreamerslab.com>", + "author": "dreamerslab <ben@dreamerslab.com>", "contributors": [ - { "name": "Aaron Larner" }, - { "name": "Glen R. Goodwin" }, { - "name" : "David Pate", + "name": "Aaron Larner" + }, + { + "name": "Glen R. Goodwin" + }, + { + "name": "David Pate", "email": "davidtpate@gmail.com", - "url" : "http://davidtpate.com" + "url": "http://davidtpate.com" }, { - "name" : "Radare", + "name": "Radare", "email": "pancake@nopcode.org", - "url" : "http://www.radare.org/" + "url": "http://www.radare.org/" } ], "dependencies": { - "node.flow" : "1.2.3" }, - "repository" : { + "repository": { "type": "git", - "url" : "https://github.com/dreamerslab/node.rmdir.git" + "url": "https://github.com/dreamerslab/node.rmdir.git" }, - "main" : "index", - "engines" : [ "node >= 0.8.0" ], - "licenses": [{ - "type": "MIT", - "url" : "http://en.wikipedia.org/wiki/MIT_License" - }], - "scripts" : { - "test" : "node test/run.js" + "main": "index", + "engines": [ + "node >= 0.8.0" + ], + "licenses": [ + { + "type": "MIT", + "url": "http://en.wikipedia.org/wiki/MIT_License" + } + ], + "scripts": { + "test": "node test/run.js" } }