Skip to content

Commit

Permalink
Modified setOutputPath to correctly handle extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
RedHatter committed Jun 25, 2016
1 parent 070be50 commit 684ad49
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 684ad49

Please sign in to comment.