Skip to content

Modified setOutputPath to correctly handle extensions. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to run npm lint to check for lint errors, there are few in here like multi-line if/for statements without brackets

})

return file
Expand Down