homegames-common 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +50 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -578,6 +578,53 @@ const authWorkflow = (authPath) => new Promise((resolve, reject) => {
|
|
|
578
578
|
});
|
|
579
579
|
});
|
|
580
580
|
|
|
581
|
+
const getConfigValue = (key, _default = undefined) => {
|
|
582
|
+
const config = getConfig();
|
|
583
|
+
|
|
584
|
+
let envValue = process.env[key] && `${process.env[key]}`;
|
|
585
|
+
if (envValue !== undefined) {
|
|
586
|
+
if (envValue === 'true') {
|
|
587
|
+
envValue = true;
|
|
588
|
+
} else if (envValue === 'false') {
|
|
589
|
+
envValue = false;
|
|
590
|
+
}
|
|
591
|
+
console.log(`Using environment value: ${envValue} for key: ${key}`);
|
|
592
|
+
return envValue;
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
if (config[key] === undefined) {
|
|
596
|
+
throw new Error(`No value for ${key} found in config`);
|
|
597
|
+
}
|
|
598
|
+
console.log(`Found value ${config[key]} in config`);
|
|
599
|
+
return config[key];
|
|
600
|
+
} catch(err) {
|
|
601
|
+
console.log(err);
|
|
602
|
+
if (_default === undefined) {
|
|
603
|
+
throw new Error(`No config value found for ${key}`);
|
|
604
|
+
} else {
|
|
605
|
+
console.log(`Could not find config for key ${key}. Using default: ${_default}`);
|
|
606
|
+
return _default;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
const getConfig = () => {
|
|
613
|
+
|
|
614
|
+
const options = [process.cwd(), require.main.filename, process.mainModule.filename, __dirname]
|
|
615
|
+
let baseDir = process.cwd();
|
|
616
|
+
let _config = {};
|
|
617
|
+
|
|
618
|
+
for (let i = 0; i < options.length; i++) {
|
|
619
|
+
if (fs.existsSync(`${options[i]}/config.js`)) {//src/util/config.js`)) {
|
|
620
|
+
console.log(`Using config at ${options[i]}`);
|
|
621
|
+
_config = require(`${options[i]}/config.js`);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
return _config;
|
|
626
|
+
}
|
|
627
|
+
|
|
581
628
|
|
|
582
629
|
module.exports = {
|
|
583
630
|
guaranteeCerts,
|
|
@@ -596,6 +643,8 @@ module.exports = {
|
|
|
596
643
|
promptLogin,
|
|
597
644
|
getUserHash,
|
|
598
645
|
authWorkflow,
|
|
599
|
-
guaranteeDir
|
|
646
|
+
guaranteeDir,
|
|
647
|
+
getUrl,
|
|
648
|
+
getConfigValue
|
|
600
649
|
};
|
|
601
650
|
|