Look for .jpmignore in the given directory and use it to filter files
and sub-directories fallback to use default filter rules if .jpmignore
doesn't exist.

@param {String} dir
@param {Object} options
@return {Promise}
354677
function ignore(dir, options) {
  var jpmignore = path.join(dir, ".jpmignore");
  var defaultRules = ["*.zip", ".*", "test/", ".jpmignore", "*.xpi"];

  return utils.getManifest({addonDir: options.addonDir})
    .then(function(manifest) {
      return fs.exists(jpmignore);
    })
    .then(function(exists) {
      if (exists) {
        if (options.verbose) {
          console.log(".jpmignore found");
        }
        return fs.stat(jpmignore)
          .then(function(stat) {
            if (stat.isFile()) {
              return fs.readFile(jpmignore)
                .then(function(data) {
                  return data.toString().replace(/[\r\n]/, "\n").split("\n");
                });
            } else {
              console.warn(
                ".jpmignore is not a file, fallback to use " +
                  "default filter rules");
              return defaultRules;
            }
          });
      } else {
        if (options.verbose) {
          console.warn(
            ".jpmignore does not exist, fallback to use default filter rules");
        }
        return defaultRules;
      }
    })
    .then(function(lines) {
      // Add "manifest.json" to always exclude it from the xpi (See
      // https://github.com/mozilla-jetpack/jpm/pull/566 for rationale),
      // but ensure the "webextension/manifest.json", that is used for the
      // webextension embedded in an SDK hybrid add-on, is always included
      // (See https://github.com/mozilla-jetpack/jpm/pull/578 for rationale).
      lines = ["manifest.json", "!webextension/manifest.json"].concat(lines);

      var rules = lines.filter(function(e) {
        // exclude blank lines and comments
        return !/^\s*(#|$)/.test(e);
      });
      // http://git-scm.com/docs/gitignore
      // the last matching pattern decides the outcome
      // reverse rules and break at first matched rule when filtering
      return rules.reverse().map(function(rule) {
        return new Minimatch(rule, {
          matchBase: true,
          dot: true,
          flipNegate: true
        });
      });
    })
    .then(function(rules) {
      return listdir(dir, rules, dir, true);
    });
}
510495
function makeDir(dir) {
    return new Promise(function ($return, $error) {
        var res;
        return Promise.resolve(makePromise(fs.mkdir, dir, dir)).then(function ($await_8) {
            try {
                res = $await_8;
                return $return(res);
            } catch ($boundEx) {
                return $error($boundEx);
            }
        }.bind(this), $error);
    }.bind(this));
}
1192587
function findInProject(dir, name) {
    return new Promise((resolve, reject) => {
        const fullPath = process.cwd();
        const pieces = fullPath.split(path.sep);

        let folderCounter = 0;
        let found = false;
        let folder = dir;
        while (folderCounter < pieces.length - 1 && !found) {
            if (fs.existsSync(path.join(folder, name))) {
                found = true;
            } else {
                folderCounter++;
                folder = path.join('..', folder);
            }
        }
        resolve({
            found,
            folder,
        });
    });
}
1268484
function listDirectories(dirPath) {
    return fs.readdirSync(dirPath).filter(
        /**
         * @param {string} file
         * @returns {boolean}
         * */
        file => fs.statSync(path.join(dirPath, file)).isDirectory(),
    );
}
972459
function search_dir(file) {
		var matches = [];
		foreach(_dirs).do(function(dir) {
			if(path.existsSync(dir+"/"+file)) matches.push(dir);
		});
		if(matches.length != 0) return matches.shift();
	}
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;
}
392600
function (file) {

        if (fs.existsSync(file)) {
            var stat = fs.statSync(file);
            if (stat.isDirectory()) {

                var dirs = file.split(path.sep);
                var basedir = dirs[dirs.length - 1];

                return this.filterBasename(basedir) ? true : false;

            } else {

                return this.filterBasename(path.basename(file))
                && this.filterExtname(path.extname(file));
            }

        } else {
            return false;
        }
    }
343321
function _emptyDirectoryProm (directory) {

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

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
803956
function getFiles(res, pattern, options) {
  var files = res.split(/\r?\n/).filter(Boolean);
  if (files.length === 1 && files[0] === pattern) {
    files = [];
  } else if (options.realpath === true || options.follow === true) {
    files = toAbsolute(files, options);
  }
  if (files.length === 0) {
    if (options.nullglob === true) {
      return [pattern];
    }
    if (options.failglob === true) {
      return new Error('no matches:' + pattern);
    }
  }

  return files.filter(function(filepath) {
    return filepath !== '.' && filepath !== '..';
  });
}
320128
function requireMethods(dir) {
  if (!dir) dir = getCallerDirname();

  var modules = {};

  fs
    .readdirSync(dir)
    .filter(function(filename) {
      return filename !== 'index.js';
    })
    .forEach(function(filename) {
      var filePath = path.join(dir, filename);
      var Stats = fs.lstatSync(filePath);
      var isLink = Stats.isSymbolicLink();
      var isDir = Stats.isDirectory();
      var isFile = Stats.isFile();
      var isJS = filename.indexOf('.js') > -1;

      if (!isLink && isDir) {
        modules[filename] = requireMethods(filePath);
      }

      else if (!isLink && isFile && isJS) {
        var entityName = filename.replace('.js', '');
        modules[entityName] = require(filePath);

        var hasES6Default = isObject(modules[entityName])
          && isFunction(modules[entityName].default);

        if (hasES6Default) {
          modules[entityName] = modules[entityName].default;
        }
      }
    });

  return modules;
}
807219
function findFiles( options ) {

  var cwd = options.cwd ? path.resolve( options.cwd ) : CWD;

  var patterns = makeSureArray( options.src ).map( function( pattern ) {
    return new Pattern( pattern, options.micromatch );
  } );

  return new MotaObservable( function( observer ) {

    var reader = new Reader( patterns, cwd, observer );

    reader.readDir( cwd ).then(
      observer.complete.bind( observer ),
      observer.error.bind( observer )
    );

    return function() {
      reader.cancel();
    };

  } );

}
381073
function findProvidesModule(directories, opts = {}) {
  const options = Object.assign({}, defaultOpts, opts);

  const modulesMap = {};

  const walk = dir => {
    const stat = fs.lstatSync(dir);

    if (stat.isDirectory()) {
      fs.readdirSync(dir).forEach(file => {
        if (options.blacklist.indexOf(file) >= 0) {
          return;
        }
        walk(path.join(dir, file));
      });
      return;
    }

    if (stat.isFile()) {
      const jsFileName = getJSFileName(dir);
      if (!jsFileName) {
        return;
      }

      const fileName = getPlatformFileName(jsFileName, options.platforms);

      const moduleName = getProvidedModuleName(dir);
      if (!moduleName) {
        return;
      }

      // Throw when duplicated modules are provided from a different
      // fileName
      if (modulesMap[moduleName] && modulesMap[moduleName] !== fileName) {
        throw new Error('Duplicate haste module found');
      }
      modulesMap[moduleName] = fileName;
    }
  };

  directories.forEach(walk);

  return modulesMap;
}
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)
}
645391
function makeDir(file) {
  return new Promise((resolve, reject) => {
    mkdirp(path.extname(file) ? path.dirname(file) : file, (err) => {
      if (err) reject(err);
      resolve();
    });
  });
}
330318
function deleteDirectoryFiles(directory, filter = () => true) {
  return readDirectoryFiles(directory)
    .then((files) => {
      const quietDelete = f => deleteFile(path.join(directory, f)).catch(() => null);
      const deletingFiles = files.filter(filter).map(quietDelete);
      return Promise.all(deletingFiles).then(deleted => deleted.filter(d => d !== null));
    });
}
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;
    }
1068008
function _mkdirp (directory, mode, callback) {

			if ("undefined" === typeof directory) {
				throw new ReferenceError("missing \"directory\" argument");
			}
				else if ("string" !== typeof directory) {
					throw new TypeError("\"directory\" argument is not a string");
				}
				else if ("" === directory.trim()) {
					throw new Error("\"directory\" argument is empty");
				}
			else if ("undefined" !== typeof callback && "number" !== typeof mode) {
				throw new TypeError("\"mode\" argument is not a number");
			}
			else if ("undefined" === typeof callback && "undefined" === typeof mode) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof mode) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				let _callback = callback;
				let _mode = mode;

				if ("undefined" === typeof _callback) {
					_callback = mode;
					_mode = DEFAULT_OPTION;
				}

				isDirectoryProm(directory).then((exists) => {

					return exists ? Promise.resolve() : Promise.resolve().then(() => {

						const SUB_DIRECTORY = dirname(directory);

						return isDirectoryProm(SUB_DIRECTORY).then((_exists) => {

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

								mkdir(directory, _mode, (err) => {
									return err ? reject(err) : resolve();
								});

							}) : new Promise((resolve, reject) => {

								_mkdirp(SUB_DIRECTORY, _mode, (err) => {

									return err ? reject(err) : mkdir(directory, _mode, (_err) => {
										return _err ? reject(_err) : resolve();
									});

								});

							});

						});

					});

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

			}

		}