1 | var potentialExtensions = [''].concat(Object.keys(require('interpret').jsVariants)),
|
2 | fs = require('fs');
|
3 |
|
4 | function existsWithAccess(path) {
|
5 | try {
|
6 | fs.accessSync(path);
|
7 | return true;
|
8 | } catch(ignore) {
|
9 | return false;
|
10 | }
|
11 | }
|
12 |
|
13 | function 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 |
|
26 | module.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 |
|
31 | return configPath + ext;
|
32 | }
|
33 | }
|
34 |
|
35 | throw new Error('File does not exist');
|
36 | }
|