/**
 * Make a directory. If any parent directories not exists, make it.(same as mkdir -p)
 * @function lib.file.mkdirP
 * @param {string} dirname - Directory path to make.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var fs = require('fs'),
    path = require('path');

exports = module.exports = function (dirname, callback) {
    if (!callback) callback = new Function;
    fs.exists(dirname, function (exists) {
        if (exists) {
            callback(null);
        } else {
            exports(path.dirname(dirname), function (err) {
                if (err) {
                    callback(err);
                } else {
                    fs.mkdir(dirname, function (err) {
                        callback(err);
                    });
                }
            });
        }
    });
};