Read dir recursivly and process files
@param dir
@param basePath
@param {Object} result Result JSON
962159
function freezeAllProcessDir(dir, basePath, result) {
    fs.readdirSync(dir).forEach(function(file) {
        file = PATH.resolve(dir, file);
        var stat = fs.statSync(file);
        if (stat.isFile()) {
            freezeAllProcessFile(file, basePath, result);

        } else if (stat.isDirectory()) {
            freezeAllProcessDir(file, basePath, result);
        }
    });
}
1247227
function scanFolders(rootFolderPath, folders, folderFileExtensions, callback) {
        var result = [];

        console.log('Scanning:: Folders', folders);
        console.log('Scanning:: Root folder path', rootFolderPath);
        var fileExtensions = self.fileExtensions.slice();
        scanFolder();

        function scanFolder() {
            var folder = folders.shift();
            if (folder === undefined) {
//                console.log('Scanning:: Finished with result', result);
                return callback(null, result);
            }
            if(folderFileExtensions.length){
                fileExtensions = folderFileExtensions.shift();
            }
            //var path = rootFolderPath + '/' + folder;
            var path = rootFolderPath + folder;

            console.log('Scanning:: Full path to folder', path, fileExtensions);

            fs.readdir(path, function (err, list) {
                if (err) {
                    console.error("Error scanning folder: ", path);
                    return scanFolder();
                }

                var files = [];

                for (var i = 0; i < list.length; i++) {
                    if (acceptFile(path, list[i], fileExtensions)) {
                        //files.push((folder.length ? folder + '/' : folder) + list[i]);
                        files.push(path + '/' + list[i]);
                    }
                }

                result = result.concat(files);

                scanFolder();
            });
        }
    }
1299214
async function readDirStructure(dirPath) {
    if (!dirPath) {
        throw new Error('Please specify a path to the directory')
    }
    const lstat = await makePromise(fs.lstat, dirPath)
    if (!lstat.isDirectory()) {
        const err = new Error('Path is not a directory')
        err.code = 'ENOTDIR'
        throw err
    }
    const dir = await makePromise(fs.readdir, dirPath)
    const lstatRes = await lib.lstatFiles(dirPath, dir)

    const directories = lstatRes.filter(isDirectory)
    const notDirectories = lstatRes.filter(isNotDirectory)

    const files = notDirectories.reduce((acc, lstatRes) => Object.assign(acc, {
        [lstatRes.relativePath]: {
            type: getType(lstatRes),
        },
    }), {})

    const dirPromises = directories.map(async ({ path, relativePath }) => {
        const structure = await readDirStructure(path)
        return [relativePath, structure]
    })
    const dirsArray = await Promise.all(dirPromises)
    const dirs = dirsArray.reduce(
        (acc, [relativePath, structure]) => {
            const d = { [relativePath]: structure }
            return Object.assign(acc, d)
        }, {}
    )
    const merged = Object.assign({}, files, dirs)
    return {
        type: 'Directory',
        content: merged,
    }
}
855115
async function archiveWorkingDir(dirPath, archive) {
  // recursively collect all entries (files and directories)
  const allEntries = await collectFSEntries(dirPath, []);

  const process = (entry, cb) => {
    const p = relativePaths(dirPath, entry.path);
    if (p.length) {
      if (entry.stats.isDirectory()) {
        archive.append(null, { name: `${p}/` });
      } else {
        archive.append(fse.createReadStream(entry.path), { name: p });
      }
    }
    cb();
  };

  return new Promise((resolve, reject) => {
    async.eachSeries(
      allEntries,
      process,
      (err) => {
        if (err) {
          reject(err);
        } else {
          resolve(archive);
        }
      },
    );
  });
}
1279505
function( dir ) {
		// Make the root results directory first
		render._mkdir( dir, function( e ) {
			if ( e ) {
				return munit.exit( 1, e, "Failed to make root results directory" );
			}

			// Make a working directory for each format
			async.each( render._formats,
				function( format, callback ) {
					var path = dir + format.name + '/';

					render._mkdir( path, function( e ) {
						if ( e ) {
							callback( e );
						}
						else {
							format.callback( path, callback );
						}
					});
				},
				function( e ) {
					if ( e ) {
						munit.exit( 1, e );
					}
					else {
						render._complete();
					}
				}
			);
		});
	}
855129
function JSONReporter(dir, config) {
    this._config = config;

    var fileName = config.file || DEFAULT_FILE_NAME;
    this._filePath = path.join(dir, fileName);
}
666450
function load(dirPath) {

    findFiles(dirPath, function(filePath){
        collection.push( require(filePath) );
    })

    function findFiles(dirPath, callback){
        fs.readdir(dirPath, function(err, files) {
            files.forEach(function(file){
                fs.stat(dirPath + '/' + file, function(err, stats) {
                    if(stats.isFile()) {
                        callback(dirPath + '/' + file);
                    }
                    if(stats.isDirectory()) {
                        getDirectoryFiles(dirPath + '/' + file, callback);
                    }
                });
            });
        });
    }
}
453861
function (dir, done) {
  var results = [];
  fs.readdir(dir, function (err, list) {
    if (err) return done(err);
    var i = 0;
    (function next() {
      var file = list[i++];
      if (!file) return done(null, results);
      file = dir + '/' + file;
      fs.stat(file, function (err2, stat) {
        if (stat && stat.isDirectory()) {
          walk(file, function (err3, res) {
            results = results.concat(res);
            next();
          });
        } else {
          results.push(file);
          next();
        }
      });
    })();
  });
}
319960
function processDirectory(directory: string) {
      // If we were rejected then we should not continue.
      if (rejected === true) {
        return;
      }
      // We are now waiting on this asynchronous task.
      waiting++;
      // Read the directory...
      fs.readdir(directory, (error, fileNames) => {
        if (error) {
          return reject(error);
        }
        // Process every file name that we got from reading the directory.
        for (let i = 0; i < fileNames.length; i++) {
          processFilePath(directory, fileNames[i]);
        }
        // We are done with this async task.
        done();
      });
    }
203563
function(dir, files){		
		fs.readdirSync(dir).forEach(function(file){
			try{
				var current = path.join(dir, file);
				var stat = fs.statSync(current);
				if (stat && stat.isDirectory()) {
					getAllFiles(current, files);
				}else {
				    files.push(current);
				}
			}catch(e){
				console.error(e);
			}
        });
	}
1371658
function processFile(fPath, context) {
    if (context.included[fPath])
        return;
    context.included[fPath] = true;

    var relPath = path.relative(context.root, fPath);
    context.write("/* " + relPath + ": begin [depth " + context.includeStack.length + "] */\n", "utf-8");
    context.includeStack.push(relPath);

    var parsedFile = context.filetype.parse(fPath);
    parsedFile.forEach(function(item) {
        if (Buffer.isBuffer(item)) {
            context.write(item);
            return;
        }
        try {
            context.filetype.process(fPath, item, context);
        } catch(ex) {
            console.error("------------");
            console.error(JSON.stringify(item));
            throw ex;
        }
    });

    context.includeStack.pop();
    context.write("/* " + relPath + ": end */\n", "utf-8");

    return parsedFile;
}
1138936
function targetPath(fromPath, basePath, targetDirectory) {
  // console.log('targetPath:fromPath: ' + fromPath);
  // console.log('targetPath:basePath: ' + basePath);
  // console.log('targetPath:targetDirectory: ' + targetDirectory);
  var relativePath = path.relative(basePath, fromPath);
  // console.log('targetPath:relativePath: ' + relativePath);
  // console.log('targetPath: ' + path.resolve(targetDirectory, relativePath));
  return path.resolve(targetDirectory, relativePath);
}
654793
function calculateNewBaseUrls(filePath, root, lookUp) {
  if (!path.isAbsolute(filePath)) {
    throw new Error(`Non-absolute path given to calculateNewBaseUrls: '${filePath}'`);
  }
  if (!pathIsInside(filePath, root)) {
    throw new Error(`Path given '${filePath}' is not in root '${root}'`);
  }
  function calculate(file, result) {
    if (file === root) {
      return { relative: path.relative(root, root), parent: root };
    }
    const parent = path.dirname(file);
    if (lookUp[parent] && result.length === 1) {
      return { relative: path.relative(parent, result[0]), parent };
    } else if (lookUp[parent]) {
      return calculate(parent, [parent]);
    }
    return calculate(parent, result);
  }

  return calculate(filePath, []);
}
267595
function(basePath, output_extension, options, callback) {
		var self = this;
		var collected_contents = {};
		var content_options = {};
		var last_modified = null;

		// treat files with special output extensions
		if (output_extension !== ".html") {
			basePath = basePath + output_extension;
		}

		self.getContent(basePath, function(err, contents, modified_date) {
			if (!err) {
				collected_contents = _.extend(collected_contents, contents);
				last_modified = modified_date;

				var run_callback = function() {
					return callback(null, collected_contents, content_options, last_modified);
				};

				//fetch shared content
				self.getSharedContent(function(err, shared_content, shared_modified_date) {
					if (!err) {
						collected_contents = _.extend(shared_content, collected_contents);
						if (shared_modified_date > last_modified) {
							last_modified = shared_modified_date;
						}
					}

					return run_callback();
				});
			} else {
				return callback("[Error: Content for " + basePath + " not found]", null, null, {});
			}
		});
	}
323444
function getDirectories (basePath, includeFiles, userSuppliedFilterFn) {

  var items;
  try {
    items = fs.readdirSync(basePath);
  }
  catch (err) {

    // probably a file not a dir, but let's check error message to be sure
    if (includeFiles && String(err.stack).match(/ENOTDIR/)) {
      return [ basePath ];
    }

    // something is wrong, perhaps directory read permissions problem
    // maybe throw err instead
    console.error(err.stack);
    return [];
  }

  return items.filter(function (file) {

    var absPath = path.join(basePath, file);

    var stats = fs.lstatSync(absPath);
    if (stats.isSymbolicLink()) {
      return false;
    }

    var isDir = includeFiles ? true : stats.isDirectory();
    var isNotDotFile = path.basename(file).indexOf('.') !== 0;
    return isDir && isNotDotFile && (userSuppliedFilterFn || allOK)(absPath);

  })
  .map(function (item) {
    // return path.join(basePath, item);
    return item;
  })
  .sort();
}
674687
function readdirAsync(filepath){
	return new Promise((resolve, reject)=>{
		fs.readdir(filepath, (err, items)=>{
			if (err) reject(err)
			else resolve(items)
		})
	})
}
917630
function(dirPath, callback) {

            if (!dirPath || typeof dirPath !== 'string') {
                callback("dirPath must be a string");
            } else {
                fs.readdir(dirPath, function(err, list) {
                    var dir = [];

                    if (err) {
                        callback(err, null);
                    } else {
                        list.forEach(function(item) {
                            dir.push(readNode(path.join(dirPath, item)));
                        });

                        callback(null, dir);
                    }

                });
            }

        }