src/clean.js
function clean(directoryPath, isRoot, done) {
  fs.stat(directoryPath, function(err, stat) {
    if (err) return done(isRoot ? undefined : err);
    if (stat.isFile()) return fs.unlink(directoryPath, done);
    fs.readdir(directoryPath, function(err, relativePaths) {
      if (err) return done(err);
      each(relativePaths, function(relativePath, next) {
        var absolutePath = path.join(directoryPath, relativePath);
        fs.stat(absolutePath, function(err, stats) {
          if (err) return next(err);
          if (!stats.isDirectory()) return fs.unlink(absolutePath, next);
          clean(absolutePath, false, next);
        });
      }, function(err) {
        if (err) return done(err);
        fs.rmdir(directoryPath, done);
      });
    });
  });
}
function clean(directoryPath, isRoot, done) {
  fs.stat(directoryPath, function(err, stat) {
    if (err) return done(isRoot ? undefined : err);
    if (stat.isFile()) return fs.unlink(directoryPath, done);
    fs.readdir(directoryPath, function(err, relativePaths) {
      if (err) return done(err);
      each(relativePaths, function(relativePath, next) {
        var absolutePath = path.join(directoryPath, relativePath);
        fs.stat(absolutePath, function(err, stats) {
          if (err) return next(err);
          if (!stats.isDirectory()) return fs.unlink(absolutePath, next);
          clean(absolutePath, false, next);
        });
      }, function(err) {
        if (err) return done(err);
        fs.rmdir(directoryPath, done);
      });
    });
  });
}
function clean ( directoryPath , isRoot , done ) { fs . stat ( directoryPath , function ( err , stat ) { if ( err ) return done ( isRoot ? undefined : err ) ; if ( stat . isFile ( ) ) return fs . unlink ( directoryPath , done ) ; fs . readdir ( directoryPath , function ( err , relativePaths ) { if ( err ) return done ( err ) ; each ( relativePaths , function ( relativePath , next ) { var absolutePath = path . join ( directoryPath , relativePath ) ; fs . stat ( absolutePath , function ( err , stats ) { if ( err ) return next ( err ) ; if ( ! stats . isDirectory ( ) ) return fs . unlink ( absolutePath , next ) ; clean ( absolutePath , false , next ) ; } ) ; } , function ( err ) { if ( err ) return done ( err ) ; fs . rmdir ( directoryPath , done ) ; } ) ; } ) ; } ) ; }
Cleans the files and directories in the directory path.
@param {string} directoryPath
@param {function(Error=)} done
Cleans the files and directories in the directory path .