Process arguments, recursing through any directories,
to find and validate JSON files

@param {array} args Array of paths
@param {array} files Array to populate

@return {array} File objects to be processed
557130
function processArgs(args, files = []) {
  return args.reduce((acc, arg) => {
    let stats;
    try {
      stats = fs.statSync(arg);
    } catch (err) {
      // Do nothing
    }

    // If argument is a directory, process the files inside
    if (stats && stats.isDirectory()) {
      return processArgs(
        fs.readdirSync(arg).map(file => path.join(arg, file)),
        files
      );
    }

    // If `statSync` failed, validating will handle the error
    // If the argument is a file, check if its a JSON file before validating
    if (!stats || JsonFileRegex.test(arg)) {
      acc.push(validateFile(arg));
    }

    return acc;
  }, files);
}
1101878
function processFilePath(directory: string, fileName: string) {
      // If we were rejected then we should not continue.
      if (rejected === true) {
        return;
      }
      // We are now waiting on this asynchronous task.
      waiting++;
      // Get the file file path for this file.
      const filePath = path.join(directory, fileName);
      // Get the stats for the file.
      fs.lstat(filePath, (error, stats) => {
        if (error) {
          return reject(error);
        }
        // If this is a directory...
        if (stats.isDirectory()) {
          // ...and it is not an ignored directory...
          if (
            fileName !== 'node_modules' &&
            fileName !== 'flow-typed' &&
            fileName !== '__flowtests__'
          ) {
            // ...then recursively process the directory.
            processDirectory(filePath);
          }
        } else if (stats.isFile()) {
          // Otherwise if this is a JavaScript/JSX file and it is not an ignored
          // JavaScript file...
          const fileIsJsOrJsx = /\.jsx?$/.test(fileName);
          const fileIsIgnored = fileName.endsWith('-flowtest.js');
          if (fileIsJsOrJsx && !fileIsIgnored) {
            // Then process the file path as JavaScript.
            processJavaScriptFilePath(filePath, stats.size);
          }
          // If this is a Flow file then we don't need to check the file pragma
          // and can add the file to our paths immediately.
          if (fileName.endsWith('.flow')) {
            filePaths.push(filePath);
          }
        }
        // We are done with this async task
        done();
      });
    }
557835
function _filesToFile (files, target, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const _target = target.trim();

				if ("" === _target) {
					throw new Error("\"target\" argument is empty");
				}
				else {

					const _callback = "undefined" === typeof callback ? separator : callback;

					Promise.resolve().then(() => {
						return isFileProm(_target);
					}).then((exists) => {

						return !exists ? Promise.resolve() : new Promise((resolve, reject) => {

							fs.unlink(_target, (err) => {
								return err ? reject(err) : resolve();
							});

						});

					}).then(() => {

						if (!files.length) {

							return new Promise((resolve, reject) => {

								fs.writeFile(_target, "", (err) => {
									return err ? reject(err) : resolve();
								});

							});

						}
						else {

							return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {

								return new Promise((resolve, reject) => {

									let error = false;
									readStream.once("error", (_err) => {
										error = true; reject(_err);
									}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
										error = true; reject(_err);
									}).once("close", () => {

										if (!error) {
											resolve();
										}

									}));

								});

							});

						}

					}).then(() => {
						_callback(null);
					}).catch(_callback);

				}

			}

		}
752231
function explode ( filepaths ) {
		var json, res = [];
		filepaths.filter ( existence ).forEach ( function ( filepath ) {
			switch ( path.extname ( filepath )) {
				case ".json" :
					json = grunt.file.readJSON ( filepath );
					res.push.apply ( res, json.map ( function ( localpath ) {
						return path.dirname ( filepath ) + "/" + localpath;
					}));
					break;
				case ".js" :
					res.push ( filepath );
					break;
			}
		});
		return res;
	}
904010
async function getFileInput(args) {
    if (typeof args.in !== 'string') {
        return null;
    }
    // Let any errors fall through to the runProgram() promise
    return JSON.parse(await txtfile.read(path.resolve(args.in)));
}
904819
function watchPaths(args) {
    var result = distinguishPaths(args.path)
    if (result.directories.length) {
      result.directories.forEach(function(directory) {
        watchDirectory(extend(args, {root: directory}));
      });
    }
    if (result.files.length)
      watchFiles(extend(args, {files: result.files}));
  }
753942
function processHtmlToJson(files, options) {
    options = grunt.util._.defaults(options || {}, {
      separator: grunt.util.linefeed
    });
    var ret = {};

    files.map(function(filepath) {
      if (!grunt.file.isDir(filepath)) {
        var filenames = filepath.split('/');
        ret[filepath]= grunt.file.read(filepath, grunt.file.read);
      }
    });

    return ret;
  }
530064
function processThunkArgs( args ) {
    let length = args.length | 0;

    if( length >= 3 ) {
        let res = new Array( --length );

        for( let i = 0; i < length; ) {
            res[i] = args[++i]; //It's a good thing this isn't undefined behavior in JavaScript
        }

        return res;
    }

    return args[1];
}
409023
function gist (options, callback) {
  if (!options.id) return callback(new Error('missing option: id'))

  request({
    url: '/gists/' + options.id,
    qs: {
      access_token: options.token
    }
  }, function (err, json) {
    if (err) return callback(err)

    var results = []

    async.forEachOf(json.files, function (item, key, callback) {
      processGithubFile({
        item: item,
        key: key,
        json: json
      }, function (err, geojson) {
        if (err) return callback(err)
        if (geojson) results.push(geojson)
        callback(null)
      })
    }, function (err) {
      if (err) return callback(err)
      if (!results.length) return callback(new Error('no geojson found in gist ' + options.id))
      callback(null, results)
    })
  })
}
1077972
function iterateFiles (dir, options, cb) {
  var iterateOptions = {
    ext: [], // extensions to look for
    dirs: false, // do callback for dirs too
    skip_: true, // skip files & dirs starting with _
    recursive: true // do a recursive find
  }

  options = deepMerge(iterateOptions, options)
  // console.log('options: ' + JSON.stringify(options))
  iterateRecurse(dir, options, cb)
}
897887
function(callback){
    var argFiles,
        filePath,
        i;

    if(!program.files || program.files.length === 0){
        return callback(null, true);
    }

    argFiles = program.files.split(',');

    output("Loading files...");

    for(i=0; i<argFiles.length; i++){
        filePath = path.resolve(__dirname, argFiles[i].toString());
        output("Reading file..." + filePath);
        if(fs.existsSync(filePath)){
            files.push(fs.readFileSync(filePath));
        }else{
            return callback("File does not exist, " + filePath, false);
        }
    }

    callback(null, true);
}
207065
function extractFolders( files ) {
    return files.data.files.map( function extractPath( file ) {
      return path.parse( file ).dir;
    }).filter( function extractUnique( path, index, array ) {
      return array.indexOf( path ) === index;
    });
  }
734221
function (files) {
    if (!_.isArray(files)) files = [files];
    return _.chain(files).map(fss.target).map(function (f) {
        if (!fss.directoryExists(f)) return f;
        return fss.allTargetFilePaths(f);
    }).flatten().uniq().reject(fss.isDotFile).map(pathSuffix).value();
}
704949
private static String[] addSrcBeforeDirectories(String[] args) {
        List<String> newargs = new ArrayList<String>();
        for (int i = 0; i<args.length; ++i) {
            File dir = new File(args[i]);
            if (dir.exists() && dir.isDirectory()) {
                if (i == 0 || !shouldBeFollowedByPath(args[i-1])) {
                    newargs.add("-src");
                }
            }
            newargs.add(args[i]);
        }
        return newargs.toArray(new String[0]);
    }
1126590
def process_files
      if @options[:parallel].empty?
        files.map { |path| check_path(path) }
      else
        Parallel.map(files, @options[:parallel]) { |path| check_path(path) }
      end
    end
1035958
function run(files, options) {
        // If translations or templates are not supplied then error
        if (options.translations.length === 0) {
            grunt.fail.fatal('Please supply translations');
        }

        // If a missing translation regex has been supplied report the missing count
        if (options.missingTranslationRegex !== null) {
            linter.setMissingTranslationRegex(options.missingTranslationRegex);
        }

        // Add the translation keys to the linter
        options.translations.forEach(function(file) {
            var files = grunt.file.expand(file);

            files.forEach(function(file) {
                if (!grunt.file.exists(file)) {
                    grunt.fail.fatal('File ' + file + ' does not exist');
                }
                linter.addKeys(grunt.file.readJSON(file));
            });
        });

        // Iterate through files and run them through the linter
        files.forEach(function(file) {
            if (!grunt.file.exists(file)) {
                grunt.fail.fatal('File ' + file + ' does not exist');
            }
            linter.check(grunt.file.read(file));
        });
    }
711574
function parse_files(files, options, callback) {
  var nodes = {
    // root section node
    '': {
      id: '',
      type: 'section',
      children: [],
      description: '',
      short_description: '',
      href: '#',
      root: true,
      file: '',
      line: 0
    }
  };

  var reportObject = { };
  
  async.forEachSeries(files, function (file, next_file) {
    var fn = parsers[path.extname(file)];

    if (!fn) {
      next_file();
      return;
    }

    console.info('Parsing file: ' + file);
    fn(file, options, function (err, file_nodes, file_report) {
      // TODO:  fail on name clash here as well -- as we might get name clash
      //        from different parsers, or even different files
      _.extend(nodes, file_nodes);
      _.extend(reportObject, file_report);
      next_file(err);
    });
  }, function (err) {
    callback(err, nodes, reportObject);
  });
}