improve log output
This commit is contained in:
parent
2fa659a22a
commit
a84a257e4b
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -2,5 +2,5 @@ export declare class Qenv {
|
|||||||
requiredEnvVars: string[];
|
requiredEnvVars: string[];
|
||||||
availableEnvVars: string[];
|
availableEnvVars: string[];
|
||||||
missingEnvVars: string[];
|
missingEnvVars: string[];
|
||||||
constructor(basePathArg: string, envYmlPathArg: any);
|
constructor(basePathArg: string, envYmlPathArg: any, failOnMissing?: boolean);
|
||||||
}
|
}
|
||||||
|
16
dist/index.js
vendored
16
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ process.env["key1"] = "original";
|
|||||||
var qenvTestObject;
|
var qenvTestObject;
|
||||||
describe("Qenv class", function () {
|
describe("Qenv class", function () {
|
||||||
it("should create a new class", function () {
|
it("should create a new class", function () {
|
||||||
qenvTestObject = new index_1.Qenv(process.cwd(), process.cwd());
|
qenvTestObject = new index_1.Qenv(process.cwd(), process.cwd(), false);
|
||||||
});
|
});
|
||||||
it("key1 should be not be overwritten since it is already present", function () {
|
it("key1 should be not be overwritten since it is already present", function () {
|
||||||
process.env.key1.should.equal("original");
|
process.env.key1.should.equal("original");
|
||||||
@ -20,4 +20,4 @@ describe("Qenv class", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBWSxJQUFJLFdBQU0sTUFBTSxDQUFDLENBQUE7QUFDN0IsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixzQkFBbUIsZUFBZSxDQUFDLENBQUE7QUFFbkMsT0FBTyxDQUFDLEdBQUcsR0FBRztJQUNWLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSx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cIixmdW5jdGlvbigpe1xuICAgIGl0KFwic2hvdWxkIGNyZWF0ZSBhIG5ldyBjbGFzc1wiLGZ1bmN0aW9uKCl7XG4gICAgICAgIHFlbnZUZXN0T2JqZWN0ID0gbmV3IFFlbnYocHJvY2Vzcy5jd2QoKSxwcm9jZXNzLmN3ZCgpLGZhbHNlKTtcbiAgICB9KTtcbiAgICBpdChcImtleTEgc2hvdWxkIGJlIG5vdCBiZSBvdmVyd3JpdHRlbiBzaW5jZSBpdCBpcyBhbHJlYWR5IHByZXNlbnRcIixmdW5jdGlvbigpe1xuICAgICAgICBwcm9jZXNzLmVudi5rZXkxLnNob3VsZC5lcXVhbChcIm9yaWdpbmFsXCIpO1xuICAgIH0pO1xuICAgIGl0KFwia2V5MiBzaG91bGQgYmUgcmVhZCBmcm9tIFltbFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIHByb2Nlc3MuZW52LmtleTIuc2hvdWxkLmVxdWFsKFwiZnJvbVltbFwiKTtcbiAgICB9KVxuXG59KTsiXX0=
|
||||||
|
@ -12,7 +12,7 @@ process.env["key1"] = "original"
|
|||||||
let qenvTestObject:Qenv;
|
let qenvTestObject:Qenv;
|
||||||
describe("Qenv class",function(){
|
describe("Qenv class",function(){
|
||||||
it("should create a new class",function(){
|
it("should create a new class",function(){
|
||||||
qenvTestObject = new Qenv(process.cwd(),process.cwd());
|
qenvTestObject = new Qenv(process.cwd(),process.cwd(),false);
|
||||||
});
|
});
|
||||||
it("key1 should be not be overwritten since it is already present",function(){
|
it("key1 should be not be overwritten since it is already present",function(){
|
||||||
process.env.key1.should.equal("original");
|
process.env.key1.should.equal("original");
|
||||||
|
14
ts/index.ts
14
ts/index.ts
@ -4,12 +4,19 @@ export class Qenv {
|
|||||||
requiredEnvVars:string[];
|
requiredEnvVars:string[];
|
||||||
availableEnvVars:string[];
|
availableEnvVars:string[];
|
||||||
missingEnvVars:string[];
|
missingEnvVars:string[];
|
||||||
constructor(basePathArg = process.cwd(),envYmlPathArg){
|
constructor(basePathArg = process.cwd(),envYmlPathArg,failOnMissing = true){
|
||||||
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
||||||
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg);
|
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg);
|
||||||
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars);
|
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars);
|
||||||
for(let keyArg in this.missingEnvVars){
|
|
||||||
plugins.beautylog.warn(this.missingEnvVars[keyArg] + " is required, but missing!")
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -32,6 +39,7 @@ let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):str
|
|||||||
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
||||||
}
|
}
|
||||||
catch(err){
|
catch(err){
|
||||||
|
plugins.beautylog.log("env file couldn't be found at " + envYmlPathArg)
|
||||||
envYml = {};
|
envYml = {};
|
||||||
}
|
}
|
||||||
for(let keyArg in requiredEnvVarsArg){
|
for(let keyArg in requiredEnvVarsArg){
|
||||||
|
Loading…
Reference in New Issue
Block a user