mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Simplify build/mkdirp-sync.js.
Former-commit-id: b49bbea9e565dbf1d23f601af74443b33fe9fc7d
This commit is contained in:
@@ -12,35 +12,27 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given `path` directory, without throwing errors for existing
|
* Makes the given `dirname` directory, without throwing errors for existing
|
||||||
* directories and making parent directories as needed.
|
* directories and making parent directories as needed.
|
||||||
*
|
*
|
||||||
* @param {String} dirname The path of the directory.
|
* @param {String} dirname The path of the directory.
|
||||||
* @param {Number|String} mode The permission mode.
|
* @param {Number|String} [mode='0777'] The permission mode.
|
||||||
*/
|
*/
|
||||||
function mkdirpSync(dirname, mode) {
|
function mkdirpSync(dirname, mode) {
|
||||||
var sep = path.sep,
|
var sep = path.sep;
|
||||||
type = typeof mode;
|
|
||||||
|
|
||||||
// ensure relative paths are prefixed with `./`
|
// ensure relative paths are prefixed with `./`
|
||||||
if (!RegExp('^\\.?' + sep).test(dirname)) {
|
if (!RegExp('^\\.?' + sep).test(dirname)) {
|
||||||
dirname = '.' + sep + dirname;
|
dirname = '.' + sep + dirname;
|
||||||
}
|
}
|
||||||
if (!(type == 'number' || type == 'string')) {
|
dirname.split(sep).reduce(function(currPath, segment) {
|
||||||
mode = '0777';
|
currPath += sep + segment;
|
||||||
}
|
|
||||||
dirname.split(sep).reduce(function(currPath, segment, index) {
|
|
||||||
// skip leading separator of absolute paths
|
|
||||||
if (index === 0 && currPath === '') {
|
|
||||||
return sep;
|
|
||||||
}
|
|
||||||
segment = currPath + (currPath === sep ? segment : sep + segment);
|
|
||||||
try {
|
try {
|
||||||
segment = fs.realpathSync(segment);
|
currPath = fs.realpathSync(currPath);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
fs.mkdirSync(segment, mode);
|
fs.mkdirSync(currPath, mode);
|
||||||
}
|
}
|
||||||
return segment;
|
return currPath;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user