qenv/dist/index.js

61 lines
8.1 KiB
JavaScript
Raw Normal View History

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) {
plugins.beautylog.error("Some Env variables could not be resolved:");
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:13:29 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBRTFDO0lBSUksY0FBWSxXQUEyQixFQUFDLGFBQWEsRUFBQyxhQUFvQjtRQUE5RCwyQkFBMkIsR0FBM0IsY0FBYyxPQUFPLENBQUMsR0FBRyxFQUFFO1FBQWUsNkJBQW9CLEdBQXBCLG9CQUFvQjtRQUN0RSxJQUFJLENBQUMsZUFBZSxHQUFHLGtCQUFrQixDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ3ZELElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxtQkFBbUIsQ0FBQyxJQUFJLENBQUMsZUFBZSxFQUFDLGFBQWEsQ0FBQyxDQUFDO1FBQ2hGLElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUMsSUFBSSxDQUFDLGVBQWUsRUFBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztRQUVwRiwwQkFBMEI7UUFDMUIsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLGNBQWMsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQU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