-
Notifications
You must be signed in to change notification settings - Fork 0
/
locator_factory.cjs
28 lines (22 loc) · 996 Bytes
/
locator_factory.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const NODE_ENV = process.env.NODE_ENV || 'development';
/**
* @param {string} relativePathModifierToRoot
* @param {string} locatorConfigPath
* @returns {Locator}
*/
module.exports = function(relativePathModifierToRoot, locatorConfigPath) {
relativePathModifierToRoot = relativePathModifierToRoot || '../../';
locatorConfigPath = locatorConfigPath || 'config/locator/';
const config = require('config');
const Locator = require('./locator.cjs');
const locatableDirectory = relativePathModifierToRoot + locatorConfigPath;
const locatableDefault = require(locatableDirectory + 'default');
let locatable = Object.assign({}, locatableDefault);
//load another config based on the environment
try {
let locatableForEnvironment = require( locatableDirectory + NODE_ENV );
locatable = Object.assign(locatable, locatableForEnvironment);
} catch (e) {}
return new Locator(config, locatable, relativePathModifierToRoot);
};