improve
This commit is contained in:
parent
de6045842d
commit
612f8307b8
6
dist/index.d.ts
vendored
6
dist/index.d.ts
vendored
@ -0,0 +1,6 @@
|
||||
export declare class qenv {
|
||||
requiredEnvVars: string[];
|
||||
availableEnvVars: string[];
|
||||
missingEnvVars: string[];
|
||||
constructor(basePathArg: string, envYmlPathArg: any);
|
||||
}
|
49
dist/index.js
vendored
49
dist/index.js
vendored
@ -1,3 +1,48 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXX0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBRTFDO0lBSUksY0FBWSxXQUEyQixFQUFDLGFBQWE7UUFBekMsMkJBQTJCLEdBQTNCLGNBQWMsT0FBTyxDQUFDLEdBQUcsRUFBRTtRQUNuQyxJQUFJLENBQUMsZUFBZSxHQUFHLGtCQUFrQixDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ3ZELElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxtQkFBbUIsQ0FBQyxJQUFJLENBQUMsZUFBZSxFQUFDLGFBQWEsQ0FBQyxDQUFDO1FBQ2hGLElBQUksQ0FBQyxjQUFjLEdBQUcsaUJBQWlCLENBQUMsSUFBSSxDQUFDLGVBQWUsRUFBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUN4RixDQUFDO0lBQ0wsV0FBQztBQUFELENBVEEsQUFTQyxJQUFBO0FBVFksWUFBSSxPQVNoQixDQUFBO0FBQUEsQ0FBQztBQUVGLElBQUksa0JBQWtCLEdBQUcsVUFBQyxPQUFjO0lBQ3BDLElBQUksTUFBTSxHQUFZLEVBQUUsQ0FBQztJQUN6QixJQUFJLFlBQVksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUks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cy5lbnZbZW52VmFyXSl7XG4gICAgICAgICAgICByZXN1bHQucHVzaChlbnZWYXIpO1xuICAgICAgICB9IGVsc2UgaWYoZW52WW1sLmhhc093blByb3BlcnkoZW52VmFyKSl7XG4gICAgICAgICAgICBwcm9jZXNzLmVudltlbnZWYXJdID0gZW52WW1sLmVudlZhcjtcbiAgICAgICAgICAgIHJlc3VsdC5wdXNoKGVudlZhcik7XG4gICAgICAgIH1cbiAgICB9XG4gICAgcmV0dXJuIHJlc3VsdDtcbn1cblxubGV0IGdldE1pc3NpbmdFbnZWYXJzID0gKHJlcXVpcmVkRW52VmFyc0FycmF5OnN0cmluZ1tdLGF2YWlsYWJsZUVudlZhcnNBcnJheTpzdHJpbmdbXSkgPT4ge1xuICAgIHJldHVybiBwbHVnaW5zLmxvZGFzaC5kaWZmZXJlbmNlKHJlcXVpcmVkRW52VmFyc0FycmF5LGF2YWlsYWJsZUVudlZhcnNBcnJheSk7XG59Il19
|
||||
|
2
dist/qenv.plugins.d.ts
vendored
2
dist/qenv.plugins.d.ts
vendored
@ -1,3 +1,5 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export declare let lodash: any;
|
||||
export import path = require("path");
|
||||
export import smartfile = require("smartfile");
|
||||
|
4
dist/qenv.plugins.js
vendored
4
dist/qenv.plugins.js
vendored
@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.lodash = require("lodash");
|
||||
exports.path = require("path");
|
||||
exports.smartfile = require("smartfile");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInFlbnYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InFlbnYucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgaW1wb3J0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgaW1wb3J0IHNtYXJ0ZmlsZSA9IHJlcXVpcmUoXCJzbWFydGZpbGVcIik7XG4iXX0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInFlbnYucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxjQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQ3hCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InFlbnYucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5leHBvcnQgaW1wb3J0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IGxvZGFzaCA9IHJlcXVpcmUoXCJsb2Rhc2hcIik7XG5leHBvcnQgaW1wb3J0IHBhdGggPSByZXF1aXJlKFwicGF0aFwiKTtcbmV4cG9ydCBpbXBvcnQgc21hcnRmaWxlID0gcmVxdWlyZShcInNtYXJ0ZmlsZVwiKTtcbiJdfQ==
|
||||
|
@ -28,6 +28,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.12",
|
||||
"lodash": "^4.13.1",
|
||||
"q": "^1.4.1",
|
||||
"smartfile": "^3.0.10",
|
||||
"typings-global": "^1.0.3"
|
||||
|
0
test/test.ts
Normal file
0
test/test.ts
Normal file
35
ts/index.ts
35
ts/index.ts
@ -1,16 +1,17 @@
|
||||
import * as plugins from "./qenv.plugins";
|
||||
|
||||
export class qenv {
|
||||
envVarsRequired:string[];
|
||||
envVarsAvailable:string[];
|
||||
envVarsMissing:string[];
|
||||
constructor(basePathArg = "./qenv.yml",envYmlPathArg){
|
||||
this.envVarsRequired = getEnvVarsRequired(basePathArg);
|
||||
this.envVarsAvailable;
|
||||
requiredEnvVars:string[];
|
||||
availableEnvVars:string[];
|
||||
missingEnvVars:string[];
|
||||
constructor(basePathArg = process.cwd(),envYmlPathArg){
|
||||
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
||||
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg);
|
||||
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars);
|
||||
}
|
||||
};
|
||||
|
||||
let getEnvVarsRequired = (pathArg:string):string[] => {
|
||||
let getRequiredEnvVars = (pathArg:string):string[] => {
|
||||
let result:string[] = [];
|
||||
let qenvFilePath = plugins.path.join(pathArg,"qenv.yml");
|
||||
let qenvFile = plugins.smartfile.local.toObjectSync(qenvFilePath);
|
||||
@ -20,15 +21,27 @@ let getEnvVarsRequired = (pathArg:string):string[] => {
|
||||
return result;
|
||||
}
|
||||
|
||||
let getEnvVarsAvailable = (requiredEnvVarsArg:string[]):string[] => {
|
||||
let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):string[] => {
|
||||
let result = [];
|
||||
let envYml;
|
||||
try {
|
||||
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
||||
}
|
||||
catch(err){
|
||||
envYml = {};
|
||||
}
|
||||
for(let keyArg in requiredEnvVarsArg){
|
||||
let envVar = requiredEnvVarsArg[keyArg];
|
||||
let envVar:string = requiredEnvVarsArg[keyArg];
|
||||
if(process.env[envVar]){
|
||||
result.push(envVar);
|
||||
} else {
|
||||
|
||||
} else if(envYml.hasOwnPropery(envVar)){
|
||||
process.env[envVar] = envYml.envVar;
|
||||
result.push(envVar);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
let getMissingEnvVars = (requiredEnvVarsArray:string[],availableEnvVarsArray:string[]) => {
|
||||
return plugins.lodash.difference(requiredEnvVarsArray,availableEnvVarsArray);
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export let lodash = require("lodash");
|
||||
export import path = require("path");
|
||||
export import smartfile = require("smartfile");
|
||||
|
Loading…
Reference in New Issue
Block a user