/*1* app.js: Common utility functions for working with directories2*3* (C) 2011, Nodejitsu Inc.4* MIT LICENSE5*6*/78var utile = require('utile'),9async = utile.async,10mkdirp = utile.mkdirp,11rimraf = utile.rimraf;1213var directories = exports;1415//16// ### function create (dirs, callback)17// #### @dirs {Object} Directories to create18// #### @callback {function} Continuation to respond to when complete19// Creates all of the specified `directories` in the current environment.20//21directories.create = function (dirs, callback) {22function createDir(dir, next) {23mkdirp(dir, 0755, function () {24next(null, dir);25});26}2728if (!dirs) {29return callback();30}3132async.mapSeries(Object.keys(dirs).map(function (key) {33return dirs[key]34}), createDir, callback);35};3637//38// ### function remove (dirs, callback)39// #### @dirs {Object} Directories to remove40// #### @callback {function} Continuation to respond to when complete41// Removes all of the specified `directories` in the current environment.42//43directories.remove = function (dirs, callback) {44function removeDir (dir, next) {45rimraf(dir, function () {46next(null, dir);47});48}4950if (!dirs) {51return callback();52}5354async.mapSeries(Object.keys(dirs).map(function (key) {55return dirs[key]56}), removeDir, callback);57};5859//60// ### function normalize (root, dirs)61// #### @keys {Object} Set of keys to normalize upon.62// #### @dirs {Object} Set of directories to normalize.63// Normalizes the specified `dirs` against the relative64// `root` of the application.65//66directories.normalize = function (keys, dirs) {67var normalized = {};6869Object.keys(dirs).forEach(function (key) {70normalized[key] = dirs[key];71Object.keys(keys).forEach(function (constant) {72normalized[key] = normalized[key].replace(constant, keys[constant]);73});74});7576return normalized;77};787980