Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created January 12, 2014 01:42
Show Gist options
  • Save myndzi/8379483 to your computer and use it in GitHub Desktop.
Save myndzi/8379483 to your computer and use it in GitHub Desktop.
function makeOutputDir(inWC, outWC, dir) {
if (outWC.indexOf('/**/') === -1) return outWC;
var outMask = path.basename(outWC);
inWC = path.dirname(inWC)+'/';
outWC = path.dirname(outWC)+'/';
dir = path.normalize(dir);
var inSplit = inWC.split('/**/'),
outSplit = outWC.split('/**/'),
dirLeft = dir.slice(0, inSplit[0].length),
dirRight = dir.slice(inSplit[0].length);
assert(inSplit.length === 2);
assert(inSplit[0] === dirLeft);
var subDir, wildDir;
if (inSplit[1].length === 0) {
subDir = '';
wildDir = dirRight;
} else {
subDir = dirRight.slice(-inSplit[1].length),
wildDir = dirRight.slice(0, -inSplit[1].length);
}
assert(inSplit[1] === subDir);
return path.join(outSplit[0], wildDir, outSplit[1], outMask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment