function normalizeOptions(options) {
  options = assign({
    dir: null,
    dependencyDir: null,
    json: 'bower.json',
    componentJson: '.bower.json',
    overrides: {},
    isRoot: false
  }, options);

  assert(
    isAbsolute(options.dir || ''),
    'options.dir must be absolute'
  );

  assert(
    isAbsolute(options.dependencyDir || ''),
    'options.dependencyDir must be absolute'
  );

  options.json = (options.isRoot || isSymlink(options.dir))
    ? options.json
    : options.componentJson;

  return options;
}
Beispiel #2
0
module.exports = function(glob, options) {
  // default options
  var opts = options || {};

  // ensure cwd is absolute
  var cwd = path.resolve(opts.cwd ? opts.cwd : process.cwd());
  cwd = unixify(cwd);

  var rootDir = opts.root;
  // if `options.root` is defined, ensure it's absolute
  if (rootDir) {
    rootDir = unixify(rootDir);
    if (process.platform === 'win32' || !isAbsolute(rootDir)) {
      rootDir = unixify(path.resolve(rootDir));
    }
  }

  // trim starting ./ from glob patterns
  if (glob.slice(0, 2) === './') {
    glob = glob.slice(2);
  }

  // when the glob pattern is only a . use an empty string
  if (glob.length === 1 && glob === '.') {
    glob = '';
  }

  // store last character before glob is modified
  var suffix = glob.slice(-1);

  // check to see if glob is negated (and not a leading negated-extglob)
  var ing = isNegated(glob);
  glob = ing.pattern;

  // make glob absolute
  if (rootDir && glob.charAt(0) === '/') {
    glob = join(rootDir, glob);
  } else if (!isAbsolute(glob) || glob.slice(0, 1) === '\\') {
    glob = join(cwd, glob);
  }

  // if glob had a trailing `/`, re-add it now in case it was removed
  if (suffix === '/' && glob.slice(-1) !== '/') {
    glob += '/';
  }

  // re-add leading `!` if it was removed
  return ing.negated ? '!' + glob : glob;
};
module.exports = function stripDirs(pathStr, count, option) {
  option = option || {narrow: false};

  if (arguments.length < 2) {
    throw new Error('Expecting two arguments and more. (path, count[, option])');
  }

  if (typeof pathStr !== 'string') {
    throw new TypeError(pathStr + ' is not a string. First argument must be a path string.');
  }
  if (isAbsolutePath(pathStr)) {
    throw new TypeError(pathStr + ' is an absolute path. A relative path required.');
  }

  if (!isNaturalNumber(count, true)) {
    throw new Error('Second argument must be a natural number or 0.');
  }

  var pathComponents = path.normalize(pathStr).split(path.sep);
  if (pathComponents.length > 1 && pathComponents[0] === '.') {
    pathComponents.shift();
  }

  if (count > pathComponents.length - 1) {
    if (option.narrow) {
      throw new RangeError('Cannot strip more directories than there are.');
    }
    count = pathComponents.length - 1;
  }

  return path.join.apply(null, pathComponents.slice(count));
};
Beispiel #4
0
function getPathInfo(cmd, opt) {
  var colon = opt.colon || COLON
  var pathEnv = opt.path || process.env.Path || process.env.PATH || ''
  var pathExt = ['']

  pathEnv = pathEnv.split(colon)

  var pathExtExe = ''
  if (isWindows) {
    pathEnv.unshift(process.cwd())
    pathExtExe = (opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM')
    pathExt = pathExtExe.split(colon)


    // Always test the cmd itself first.  isexe will check to make sure
    // it's found in the pathExt set.
    if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')
      pathExt.unshift('')
  }

  // If it's absolute, then we don't bother searching the pathenv.
  // just check the file itself, and that's it.
  if (isAbsolute(cmd))
    pathEnv = ['']

  return {
    env: pathEnv,
    ext: pathExt,
    extExe: pathExtExe
  }
}
Beispiel #5
0
function normalizeOptions(options) {
  if (options && typeof options.camelCase !== 'undefined') {
    console.log('bowerFiles.options.camelCase: Use .camelCase(true).');
  }
  options = assign({
    cwd: process.cwd(),
    json: 'bower.json',
    overrides: {},
    componentJson: '.bower.json',
    camelCase: true,
    dir: null
  }, options);

  assert(
    isAbsolute(options.cwd || ''),
    'options.cwd must be an absolute path'
  );

  if (!options.dir) {
    var bowerrc = new BowerConfig(options.cwd).load().toObject();
    options.cwd = untildify(bowerrc.cwd);
    options.dir = untildify(bowerrc.directory);
  }
  options.dir = path.resolve(options.cwd, options.dir);

  return options;
}
const resolveDir = function(dir) {
	dir = path.normalize(dir);
	if (isAbsolute(dir)) {
		return dir;
	}
	return path.join(process.cwd(), dir);
};
function resolver(search, app) {
  try {
    if (isAbsolute(search.name)) {
      search.name = require.resolve(search.name);
    } else {
      search.name = resolve.sync(search.name, {basedir: gm});
    }
    search.app = app.register(search.name, search.name);
  } catch (err) {}
}
Beispiel #8
0
function replaceHomedir(filepath, replacement) {
  if (typeof filepath !== 'string') {
    throw new Error('Path for replace-homedir must be a string.');
  }

  if (!isAbsolute(filepath)) {
    return filepath;
  }

  var home = removeTrailingSep(homedir());
  var lookupHome = home + path.sep;
  var lookupPath = removeTrailingSep(filepath) + path.sep;

  if (lookupPath.indexOf(lookupHome) !== 0) {
    return filepath;
  }

  return filepath.replace(home, replacement);
}
Beispiel #9
0
Template.prototype.cache = function (patterns, options) {
  this.options = _.extend({}, this.options, options);

  if (typeof patterns === 'string' && isAbsolute(patterns)) {
    if (this._cache.hasOwnProperty(patterns)) {
      return this._cache[patterns];
    }
    this.compileFile(patterns, this.options);
    return this;
  }

  glob.sync(patterns, this.options).forEach(function(filepath) {
    filepath = path.resolve(this.options.cwd, filepath);
    if (this._cache.hasOwnProperty(filepath)) {
      return this._cache[filepath];
    }
    this.compileFile(filepath, this.options);
  }.bind(this));
  return this;
};
Beispiel #10
0
module.exports = function parse(fp) {
  if (typeof fp !== 'string') {
    throw new Error('parse-filepath expects a string.');
  }

  if (cache.has(fp)) {
    return cache.get(fp);
  }

  var res = { path: fp, isAbsolute: isAbsolute(fp) };
  var params = {
    base: 'basename',
    dir: 'dirname',
    ext: 'extname',
    name: 'name',
    root: 'root'
  };

  res.absolute = path.resolve(res.path);

  if (typeof nativeParse === 'function') {
    var parsed = nativeParse(fp);
    for (var key in parsed) {
      if (parsed.hasOwnProperty(key)) {
        res[params[key]] = parsed[key];
      }
    }

  } else {
    var ext = path.extname(fp);
    res.name = path.basename(fp, ext);
    res.basename = res.name + ext;
    res.extname = path.extname(fp);
    res.dirname = path.dirname(fp);
    res.root = '';
  }

  cache.set(fp, res);
  return res;
};
Beispiel #11
0
function isModuleName(value) {
    return !isHttp(value) && !isAbsolute(value) && value.charAt(0) !== '.';
}
Beispiel #12
0
assert.isAbsolute = function (fp) {
  assert(fp);
  assert(isAbsolute(fp));
};
Beispiel #13
0
 it('should resolve the filepath', function () {
   var actual = resolveDep('*.json');
   expect(isAbsolute(actual[0])).to.be.true;
 });
Beispiel #14
0
 it('should resolve the filepath', function () {
   var actual = resolveDep.local('./index.js');
   expect(isAbsolute(actual[0])).to.be.true;
 });
Beispiel #15
0
function toReference(path, cwd) {
    return "/// <reference path=\"" + path_2.normalizeSlashes(isAbsolute(path) ? path_1.relative(cwd, path) : path_1.normalize(path)) + "\" />";
}