Skip to content

Instantly share code, notes, and snippets.

@isnifer
Last active December 20, 2016 13:02
Show Gist options
  • Save isnifer/ce4dc6a70d7bda126758d7e8aad8ec76 to your computer and use it in GitHub Desktop.
Save isnifer/ce4dc6a70d7bda126758d7e8aad8ec76 to your computer and use it in GitHub Desktop.
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