mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Move mkdir -p functionality to its own module and cleanup --output build tests.
Former-commit-id: b7ea2a41c60357e780e10bd3d665db3d50e7f044
This commit is contained in:
41
build/mkdirp-sync.js
Executable file
41
build/mkdirp-sync.js
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env node
|
||||
;(function() {
|
||||
'use strict';
|
||||
|
||||
/** Load Node.js modules */
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
/**
|
||||
* Makes the given `path` directory, without throwing errors for existing
|
||||
* directories and making parent directories as needed.
|
||||
*
|
||||
* @param {String} dirname The path of the directory.
|
||||
* @param {Number|String} mode The permission mode.
|
||||
*/
|
||||
function mkdirpSync(dirname, mode) {
|
||||
var separator = path.sep,
|
||||
segments = dirname.split(separator),
|
||||
type = typeof mode;
|
||||
|
||||
if (!(type == 'number' || type == 'string')) {
|
||||
mode = '0777';
|
||||
}
|
||||
segments.reduce(function(currPath, segment, index) {
|
||||
// skip leading separator of absolute paths
|
||||
if (index === 0 && currPath === '') {
|
||||
return separator;
|
||||
}
|
||||
segment = currPath + (currPath === separator ? segment : separator + segment);
|
||||
try {
|
||||
segment = fs.realpathSync(segment);
|
||||
} catch(e) {
|
||||
fs.mkdirSync(segment, mode);
|
||||
}
|
||||
return segment;
|
||||
});
|
||||
}
|
||||
|
||||
// expose
|
||||
module.exports = mkdirpSync;
|
||||
}());
|
||||
Reference in New Issue
Block a user