Skip to content

Commit

Permalink
Adjust load of config files (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrunet authored Jul 7, 2023
1 parent 94c1827 commit 36a7fe2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions common/module/src/config/ACConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function initializeDefaults(config: IConfigInternal) {
*
* @memberOf this
*/
function loadConfigFromYAMLorJSONFile() {
async function loadConfigFromYAMLorJSONFile() {
ACConstants.DEBUG && console.log("START 'loadConfigFromYAMLorJSONFile' function");

// Variable Decleration
Expand Down Expand Up @@ -281,7 +281,15 @@ function loadConfigFromYAMLorJSONFile() {
ACConstants.DEBUG && console.log("Loading: " + jsOrJSONFile)

// Load in as json or js and return this object
return JSON.parse(fs.readFileSync(fileToCheck).toString());
try {
return require(fileToCheck);
} catch (err) {
try {
return await import(fileToCheck);
} catch (err) {
return JSON.parse(fs.readFileSync(jsOrJSONFile).toString());
}
}
}
} catch (e) {
ACConstants.DEBUG && console.log("JSON or JS file does not exists, will load default config.")
Expand Down Expand Up @@ -318,7 +326,7 @@ async function processConfiguration(config?) : Promise<IConfigInternal> {
let configFromFile = null;

// Read in the .yaml (.yml) or .json file to load in the configuration
configFromFile = loadConfigFromYAMLorJSONFile();
configFromFile = await loadConfigFromYAMLorJSONFile();

ACConstants.DEBUG && console.log("Loaded config from file: ");
ACConstants.DEBUG && console.log(configFromFile);
Expand Down

0 comments on commit 36a7fe2

Please sign in to comment.