NB: files are either added, modified, or removed
@param  {Object} resource - A GitHub resource
@return {Array} An array of pull request files
518435
function getPullRequestFiles(resource) {
  return github.pullRequests
    .getFiles({
      owner: resource.owner,
      repo: resource.repo,
      number: resource.number,
      per_page: 100
    })
    .then(function(res) {
      return res.data;
    });
}
657043
function collectInputFiles(pattern) {
  return new Promise((resolve, reject) => {
    glob(pattern, {root: SRC_DIR, nomount: true}, (err, files) => {
      if (err) {
        return reject(err);
      }
      resolve(files);
    });
  });
}
623305
function() {
				var file = this.getSource().getSource();
				return plupload.inArray(plupload.typeOf(file), ['blob', 'file']) !== -1 ? file : null;
			}
327664
function() {
            // Get the resource's new metadata
            self.resources.get(createdResource.id, function(err, resource) {
                if (err) {
                    return callbacks.error(err);
                }

                // Check thumbnails
                var thumbnailsDone = _.chain(resource.thumbnails)
                    .filter({'status': 'pending'})
                    .isEmpty()
                    .value();
                if (thumbnailsDone) {
                    callbacks.thumbnails(resource.thumbnails);
                }

                // Check the images
                var imagesDone = _.chain(resource.images)
                    .filter({'status': 'pending'})
                    .isEmpty()
                    .value();
                if (imagesDone) {
                    callbacks.images(resource.images);
                }

                // If there are no pending processors left, we're done and can return to the caller
                if (resource.status !== 'pending') {
                    return callbacks.complete(resource);

                // Continue polling as long as there are still pending processors
                } else {
                    // Add a quarter of the polling timeout each time we check whether new updates
                    // are available. This will ensure that the interval gradually backs off.
                    pollingTimeout += Math.round(pollingTimeout / Embdr.DEFAULT_POLLING_BACKOFF_DENOMINATOR);
                    if (pollingTimeout > Embdr.MAX_POLLING_TIMEOUT) {
                        pollingTimeout = Embdr.MAX_POLLING_TIMEOUT;
                    }
                    setTimeout(poll, pollingTimeout);
                }
            });
        }
437775
async function getPrFiles(mrNo) {
  logger.debug({ mrNo }, 'getPrFiles');
  if (!mrNo) {
    return [];
  }
  const files = (await get(
    `projects/${config.repository}/merge_requests/${mrNo}/changes`
  )).body.changes;
  return files.map(f => f.new_path);
}
1141930
function filesInRepository(dir) {
        var ignoreDirs = cog.getOption('ignore_dirs');
        // TODO: Allow an array and move to config.
        var ignoreFiles = /~$/;
        var files = glob.sync(dir ? dir + '/*' : '*');
        var ret = [];
        for (var i = 0; i < files.length; i++) {
            if (fs.lstatSync(files[i]).isDirectory()) {
                // Ignore standard directories of uninterest.
                if (!dir && ignoreDirs.indexOf(files[i]) >= 0) {
                    continue;
                }
                ret = filesInRepository(files[i]).concat(ret);
            } else {
                if (!ignoreFiles.test(files[i])) {
                    ret.push(files[i]);
                }
            }
        }
        return ret;
    }
20914
function bundler(options) {
        var allFiles = {};
        var bundles = {};
        var dir = options.src;
        var dest = options.dest;
        var resourcesFile = options.resourceJson;
        var indexBundles = options.indexBundles;
        var titleIndexBnudles = {};
        var traversed_bundles = {}, traversed_files = {}, excluded_bundles = {};
        var resourcesJs = {};
        for (var key in options) {
            resourcesJs[key] = options[key];
        }
        resourcesJs.bundles = bundles;

        function getFiles(packageName, files, bundledFile, includedBundles) {
            if (!traversed_bundles[packageName] && !excluded_bundles[packageName]) {
                traversed_bundles[packageName] = true;
                var bundle = resourcesJs.bundles[packageName];
                if (bundle) {
                    bundle.bundled = bundle.bundled || [];
                    bundle.bundled_html = bundle.bundled_html || [];
                    bundle.in = bundle.in || [];
                    for (var i in bundle.on) {
                        files = getFiles(bundle.on[i], files, bundledFile, includedBundles);
                    }
                    for (var j in bundle.js) {
                        var _file2 = cleanURL(dir + "/" + bundle.js[j]);
                        if (!traversed_files[_file2]) {
                            files.js.push(_file2);
                            traversed_files[_file2] = packageName;
                        }
                    }
                    if (files.js.length > 0) {
                        bundle.bundled.push(bundledFile + ".js");
                    }

                    for (var i in bundle.html) {
                        var _file = cleanURL(dir + "/" + bundle.html[i]);
                        if (!traversed_files[_file]) {
                            files.html.push(_file);
                            traversed_files[_file] = packageName;
                        }
                    }
                    if (files.html.length > 0) {
                        bundle.bundled_html.push(bundledFile + ".html");
                    }

                    includedBundles.push(packageName);
                }
            }
            return files;
        }

        if (TASK_BUNDLIFY || TASK_SCAN) {
            grunt.file.recurse(dir, function(abspath, rootdir, subdir, filename) {
                if (filename === "module.json" && abspath.indexOf(dest) !== 0) {
                    var packageInfo = {};
                    if (grunt.file.exists(subdir + "/.bower.json")) {
                        var bowerJson = grunt.file.readJSON(subdir + "/.bower.json");
                        packageInfo.bowerName = bowerJson.name;
                        packageInfo.bowerVersion = bowerJson.version;
                    }
                    if (grunt.file.exists(subdir + "/composer.json")) {
                        var composerJson = grunt.file.readJSON(subdir + "/composer.json");
                        packageInfo.composerName = composerJson.name;
                        packageInfo.composerVersion = composerJson.version;
                    }
                    var _bundles = grunt.file.readJSON(abspath);
                    var packageName = _bundles.name;
                    if (_bundles.exclude) {
                        for (var i in _bundles.exclude) {
                            excluded_bundles[_bundles.exclude[i]] = true;
                        }
                    }
                    if (packageName !== undefined) {
                        titleIndexBnudles[packageName] = [];
                        for (var bundleName in _bundles) {
                            if ((bundleName === packageName || bundleName.indexOf(packageName + "/") === 0) && !excluded_bundles[bundleName]) {
                                if (bundles[bundleName]) {
                                    console.log("====Duplicate Package", bundleName);
                                } else if (!toIgnore(bundleName)) {
                                    titleIndexBnudles[packageName].push(bundleName);
                                }
                                bundles[bundleName] = { js: [], on: [], css: [], html: [], packageInfo: packageInfo};
                                for (var file_i in _bundles[bundleName].js) {
                                    var js_file = subdir + "/" + _bundles[bundleName].js[file_i];
                                    bundles[bundleName].js.push(js_file);
                                    if (!allFiles[js_file]) {
                                        allFiles[js_file] = js_file;
                                    } else {
                                        console.log("====Duplicate File" + js_file);
                                    }
                                }
                                for (var file_j in _bundles[bundleName].css) {
                                    var css_file = subdir + "/" + _bundles[bundleName].css[file_j];
                                    bundles[bundleName].css.push(css_file);
                                    if (!allFiles[css_file]) {
                                        allFiles[css_file] = css_file;
                                    } else {
                                        console.log("====Duplicate File" + css_file);
                                    }
                                }
                                for (var file_k in _bundles[bundleName].html) {
                                    var html_file = subdir + "/" + _bundles[bundleName].html[file_k];
                                    bundles[bundleName].html.push(html_file);
                                    if (!allFiles[html_file]) {
                                        allFiles[html_file] = html_file;
                                    } else {
                                        console.log("====Duplicate File" + html_file);
                                    }
                                }
                                bundles[bundleName].on = _bundles[bundleName].on || [];
                                console.log("╬═╬ Module.json", abspath);
                                //console.log(bundleName, _bundles[bundleName].on);
                            }
                        }
                    }
                }
            });


            var titleIndexBnudlesNames = Object.keys(titleIndexBnudles);

            if (options.modulize) {
                titleIndexBnudlesNames.map(function(bundName) {
                    if (!bundles[bundName] && !toIgnore(bundName)) {
                        bundles[bundName] = { js: [], on: titleIndexBnudles[bundName], css: [], html: [], packageInfo: {}};
                        console.log("New Package ", bundName, bundles[bundName]);
                    }
                });
            }

            for (var packageKey in excluded_bundles) {
                delete bundles[packageKey];
            }

            var firstIndexBundled = null;

            if (!TASK_SKIP_INIT) {
                var myIndexBnudles = indexBundles;
                if (TASK_BUNDLIFY) {

                    var moreBundles = Object.keys(bundles);

                    if (options.sort) {
                        moreBundles = moreBundles.sort();
                    }

                    if (options.projectPrefix !== undefined) {
                        myIndexBnudles = uniqueArray(myIndexBnudles.concat(titleIndexBnudlesNames.concat(moreBundles).filter(function(bundleName) {
                            return bundleName.indexOf(options.projectPrefix) === 0;
                        })));
                    }

                    myIndexBnudles = uniqueArray(myIndexBnudles.concat(titleIndexBnudlesNames.concat(moreBundles))).filter(function(bundleName) {
                        return !toIgnore(bundleName);
                    });

                }
                console.log("Bundles in Order", myIndexBnudles);

                var prevBundle = null;
                myIndexBnudles.forEach(function(bundleName) {
                    var _bundleMap = {};
                    var includedBundles = [];
                    var bundledFile = dest + "/bootloader_bundled/" + bundleName.split("/").join(".");
                    var bundledFile_js = bundledFile + ".js";
                    var files = getFiles(bundleName, {js: [], html: []}, bundledFile, includedBundles);
                    var js_files = uniqueArray(files.js.reverse()).reverse();
                    if (js_files.length > 0) {
                        if (!firstIndexBundled && options.resourcesInline) {
                            firstIndexBundled = bundleName;
                            js_files.unshift(resourcesFile + ".js");
                        }
                        _bundleMap[bundledFile_js] = js_files;
                        //console.log("files",bundleName,files.length,files);
                        setBundleConfig(bundleName, _bundleMap, includedBundles, bundledFile_js);

                        if (prevBundle && options.order) {
                            var bundle = resourcesJs.bundles[bundleName];
                            if (bundle) {
                                bundle.on = [prevBundle].concat(bundle.on);
                            }
                        }
                        prevBundle = bundleName;

                    } else console.log("╬═╬ No File in bundle to bundlify thus skipping ", bundleName);

                    var html_files = uniqueArray(files.html.reverse()).reverse();
                    if (html_files.length) {
                        var html_file_content = "";
                        for (var i in html_files) {
                            html_file_content += '<script type="text/html" src="' + html_files[i] + '">' + grunt.file.read(html_files[i]).split("\t").join("")
                                .split("\n").join(" ")
                                .split(">").map(function(v) {
                                    return v.trim();
                                }).join(">") + '</script>';
                        }
                        grunt.file.write(bundledFile + ".html", html_file_content);
                    }

                });

                resourcesJs.gitinfo = grunt.config().gitinfo;
                if (firstIndexBundled) {
                    var resJsonString = JSON.stringify({
                        RESOURCES_JSON: resourcesJs,
                        RESOURCES_FILE: resourcesFile
                    }).replace(/\r?\n|\r|\\n/g, ' ');

                    var packed = resJsonString;
                    var unpack = "";
                    if(options.jsonpack){
                        var jsonpack = require('jsonpack/main');
                        var fs = require("fs");
                        unpack = grunt.file.read('node_modules/jsonpack/main.js');
                        packed =('(jsonpack.unpack(\''+jsonpack.pack(resJsonString)+'\'))');
                    }

                    grunt.file.write(resourcesFile + ".js", unpack+";var _BOOTLOADER_CONFIG_=" + packed);
                    resourcesJs.bundles[firstIndexBundled].js.unshift(resourcesFile + ".js");
                }

                grunt.task.run("uglify");
            }

            grunt.file.write(resourcesFile, JSON.stringify(resourcesJs));

        }
    }
360443
def extract_files(self, resource):
        
        if hasattr(resource, "__iter__"):
            files = [file for file in resource if self.can_be_extracted(file)]
        elif os.path.isfile(resource):
            files = [resource] if self.can_be_extracted(resource) else []
        else:
            files = self._extract_from_directory(resource)

        return files
156858
function archiveResource(resource, primary, archive) {
        if (!resource.archive) { return true; }

        var name = resource.name;

        primary.bind(name);
        archive.bind(name);

        // get the archive criteria
        var criteria = resource.archive();

        log.info('Getting archive docs for ' + name);

        // find all the documents that match the archive criteria
        return getDocsToArchive(criteria, primary[name])
            .then(function (docs) {

                log.info('Found ' + docs.length + ' ' + name + ' docs to archive');

                // insert all of the documents into the archive database
                var deferred = Q.defer();
                archive[name].insert(docs, function (err, results) {
                    err ? deferred.reject(err) : deferred.resolve(results);
                });
                return deferred.promise;
            })
            .then(function () {

                log.info('Docs inserted into archive DB for ' + name + '. Now deleting docs in main db');

                // delete the data from the primary database
                var deferred = Q.defer();
                primary[name].remove(criteria, function (err, results) {

                    log.info('Deleting docs complete for ' + name);

                    err ? deferred.reject(err) : deferred.resolve(results);
                });
                return deferred.promise;

            });
    }
903618
function loadDeps(file, resource) {
  file.requires.forEach(function(id) {
    resource.add(id);
  });

  file.asyncs.forEach(function(id) {
    resource.add(id, true);
  });
}
1069908
function getDirNamesForDuplicateFiles(files) {
        // Must have at least two files in list for this to make sense
        if (files.length <= 1) {
            return [];
        }

        // First collect paths from the list of files and fill map with them
        var map = {}, filePaths = [], displayPaths = [];
        files.forEach(function (file, index) {
            var fp = file.fullPath.split("/");
            fp.pop(); // Remove the filename itself
            displayPaths[index] = fp.pop();
            filePaths[index] = fp;

            if (!map[displayPaths[index]]) {
                map[displayPaths[index]] = [index];
            } else {
                map[displayPaths[index]].push(index);
            }
        });

        // This function is used to loop through map and resolve duplicate names
        var processMap = function (map) {
            var didSomething = false;
            _.forEach(map, function (arr, key) {
                // length > 1 means we have duplicates that need to be resolved
                if (arr.length > 1) {
                    arr.forEach(function (index) {
                        if (filePaths[index].length !== 0) {
                            displayPaths[index] = filePaths[index].pop() + "/" + displayPaths[index];
                            didSomething = true;

                            if (!map[displayPaths[index]]) {
                                map[displayPaths[index]] = [index];
                            } else {
                                map[displayPaths[index]].push(index);
                            }
                        }
                    });
                }
                delete map[key];
            });
            return didSomething;
        };

        var repeat;
        do {
            repeat = processMap(map);
        } while (repeat);

        return displayPaths;
    }
1131940
function (glob, opts) {
    if (opts.ignore) {
      this.map('exclude', opts.ignore, opts);
    }
    if (opts.exclude) {
      this.map('exclude', opts.exclude, opts);
    }
    if (opts.include) {
      this.map('include', opts.include, opts);
    }

    // if not disabled by the user, run the built-ins
    if (!this.disabled('builtins')) {
      if (!this.disabled('npm')) {
        this.use(npm(opts));
      }
      if (!this.disabled('dotfiles')) {
        this.use(dotfiles()(opts));
      }
      if (!this.disabled('gitignore')) {
        this.use(gitignore()(opts));
      }
    }
  }
615970
function getFiles(base, dir = '', results = []) {
            const files = fs.readdirSync(path.join(base, dir));
            for (const file of files) {
                const relativeToBase = path.join(dir, file);
                if (fs.statSync(path.join(base, relativeToBase)).isDirectory()) {
                    getFiles(base, relativeToBase, results);
                } else {
                    results.push(relativeToBase);
                }
            }
            return results;
        }
313920
function getSourceFilesFromGlob(globPattern, ignoreGlobs) {
    return new Promise((fulfil, reject) => {
        glob(globPattern, { ignore: ignoreGlobs }, (err, files) => {
            if (err) {
                reject(err);
            } else {
                fulfil(files);
            }
        });
    });
}
580340
function parseMissingResources(response) {
  return response.body.data &&
    response.body.data.relationships &&
    response.body.data.relationships['missing-resources'] &&
    response.body.data.relationships['missing-resources'].data || [];
}
546024
function getUnchangedTasks(globs) {
  var prevPaths;
  var nextPaths;
  var unchangedPaths;
  var prevFiles;
  var nextFiles;
  var tasks1;
  var paths1;
  var tasks;
  var paths;

  // time: current
  return getFlatUniquePaths(globs)
    .then(function(res) {
      nextPaths = res;
      return gitCmds.safeStashAll();
    })
    .then(function() {
      // time: prev
      return getFlatUniquePaths(globs);
    })
    .then(function(res) {
      prevPaths = res;
      unchangedPaths = _.intersection(prevPaths, nextPaths);

      if (unchangedPaths.length === 0) {
        return Promise.reject(
          new Error('No Huxleyfile found that is unchanged.')
        );
      }

      // at this point, we got all the `Huxleyfile.json`s directory paths that
      // exist before and after stashing
      return Promise.map(unchangedPaths, loadJSON);
    })
    .then(function(res) {
      prevFiles = res;
      return gitCmds.safeUnstashAll();
    })
    .then(function() {
      // time: current
      return Promise.map(unchangedPaths, loadJSON);
    })
    .then(function(res) {
      // at this point, we read all the `Huxleyfile.json`s of those paths
      nextFiles = res;

      var unchangedContainerPaths = unchangedPaths.map(path.dirname);
      var res1 = filterFilesForUnchangedTasks(
        prevFiles,
        nextFiles,
        unchangedContainerPaths
      );

      // not done! We need to make sure these tasks' `record.json`s actually
      // exist
      return filterExistingRecords(res1[0], res1[1]);
    })
    .spread(function(a, b) {
      tasks1 = a;
      paths1 = b;
      return gitCmds.safeStashAll();
    })
    .then(function() {
      // time: prev
      return filterExistingRecords(tasks1, paths1);
    })
    .spread(function(a, b) {
      tasks = a;
      paths = b;
      return gitCmds.safeUnstashAll();
    })
    .then(function() {
      // time: current
      if (tasks.length === 0) {
        return Promise.reject(new Error('No task found that is unchanged.'));
      }

      return [tasks, paths];
    });
}
408773
function getFiles(dir) {
    var files = [];

    var traverse = function (dir) {
        var dirList = dir.listFiles();
        dirList.forEach(function (file) {
            if (/\.css$/.test(file)) {
                files.push(file);
            } else if (file.isDirectory()) {
                traverse(file);
            }
        });
    };

    traverse(dir);

    return files;
}