How to use the path.dirname 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 bazelbuild / rules_nodejs / packages / hide-bazel-files / index.js View on Github external
function main() {
  // Rename all bazel files found by prefixing them with `_`
  const cwd = process.cwd();
  const rootNodeModules =
      /\/node_modules\/@bazel\/hide-bazel-files$/.test(cwd.replace(/\\/g, '/')) ?
      path.dirname(path.dirname(cwd)) :
      path.posix.join(cwd, 'node_modules');
  for (f of findBazelFiles(rootNodeModules)) {
    const d = path.posix.join(path.dirname(f), `_${path.basename(f)}`);
    fs.renameSync(f, d);
  }
  return 0;
}
github aurelia / webpack-plugin / dist / ConventionDependenciesPlugin.js View on Github external
parser.hooks.program.tap("Aurelia:ConventionDependencies", () => {
            const { resource: file, rawRequest } = parser.state.current;
            if (!file)
                return;
            // We don't want to bring in dependencies of the async! loader
            if (/^async[!?]/.test(rawRequest))
                return;
            if (!minimatch(path.relative(root, file), this.glob))
                return;
            for (let c of this.conventions) {
                try {
                    const probe = c(file);
                    compilation.inputFileSystem.statSync(probe); // Check if file exists
                    let relative = path.relative(path.dirname(file), probe);
                    if (!relative.startsWith("."))
                        relative = "./" + relative;
                    addDependency(relative);
                    // If the module has a conventional dependency, make sure we preserve its name as well.
                    // This solves the pattern where a VM is statically loaded, e.g. `import { ViewModel } from "x"`
                    // and then passed to Aurelia, e.g. with `aurelia-dialog`.
                    // At this point Aurelia must determine the origin of the module to be able to look for 
                    // a conventional view, and so the module name must be preserved although it's never loaded 
                    // by `aurelia-loader`. See also aurelia/metadata#51.
                    parser.state.current[PreserveModuleNamePlugin_1.preserveModuleName] = true;
                }
                catch (ex) { }
            }
        });
    }
github viebel / klipse / docs / cache-cljs / cljs_SLASH_module_deps.js View on Github external
resolve: function(id, parentOpts, cb) {
    // set the basedir properly so we don't try to resolve requires in the Closure
    // Compiler processed `node_modules` folder.
    parentOpts.basedir =
      parentOpts.filename === filename
        ? path.resolve(__dirname)
        : path.dirname(parentOpts.filename);

    resolver(parentOpts.basedir, id, cb);
  },
  filter: function(id) {
github brigadecore / brigade / brigade-worker / node_modules / mkdirp / index.js View on Github external
xfs.mkdir(p, mode, function (er) {
        if (!er) {
            made = made || p;
            return cb(null, made);
        }
        switch (er.code) {
            case 'ENOENT':
                if (path.dirname(p) === p) return cb(er);
                mkdirP(path.dirname(p), opts, function (er, made) {
                    if (er) cb(er, made);
                    else mkdirP(p, opts, cb, made);
                });
                break;

            // In the case of any other error, just see if there's a dir
            // there already.  If so, then hooray!  If not, then something
            // is borked.
            default:
                xfs.stat(p, function (er2, stat) {
                    // if the stat fails, then that's super weird.
                    // let the original error be the failure reason.
                    if (er2 || !stat.isDirectory()) cb(er, made)
                    else cb(null, made);
                });
github dapphub / dapple / lib / streams / test_summarizer.js View on Github external
}, function (cb) {
    var ext = '.stdout';
    var output = clc.green('Passed all ' + totalTests + ' tests!');

    if (failingTests.length > 0) {
      ext = '.stderr';
      output = clc.red(
        'Failed ' + failingTests.length +
        ' out of ' + totalTests + ' tests.');

      var failedOutput = '';
      for (let failingTest of failingTests) {
        failedOutput += clc.red(path.dirname(failingTest.path) +
            ': ' + path.basename(failingTest.path, ext)) + '\n  ';
      }

      this.push(new File({
        path: path.join('Failing Tests', 'summary' + ext),
        contents: new Buffer(failedOutput)
      }));
    }

    this.push(new File({
      path: path.join('Summary', 'summary' + ext),
      contents: new Buffer(output)
    }));

    cb();
  });
github ecomfe / echarts-examples / build.js View on Github external
function doWrite(destRelativePath, html) {
        let destPath = path.resolve(config.releaseDestDir, destRelativePath);
        fse.ensureDirSync(path.dirname(destPath));
        fs.writeFileSync(destPath, html, 'utf8');
        console.log(chalk.green(`generated: ${destPath}`));
    }
github liblouis / liblouis-js / easy-api.js View on Github external
}

		this.capi.TABLE_URL = tableurl;
		if(!IS_NODE) {
			this.capi.FS.lookup = bindDynLoader(this);
		} else {
			this.disableOnDemandTableLoading();

			this.capi.FS.mkdir('/tables');

			var tablefolder = tableurl;

			if(!tablefolder) {
				var path = require('path');
				var buildpath = require.resolve('liblouis-build');
				tablefolder = path.resolve(path.dirname(buildpath), "tables/");
			}

			try {
				this.capi.FS.mount(this.capi.FS.filesystems.NODEFS, { root: tablefolder }, '/tables');
			} catch(e) {
				console.error(e);
				throw new Error("mounting of table folder failed");
			}
		}
	},
github nas5w / typeofnan-javascript-quizzes / scripts / new-question / index.js View on Github external
throw new Error('Please, specify question title');
  }

  const questionName = agrs[0];
  const srcDir = `${path.dirname(require.main.filename)}/../../content/questions`;
  const existingQuestions = getDirectories(srcDir);

  if (existingQuestions.indexOf(questionName) > -1) {
    throw new Error(`Question ${questionName} already exists. Please, specify another name`);
  }

  mkdirSync(`${srcDir}/${questionName}`, (err) => {
    if (err) throw err;
  });

  const fileTemplate = readFileSync(`${path.dirname(require.main.filename)}/index.md`, 'utf8');
  const blankQuestionTmpl = template(fileTemplate);

  writeFileSync(`${srcDir}/${questionName}/index.md`, blankQuestionTmpl({
    order: existingQuestions.length,
    date: new Date(),
  }));

  console.info('All done!');
}
github stef-levesque / vscode-perforce / src / PerforceCommands.ts View on Github external
var editor = window.activeTextEditor;
        if(!checkFileSelected()) {
            return false;
        }

        if (!editor || !editor.document) {
            return false;
        }

        var fileUri = editor.document.uri; 

        //If folder not opened, run p4 in files folder.
        if(checkFolderOpened()) {
            edit(fileUri);
        } else {
            edit(fileUri, Path.dirname(fileUri.fsPath));
        }
    }
github onury / docma / lib / Template.js View on Github external
constructor(params) {
        if (!params) {
            throw new Error('Template initialization failed!');
        }
        const dirname = path.dirname(params.path);
        const pkgPath = path.join(dirname, 'package.json');
        const pkg = utils.safeRequire(pkgPath);
        if (!pkg) {
            throw new Error(`Template package.json is not found at ${pkgPath}`);
        }
        pkg.docmaTemplate = pkg.docmaTemplate || {};

        /** @private */
        this._ = _.extend({}, params, {
            dirname,
            pkg,
            templateDir: path.join(dirname, 'template'),
            initialOptions: (params.buildConfig.template || {}).options || {},
            defaultOptions: null,
            mainHTML: '',
            compile: null,