2016-06-20 05:06:15 +00:00
|
|
|
"use strict";
|
|
|
|
var plugins = require("./qenv.plugins");
|
2016-06-20 08:45:43 +00:00
|
|
|
var Qenv = (function () {
|
2016-06-21 14:13:29 +00:00
|
|
|
function Qenv(basePathArg, envYmlPathArg, failOnMissing) {
|
2016-06-20 05:06:15 +00:00
|
|
|
if (basePathArg === void 0) { basePathArg = process.cwd(); }
|
2016-06-21 14:13:29 +00:00
|
|
|
if (failOnMissing === void 0) { failOnMissing = true; }
|
2016-06-20 05:06:15 +00:00
|
|
|
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
|
|
|
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars, envYmlPathArg);
|
|
|
|
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars, this.availableEnvVars);
|
2016-06-21 14:13:29 +00:00
|
|
|
//handle missing variables
|
|
|
|
if (this.missingEnvVars.length > 0) {
|
2016-06-21 14:25:03 +00:00
|
|
|
plugins.beautylog.info("Required Env Vars are:");
|
|
|
|
console.log(this.requiredEnvVars);
|
|
|
|
plugins.beautylog.error("However some Env variables could not be resolved:");
|
2016-06-21 14:13:29 +00:00
|
|
|
console.log(this.missingEnvVars);
|
|
|
|
if (failOnMissing) {
|
|
|
|
plugins.beautylog.error("Exiting!");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-06-20 08:45:43 +00:00
|
|
|
}
|
2016-06-20 05:06:15 +00:00
|
|
|
}
|
2016-06-20 08:45:43 +00:00
|
|
|
return Qenv;
|
2016-06-20 05:06:15 +00:00
|
|
|
}());
|
2016-06-20 08:45:43 +00:00
|
|
|
exports.Qenv = Qenv;
|
2016-06-20 05:06:15 +00:00
|
|
|
;
|
|
|
|
var getRequiredEnvVars = function (pathArg) {
|
|
|
|
var result = [];
|
|
|
|
var qenvFilePath = plugins.path.join(pathArg, "qenv.yml");
|
|
|
|
var qenvFile = plugins.smartfile.local.toObjectSync(qenvFilePath);
|
|
|
|
for (var keyArg in qenvFile.vars) {
|
|
|
|
result.push(qenvFile.vars[keyArg]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
var getAvailableEnvVars = function (requiredEnvVarsArg, envYmlPathArg) {
|
|
|
|
var result = [];
|
2016-06-20 08:45:43 +00:00
|
|
|
envYmlPathArg = plugins.path.join(envYmlPathArg, "env.yml");
|
2016-06-20 05:06:15 +00:00
|
|
|
var envYml;
|
|
|
|
try {
|
|
|
|
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
|
|
|
}
|
|
|
|
catch (err) {
|
2016-06-21 14:13:29 +00:00
|
|
|
plugins.beautylog.log("env file couldn't be found at " + envYmlPathArg);
|
2016-06-20 05:06:15 +00:00
|
|
|
envYml = {};
|
|
|
|
}
|
|
|
|
for (var keyArg in requiredEnvVarsArg) {
|
2016-06-20 08:45:43 +00:00
|
|
|
var requiredEnvVar = requiredEnvVarsArg[keyArg];
|
|
|
|
if (process.env[requiredEnvVar]) {
|
|
|
|
result.push(requiredEnvVar);
|
2016-06-20 05:06:15 +00:00
|
|
|
}
|
2016-06-20 08:45:43 +00:00
|
|
|
else if (envYml.hasOwnProperty(requiredEnvVar)) {
|
|
|
|
process.env[requiredEnvVar] = envYml[requiredEnvVar];
|
|
|
|
result.push(requiredEnvVar);
|
2016-06-20 05:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
var getMissingEnvVars = function (requiredEnvVarsArray, availableEnvVarsArray) {
|
|
|
|
return plugins.lodash.difference(requiredEnvVarsArray, availableEnvVarsArray);
|
|
|
|
};
|
2016-06-19 15:33:54 +00:00
|
|
|
|
2016-06-21 14:25:03 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQU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