qenv/dist/index.js
2016-06-20 10:45:43 +02:00

53 lines
6.9 KiB
JavaScript

"use strict";
var plugins = require("./qenv.plugins");
var Qenv = (function () {
function Qenv(basePathArg, envYmlPathArg) {
if (basePathArg === void 0) { basePathArg = process.cwd(); }
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars, envYmlPathArg);
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars, this.availableEnvVars);
for (var keyArg in this.missingEnvVars) {
plugins.beautylog.warn(this.missingEnvVars[keyArg] + " is required, but missing!");
}
}
return Qenv;
}());
exports.Qenv = Qenv;
;
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 = [];
envYmlPathArg = plugins.path.join(envYmlPathArg, "env.yml");
var envYml;
try {
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
}
catch (err) {
envYml = {};
}
for (var keyArg in requiredEnvVarsArg) {
var requiredEnvVar = requiredEnvVarsArg[keyArg];
if (process.env[requiredEnvVar]) {
result.push(requiredEnvVar);
}
else if (envYml.hasOwnProperty(requiredEnvVar)) {
process.env[requiredEnvVar] = envYml[requiredEnvVar];
result.push(requiredEnvVar);
}
}
return result;
};
var getMissingEnvVars = function (requiredEnvVarsArray, availableEnvVarsArray) {
return plugins.lodash.difference(requiredEnvVarsArray, availableEnvVarsArray);
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBRTFDO0lBSUksY0FBWS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