How to use the path.relative function in path

To help you get started, we’ve selected a few path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tilemill-project / millstone / lib / util.js View on Github external
function forcelink(src, dest, options, callback) {
    if (!options || !options.cache) throw new Error('options.cache not defined!');
    if (!callback) throw new Error('callback not defined!');
    // uses relative path if linking to cache dir
    if (path.relative) {
        src = path.relative(options.cache, dest).slice(0, 2) !== '..' ? path.relative(path.dirname(dest), src) : src;
    }
    fs.lstat(dest, function(err, stat) {
        // Error.
        if (err && err.code !== 'ENOENT') {
            return callback(err);
        }

        // Path does not exist. Symlink.
        if (err && err.code === 'ENOENT') {
            if (env == 'development') console.error("[millstone] linking '" + dest + "' -> '"  + src + "'");
            return fs.symlink(src, dest, callback);
        }

        // Path exists and is not a symlink. Do nothing.
        if (!stat.isSymbolicLink()) {
            if (env == 'development') console.error("[millstone] skipping re-linking '" + src + "' because '"  + dest + " is already an existing file");
github alan-ai / alan-sdk-reactnative / testtools / node_modules / metro / src / lib / TerminalReporter.js View on Github external
_getBundleStatusMessage(_ref, phase) {
    let _ref$bundleDetails = _ref.bundleDetails,
      entryFile = _ref$bundleDetails.entryFile,
      platform = _ref$bundleDetails.platform,
      dev = _ref$bundleDetails.dev,
      minify = _ref$bundleDetails.minify,
      bundleType = _ref$bundleDetails.bundleType,
      transformedFileCount = _ref.transformedFileCount,
      totalFileCount = _ref.totalFileCount,
      ratio = _ref.ratio;
    const localPath = path.relative(".", entryFile);
    const fileName = path.basename(localPath);
    const dirName = path.dirname(localPath);
    platform = platform ? platform + ", " : "";
    const devOrProd = dev ? "dev" : "prod";
    const min = minify ? ", minified" : "";
    const progress = (100 * ratio).toFixed(1);
    const currentPhase =
      phase === "done" ? ", done." : phase === "failed" ? ", failed." : "";
    const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
    return (
      chalk.inverse.green.bold(` ${bundleType.toUpperCase()} `) +
      chalk.dim(` [${platform}${devOrProd}${min}] ${dirName}/`) +
      chalk.bold(fileName) +
      " " +
      chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +
      chalk.bgWhite.white(
github lskjs / lskjs / packages / lsk-modules / packages / build / src / Runner / tools / copy.js View on Github external
watcher.on('all', async (event, filePath) => {
      const start = new Date();
      const src = path.relative('./', filePath);
      const dist = path.join(
        this.resolveDist('build/'),
        src.startsWith('src') ? path.relative('src', src) : src,
      );
      switch (event) {
        case 'add':
        case 'change':
          await makeDir(path.dirname(dist));
          await copyFile(filePath, dist);
          break;
        case 'unlink':
        case 'unlinkDir':
          cleanDir(dist, { nosort: true, dot: true });
          break;
        default:
          return;
      }
      const end = new Date();
      const time = end.getTime() - start.getTime();
github GingerBear / react-native-web-ssr-boilerplate / config / webpack.config.prod.js View on Github external
devtoolModuleFilenameTemplate: info =>
      path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/')
  },
github licoliu / pomy / site / startup.js View on Github external
fat: {},
    uat: {},
    prod: {}
  }
};

var cwd = process.cwd();
var rootPath = path.join(path.dirname(__filename), "../../../");
var pomyConfig = path.join(rootPath, "pomy.json");

if (fs.existsSync(pomyConfig)) {
  global.settings = config(path.relative(cwd, pomyConfig));
} else {
  rootPath = path.join(path.dirname(__filename), "../");
  pomyConfig = path.join(rootPath, "pomy.json");
  global.settings = config(path.relative(cwd, pomyConfig));
}

global.settings.paths = {
  cwd: cwd,
  root: rootPath
};

var argvs = minimist(process.argv.slice(2));

var name = global.settings.name;
var target = argvs.target || global.settings.target || 'local';
var debug = !!(argvs.debug || global.settings.debug);

var dSite = global.settings.deploy[target];
var ips = dSite.ips;
var ip = argvs.ip || (ips.length > 0 ? ips[0] : null) || '127.0.0.1';
github doesdev / rollup-plugin-analyzer / lib / html-report.js View on Github external
const toSizes = modules => {
  let sizes = {}
  for (let { id, size } of modules) {
    let cwd = path.dirname(id)
    let { pkg, path: pkgPath } = readPkgUp.sync({ cwd })
    let [name, relPath] = pkg !== null
      ? [pkg.name, path.relative(path.dirname(pkgPath), id)]
      : ['(unknown)', id]
    sizes[name] = sizes[name] || []
    sizes[name][relPath] = size
  }
  return sizes
}
github ZZROTDesign / alpine-ghost / ghost / core / server / data / importer / handlers / image.js View on Github external
return store.getUniqueFileName(store, image, image.targetDir).then(function (targetFilename) {
                image.newPath = (config.paths.subdir + '/' +
                    config.paths.imagesRelPath + '/' + path.relative(config.paths.imagesPath, targetFilename))
                        .replace(new RegExp('\\' + path.sep, 'g'), '/');
                return image;
            });
        });
github Floobits / floobits-atom / lib / common / utils.js View on Github external
function to_rel_path (abs_path) {
  return to_unix_path(path.relative(fl.base_path, abs_path));
}
github alibaba / ice / tools / iceworks / renderer / src / pages / Home / ProjectDashboard / Assets.jsx View on Github external
files.forEach((file) => {
      const fullPath = path.join(dirPath, file);
      stats = fs.lstatSync(fullPath);
      if (stats.isDirectory()) {
        list = list.concat(this.recursiveReaddirSync(fullPath, rootDir));
      } else {
        list.push({
          path: path.relative(rootDir, fullPath),
          size: filesize(stats.size),
          fullPath,
          statsSize: stats.size,
        });
      }
    });
    list = list.sort((a, b) => {