How to use the dirname function from path

Find comprehensive JavaScript path.dirname code examples handpicked from public code repositorys.

20
21
22
23
24
25
26
27
28
29
30
const specFilePath = path.resolve(
  path.join(__dirname, '../../../kolibri/core/assets/src/core-app/apiSpec.js')
);


function specModule(filePath) {
  const rootPath = path.dirname(filePath);
  function newPath(p1) {
    if (p1.startsWith('.')) {
      return path.join(rootPath, p1);
    } else {
fork icon466
star icon582
watch icon40

62
63
64
65
66
67
68
69
70
}
const isDir = fs.lstatSync(srcPath).isDirectory()
if (isDir) {
    srcPath = ensureTrailingSlash(srcPath);
}
const parent = path.dirname(toPath);
if (!fs.existsSync(parent)) {
    fs.mkdirSync(parent, { recursive: true })
}
fork icon7
star icon0
watch icon2

125
126
127
128
129
130
131
132
133
134
  const old = readFile(fileName);
  if (content === old) {
    return;
  }
}
const dirname = path.dirname(fileName);
if (!fs.existsSync(dirname)) {
  fs.mkdirSync(dirname, {recursive: true});
}
fs.writeFileSync(fileName, content);
fork icon5
star icon4
watch icon3

+ 3 other calls in file

151
152
153
154
155
156
157
158
159
160

try {
  const frameworkJsonPath = require.resolve(`${sourceOfWebpack}/package.json`, {
    paths: [projectRoot]
  });
  const frameworkPathRoot = path.dirname(frameworkJsonPath);


  framework.importPath = frameworkPathRoot;
  framework.packageJson = require(frameworkJsonPath);
fork icon0
star icon0
watch icon3

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14
15
const path = require('path')


const highlight = require('highlight.js')


// -----------------------------------------------------------------------------
const AppDir = path.dirname(path.dirname(path.dirname(__dirname)))
const Extensions = initExtensions()
// const PluginName = path.basename(__dirname)


exports.toHTML = toHTML
fork icon0
star icon0
watch icon0

10
11
12
13
14
15
16
17
18
19
20
21
22
var path = require('path');


var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';


module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
  var destDir = path.dirname(destFilepath);


  function srcPathToDestRequire(srcFilepath) {
    var requirePath = path.posix.relative(destDir, srcFilepath);
    return 'require(\'' + requirePath + '\')';
fork icon0
star icon0
watch icon0