ready for primetime
This commit is contained in:
parent
612f8307b8
commit
1d4808ed4a
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
export declare class qenv {
|
||||
export declare class Qenv {
|
||||
requiredEnvVars: string[];
|
||||
availableEnvVars: string[];
|
||||
missingEnvVars: string[];
|
||||
|
26
dist/index.js
vendored
26
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
test/assets/env.yml
Normal file
2
test/assets/env.yml
Normal file
@ -0,0 +1,2 @@
|
||||
key1: fromYml
|
||||
key2: fromYml
|
4
test/assets/qenv.yml
Normal file
4
test/assets/qenv.yml
Normal file
@ -0,0 +1,4 @@
|
||||
vars:
|
||||
- key1
|
||||
- key2
|
||||
- key3
|
2
test/test.d.ts
vendored
Normal file
2
test/test.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import "typings-test";
|
||||
import "should";
|
23
test/test.js
Normal file
23
test/test.js
Normal file
@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
var path = require("path");
|
||||
require("should");
|
||||
var index_1 = require("../dist/index");
|
||||
process.cwd = function () {
|
||||
return path.join(__dirname, "./assets/");
|
||||
};
|
||||
process.env["key1"] = "original";
|
||||
var qenvTestObject;
|
||||
describe("Qenv class", function () {
|
||||
it("should create a new class", function () {
|
||||
qenvTestObject = new index_1.Qenv(process.cwd(), process.cwd());
|
||||
});
|
||||
it("key1 should be not be overwritten since it is already present", function () {
|
||||
process.env.key1.should.equal("original");
|
||||
});
|
||||
it("key2 should be read from Yml", function () {
|
||||
process.env.key2.should.equal("fromYml");
|
||||
});
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBWSxJQUFJLFdBQU0sTUFBTSxDQ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SBcIi4uL2Rpc3QvaW5kZXhcIjtcblxucHJvY2Vzcy5jd2QgPSAoKSA9PiB7XG4gICAgcmV0dXJuIHBhdGguam9pbihfX2Rpcm5hbWUsXCIuL2Fzc2V0cy9cIik7XG59XG5cbnByb2Nlc3MuZW52W1wia2V5MVwiXSA9IFwib3JpZ2luYWxcIlxuXG5sZXQgcWVudlRlc3RPYmplY3Q6UWVudjtcbmRlc2NyaWJlKFwiUWVudiBjbGFzc1wiLGZ1bmN0aW9uKCl7XG4gICAgaXQoXCJzaG91bGQgY3JlYXRlIGEgbmV3IGNsYXNzXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcWVudlRlc3RPYmplY3QgPSBuZXcgUWVudihwcm9jZXNzLmN3ZCgpLHByb2Nlc3MuY3dkKCkpO1xuICAgIH0pO1xuICAgIGl0KFwia2V5MSBzaG91bGQgYmUgbm90IGJlIG92ZXJ3cml0dGVuIHNpbmNlIGl0IGlzIGFscmVhZHkgcHJlc2VudFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIHByb2Nlc3MuZW52LmtleTEuc2hvdWxkLmVxdWFsKFwib3JpZ2luYWxcIik7XG4gICAgfSk7XG4gICAgaXQoXCJrZXkyIHNob3VsZCBiZSByZWFkIGZyb20gWW1sXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcHJvY2Vzcy5lbnYua2V5Mi5zaG91bGQuZXF1YWwoXCJmcm9tWW1sXCIpO1xuICAgIH0pXG5cbn0pOyJdfQ==
|
24
test/test.ts
24
test/test.ts
@ -0,0 +1,24 @@
|
||||
import "typings-test";
|
||||
import * as path from "path";
|
||||
import "should";
|
||||
import {Qenv} from "../dist/index";
|
||||
|
||||
process.cwd = () => {
|
||||
return path.join(__dirname,"./assets/");
|
||||
}
|
||||
|
||||
process.env["key1"] = "original"
|
||||
|
||||
let qenvTestObject:Qenv;
|
||||
describe("Qenv class",function(){
|
||||
it("should create a new class",function(){
|
||||
qenvTestObject = new Qenv(process.cwd(),process.cwd());
|
||||
});
|
||||
it("key1 should be not be overwritten since it is already present",function(){
|
||||
process.env.key1.should.equal("original");
|
||||
});
|
||||
it("key2 should be read from Yml",function(){
|
||||
process.env.key2.should.equal("fromYml");
|
||||
})
|
||||
|
||||
});
|
18
ts/index.ts
18
ts/index.ts
@ -1,6 +1,6 @@
|
||||
import * as plugins from "./qenv.plugins";
|
||||
|
||||
export class qenv {
|
||||
export class Qenv {
|
||||
requiredEnvVars:string[];
|
||||
availableEnvVars:string[];
|
||||
missingEnvVars:string[];
|
||||
@ -8,6 +8,9 @@ export class qenv {
|
||||
this.requiredEnvVars = getRequiredEnvVars(basePathArg);
|
||||
this.availableEnvVars = getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg);
|
||||
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars);
|
||||
for(let keyArg in this.missingEnvVars){
|
||||
plugins.beautylog.warn(this.missingEnvVars[keyArg] + " is required, but missing!")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -23,6 +26,7 @@ let getRequiredEnvVars = (pathArg:string):string[] => {
|
||||
|
||||
let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):string[] => {
|
||||
let result = [];
|
||||
envYmlPathArg = plugins.path.join(envYmlPathArg,"env.yml")
|
||||
let envYml;
|
||||
try {
|
||||
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
|
||||
@ -31,12 +35,12 @@ let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):str
|
||||
envYml = {};
|
||||
}
|
||||
for(let keyArg in requiredEnvVarsArg){
|
||||
let envVar:string = requiredEnvVarsArg[keyArg];
|
||||
if(process.env[envVar]){
|
||||
result.push(envVar);
|
||||
} else if(envYml.hasOwnPropery(envVar)){
|
||||
process.env[envVar] = envYml.envVar;
|
||||
result.push(envVar);
|
||||
let requiredEnvVar:string = requiredEnvVarsArg[keyArg];
|
||||
if(process.env[requiredEnvVar]){
|
||||
result.push(requiredEnvVar);
|
||||
} else if(envYml.hasOwnProperty(requiredEnvVar)){
|
||||
process.env[requiredEnvVar] = envYml[requiredEnvVar];
|
||||
result.push(requiredEnvVar);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user