Skip to content

Commit 684ad49

Browse files
author
RedHatter
committed
Modified setOutputPath to correctly handle extensions.
1 parent 070be50 commit 684ad49

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,32 @@ module.exports = class SpikeUtils {
3737
/**
3838
* Given a source file path, returns the path to the final output.
3939
* @param {String} file - path to source file
40+
* @param {String} extension - (optinal) final file extension
4041
* @return {File} object containing relative and absolute paths
4142
*/
42-
getOutputPath (f) {
43+
getOutputPath (f, extension) {
4344
let file = new File(this.conf.context, f)
4445

4546
this.conf.spike.dumpDirs.forEach((d) => {
4647
const re = new RegExp(`^${d}\\${path.sep}`)
47-
if (file.relative.match(re)) {
48-
file = new File(this.conf.output.path, file.relative.replace(re, ''))
48+
if (!file.relative.match(re)) return
49+
50+
let output = file.relative.replace(re, '')
51+
52+
if (!extension) {
53+
for (let ext in this.conf.spike.matchers) {
54+
if (micromatch.isMatch(output, this.conf.spike.matchers[ext])) {
55+
extension = ext
56+
break
57+
}
58+
}
4959
}
60+
61+
if (extension) {
62+
output = output.replace(path.extname(output), '.' + extension)
63+
}
64+
65+
file = new File(this.conf.output.path, output)
5066
})
5167

5268
return file

0 commit comments

Comments
 (0)