Initial commit
This commit is contained in:
42
node_modules/ensureDir/index.js
generated
vendored
Normal file
42
node_modules/ensureDir/index.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
var path = require('path')
|
||||
, fs = require('fs');
|
||||
|
||||
var fnExists = fs.exists || path.exists;
|
||||
|
||||
/**
|
||||
* Ensures the directory exists, creating it recursively if not.
|
||||
*
|
||||
* @param {string} dir The directory path to ensure existance.
|
||||
* @param {number=} mode See fs.mkdir
|
||||
* @param {function(?Error)} callback
|
||||
*/
|
||||
module.exports = function (dir, mode, callback) {
|
||||
if (mode && typeof(mode) === 'function') {
|
||||
callback = mode;
|
||||
mode = null;
|
||||
}
|
||||
|
||||
mode = mode || 0777 & (~process.umask());
|
||||
|
||||
callback = callback || function () {
|
||||
};
|
||||
|
||||
_ensureDir(dir, mode, callback);
|
||||
};
|
||||
|
||||
function _ensureDir(dir, mode, callback) {
|
||||
fnExists(dir, function (exists) {
|
||||
if (exists) return callback(null);
|
||||
|
||||
var current = path.resolve(dir), parent = path.dirname(current);
|
||||
|
||||
_ensureDir(parent, mode, function (err) {
|
||||
if (err) return callback(err);
|
||||
|
||||
fs.mkdir(current, mode, function (err) {
|
||||
if (err && err.code != 'EEXIST') return callback(err); // avoid the error under concurrency
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
20
node_modules/ensureDir/package.json
generated
vendored
Normal file
20
node_modules/ensureDir/package.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "ensureDir",
|
||||
"description": "Ensures the directory exists, creating it recursively if not",
|
||||
"version": "1.0.6",
|
||||
"author": "Sam X. Xu <samxxu@gmail.com>",
|
||||
"main": "./index",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/samxxu/ensureDir.git"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user