Replace dynamic-require with fs readFileSync
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
@@ -10,8 +11,7 @@ const __dirname = path.dirname(__filename);
|
|||||||
class Config {
|
class Config {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.location = Config.determineLocation();
|
this.location = Config.determineLocation();
|
||||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
this.fields = Config.readFileContents(this.location);
|
||||||
this.fields = require(`${this.location}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getInstance() {
|
static getInstance() {
|
||||||
@@ -25,6 +25,17 @@ class Config {
|
|||||||
return path.join(__dirname, "..", "..", process.env.SEASONED_CONFIG);
|
return path.join(__dirname, "..", "..", process.env.SEASONED_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readFileContents(location) {
|
||||||
|
let content = {};
|
||||||
|
try {
|
||||||
|
content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" }));
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error loading configuration file at path: ${location}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
get(section, option) {
|
get(section, option) {
|
||||||
if (
|
if (
|
||||||
this.fields[section] === undefined ||
|
this.fields[section] === undefined ||
|
||||||
|
|||||||
Reference in New Issue
Block a user