From 2f54f66c594351bb03ea944a9b74cb46071bf495 Mon Sep 17 00:00:00 2001 From: Tom Adam Date: Tue, 1 Apr 2014 15:21:58 +0100 Subject: [PATCH] Allow function for outFolder in dest --- lib/dest/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/dest/index.js b/lib/dest/index.js index b2776191..fdff5f9d 100644 --- a/lib/dest/index.js +++ b/lib/dest/index.js @@ -7,17 +7,22 @@ var writeContents = require('./writeContents'); var defaultMode = 0777 & (~process.umask()); module.exports = function(outFolder, opt) { - if (typeof outFolder !== 'string') throw new Error('Invalid output folder'); - if (!opt) opt = {}; if (!opt.cwd) opt.cwd = process.cwd(); if (typeof opt.mode === 'string') opt.mode = parseInt(opt.mode, 8); var cwd = path.resolve(opt.cwd); - var basePath = path.resolve(cwd, outFolder); var folderMode = (opt.mode || defaultMode); + var basePath; + + if (typeof outFolder === 'string') { + basePath = path.resolve(cwd, outFolder); + } else if (typeof outFolder !== 'function') { + throw new Error('Invalid output folder'); + } function saveFile (file, cb) { + if (typeof outFolder === 'function') basePath = path.resolve(cwd, outFolder(file)); var writePath = path.resolve(basePath, file.relative); var writeFolder = path.dirname(writePath);