49 lines
6.0 KiB
JavaScript
49 lines
6.0 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);
|
|
}
|
|
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 = [];
|
|
var envYml;
|
|
try {
|
|
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
|
}
|
|
catch (err) {
|
|
envYml = {};
|
|
}
|
|
for (var keyArg in requiredEnvVarsArg) {
|
|
var envVar = requiredEnvVarsArg[keyArg];
|
|
if (process.env[envVar]) {
|
|
result.push(envVar);
|
|
}
|
|
else if (envYml.hasOwnPropery(envVar)) {
|
|
process.env[envVar] = envYml.envVar;
|
|
result.push(envVar);
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
var getMissingEnvVars = function (requiredEnvVarsArray, availableEnvVarsArray) {
|
|
return plugins.lodash.difference(requiredEnvVarsArray, availableEnvVarsArray);
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTS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