diff --git a/lib/index.js b/lib/index.js index 9ceb280..4c5403d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -37,16 +37,32 @@ module.exports = class SpikeUtils { /** * Given a source file path, returns the path to the final output. * @param {String} file - path to source file + * @param {String} extension - (optinal) final file extension * @return {File} object containing relative and absolute paths */ - getOutputPath (f) { + getOutputPath (f, extension) { let file = new File(this.conf.context, f) this.conf.spike.dumpDirs.forEach((d) => { const re = new RegExp(`^${d}\\${path.sep}`) - if (file.relative.match(re)) { - file = new File(this.conf.output.path, file.relative.replace(re, '')) + if (!file.relative.match(re)) return + + let output = file.relative.replace(re, '') + + if (!extension) { + for (let ext in this.conf.spike.matchers) { + if (micromatch.isMatch(output, this.conf.spike.matchers[ext])) { + extension = ext + break + } + } } + + if (extension) { + output = output.replace(path.extname(output), '.' + extension) + } + + file = new File(this.conf.output.path, output) }) return file