UNPKG

857 BJavaScriptView Raw
1var potentialExtensions = [''].concat(Object.keys(require('interpret').jsVariants)),
2 fs = require('fs');
3
4function existsWithAccess(path) {
5 try {
6 fs.accessSync(path);
7 return true;
8 } catch(ignore) {
9 return false;
10 }
11}
12
13function exists(path) {
14 if(fs.accessSync) {
15 return existsWithAccess(path);
16 } else {
17 try {
18 var stats = fs.statSync(path);
19 return stats.isFile();
20 } catch(ignore) {
21 return false;
22 }
23 }
24}
25
26module.exports = function(configPath) {
27 for(var i = 0, len = potentialExtensions.length; i < len; i++) {
28 var ext = potentialExtensions[i];
29 if(exists(configPath + ext)) {
30 // file exists, use that extension
31 return configPath + ext;
32 }
33 }
34
35 throw new Error('File does not exist');
36}