2018-08-12 22:09:37 +00:00
|
|
|
import * as plugins from './qenv.plugins';
|
|
|
|
import { IKeyValueObject } from './qenv.classes.qenv';
|
2017-05-12 16:17:22 +00:00
|
|
|
|
|
|
|
export let getRequiredEnvVars = (pathArg: string, requiredEnvVarsArray: string[]) => {
|
2018-08-12 22:09:37 +00:00
|
|
|
let qenvFilePath = plugins.path.join(pathArg, 'qenv.yml');
|
|
|
|
let qenvFile = plugins.smartfile.fs.toObjectSync(qenvFilePath);
|
2017-05-12 16:17:22 +00:00
|
|
|
for (let keyArg in qenvFile.vars) {
|
2018-08-12 22:09:37 +00:00
|
|
|
requiredEnvVarsArray.push(qenvFile.vars[keyArg]);
|
2017-05-12 16:17:22 +00:00
|
|
|
}
|
2018-08-12 22:09:37 +00:00
|
|
|
};
|
2017-05-12 16:17:22 +00:00
|
|
|
|
|
|
|
export let getAvailableEnvVars = (
|
|
|
|
requiredEnvVarsArg: string[],
|
|
|
|
envYmlPathArg: string,
|
|
|
|
availableEnvVarsArray: string[],
|
|
|
|
keyValueObjectArrayArg: IKeyValueObject[]
|
|
|
|
) => {
|
2018-08-12 22:09:37 +00:00
|
|
|
envYmlPathArg = plugins.path.join(envYmlPathArg, 'env.yml');
|
|
|
|
let envYml;
|
2017-05-12 16:17:22 +00:00
|
|
|
try {
|
2018-08-12 22:09:37 +00:00
|
|
|
envYml = plugins.smartfile.fs.toObjectSync(envYmlPathArg);
|
2017-05-12 16:17:22 +00:00
|
|
|
} catch (err) {
|
2018-08-12 22:09:37 +00:00
|
|
|
console.log("env file couldn't be found at " + envYmlPathArg);
|
|
|
|
envYml = {};
|
2017-05-12 16:17:22 +00:00
|
|
|
}
|
|
|
|
for (let requiredEnvVar of requiredEnvVarsArg) {
|
2018-08-12 22:09:37 +00:00
|
|
|
if (process.env[requiredEnvVar]) {
|
|
|
|
availableEnvVarsArray.push(requiredEnvVar);
|
2017-05-12 16:17:22 +00:00
|
|
|
keyValueObjectArrayArg.push({
|
|
|
|
key: requiredEnvVar,
|
2018-08-12 22:09:37 +00:00
|
|
|
value: process.env[requiredEnvVar]
|
|
|
|
});
|
2017-05-12 16:17:22 +00:00
|
|
|
} else if (envYml.hasOwnProperty(requiredEnvVar)) {
|
2018-08-12 22:09:37 +00:00
|
|
|
process.env[requiredEnvVar] = envYml[requiredEnvVar];
|
|
|
|
availableEnvVarsArray.push(requiredEnvVar);
|
2017-05-12 16:17:22 +00:00
|
|
|
keyValueObjectArrayArg.push({
|
|
|
|
key: requiredEnvVar,
|
2018-08-12 22:09:37 +00:00
|
|
|
value: process.env[requiredEnvVar]
|
|
|
|
});
|
2017-05-12 16:17:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-12 22:09:37 +00:00
|
|
|
};
|
2017-05-12 16:17:22 +00:00
|
|
|
|
2018-08-12 22:09:37 +00:00
|
|
|
export let getMissingEnvVars = (
|
|
|
|
requiredEnvVarsArray: string[],
|
|
|
|
availableEnvVarsArray: string[]
|
|
|
|
): string[] => {
|
|
|
|
const missingEnvVars: string[] = [];
|
|
|
|
for (const envVar of requiredEnvVarsArray) {
|
|
|
|
if (!availableEnvVarsArray.includes(envVar)) {
|
|
|
|
missingEnvVars.push(envVar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return missingEnvVars;
|
|
|
|
};
|