Last active
December 20, 2016 13:02
-
-
Save isnifer/ce4dc6a70d7bda126758d7e8aad8ec76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const fs = require('fs'); | |
let flavors = process.env.FLAVORS; | |
flavors = flavors ? [...flavors.split(','), ''] : []; | |
module.exports = function(originalPath, callingFileName, options) { | |
let dirpath = callingFileName.split('/'); | |
dirpath = dirpath.slice(0, dirpath.length - 1).join('/'); | |
let expectedPath; | |
for (suffix of flavors) { | |
const correctSuffix = suffix ? `.${suffix}` : ''; | |
const pathname = path.resolve(dirpath, `${originalPath}${correctSuffix}.js`); | |
const isExist = fs.existsSync(pathname); | |
if (isExist) { | |
let nextPathName = pathname.split('/'); | |
nextPathName = nextPathName[nextPathName.length - 1]; | |
const originalPathArray = originalPath.split('/'); | |
expectedPath = [ | |
...originalPathArray.slice(0, originalPathArray.length - 1), | |
nextPathName | |
].join('/'); | |
break; | |
} | |
} | |
return expectedPath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment