Newer
Older
CVSS_3.0_GUI / dist / CVSS_3.0_Calc-1.0.0-linux-x64 / node_modules / nwjs-builder-phoenix / node_modules / yargs / node_modules / read-pkg-up / node_modules / find-up / index.js
root on 7 May 2019 951 bytes Initial commit
  1. 'use strict';
  2. var path = require('path');
  3. var pathExists = require('path-exists');
  4. var Promise = require('pinkie-promise');
  5.  
  6. function splitPath(x) {
  7. return path.resolve(x || '').split(path.sep);
  8. }
  9.  
  10. function join(parts, filename) {
  11. return path.resolve(parts.join(path.sep) + path.sep, filename);
  12. }
  13.  
  14. module.exports = function (filename, opts) {
  15. opts = opts || {};
  16.  
  17. var parts = splitPath(opts.cwd);
  18.  
  19. return new Promise(function (resolve) {
  20. (function find() {
  21. var fp = join(parts, filename);
  22.  
  23. pathExists(fp).then(function (exists) {
  24. if (exists) {
  25. resolve(fp);
  26. } else if (parts.pop()) {
  27. find();
  28. } else {
  29. resolve(null);
  30. }
  31. });
  32. })();
  33. });
  34. };
  35.  
  36. module.exports.sync = function (filename, opts) {
  37. opts = opts || {};
  38.  
  39. var parts = splitPath(opts.cwd);
  40. var len = parts.length;
  41.  
  42. while (len--) {
  43. var fp = join(parts, filename);
  44.  
  45. if (pathExists.sync(fp)) {
  46. return fp;
  47. }
  48.  
  49. parts.pop();
  50. }
  51.  
  52. return null;
  53. };
Buy Me A Coffee