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 () {
|
|
|
|
function Qenv(basePathArg, envYmlPathArg) {
|
2016-06-20 05:06:15 +00:00
|
|
|
if (basePathArg === void 0) { basePathArg = process.cwd(); }
|
|
|
|
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
|
|
|
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars, envYmlPathArg);
|
|
|
|
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars, this.availableEnvVars);
|
2016-06-20 08:45:43 +00:00
|
|
|
for (var keyArg in this.missingEnvVars) {
|
|
|
|
plugins.beautylog.warn(this.missingEnvVars[keyArg] + " is required, but missing!");
|
|
|
|
}
|
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) {
|
|
|
|
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-20 08:45:43 +00:00
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBRTFDO0lBSUksY0FBWSxXQUEyQixFQUFDLGFBQWE7UUFBekMsMkJBQTJCLEdBQTNCLGNBQWMsT0FBTyxDQUFDLEdBQUcsRUFBRTtRQUNuQyxJQUFJLENBQUMsZUFBZSxHQUFHLGtCQUFrQixDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ3ZELElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxtQkFBbUIsQ0FBQyxJQUFJLENBQUMsZUFBZSxFQUFDLGFBQWEsQ0FBQyxDQUFDO1FBQ2hGLElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUMsSUFBSSxDQUFDLGVBQWUsRUFBQyxJQUFJLENBQUMsZ0JBQWdCLENBQ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