Compare commits

..

7 Commits

Author SHA1 Message Date
c61ef2eeba 1.0.5 2016-06-20 11:21:26 +02:00
41c97c4c05 improve README 2016-06-20 11:21:21 +02:00
8870f9adf2 1.0.4 2016-06-20 11:04:19 +02:00
dfb400ba5c improve README 2016-06-20 11:04:16 +02:00
38609031d9 1.0.3 2016-06-20 10:45:46 +02:00
1d4808ed4a ready for primetime 2016-06-20 10:45:43 +02:00
612f8307b8 improve 2016-06-20 07:06:15 +02:00
13 changed files with 166 additions and 21 deletions

View File

@ -2,6 +2,18 @@
provides an easy way for promised environments provides an easy way for promised environments
## Usage ## Usage
qenv looks for an qenv.yml that defines needed env vars. qenv dirst checks if they are already specified. qenv works with two files:
If not, qenv by default looks for a .nogit/env.yml file.
If any env var is not specified, qenv throws an error and exits. * **qenv.yml** - specifies which ENV vars are required.
* **env.yml** specifies all env vars that are not already set in the current environment.
Now obviously you can set build specific env vars in many CI environments.
So there we do not need an **env.yml** since all ENV vars are in place
However when on another machine you can have a env.yml that will be added to the environment by qenv.
```typescript
import {Qenv} from "qenv";
myQenv = new Qenv("path/to/dir/where/qenv.yml/is/","path/to/dir/where/env.yml/is(");
```

6
dist/index.d.ts vendored
View File

@ -0,0 +1,6 @@
export declare class Qenv {
requiredEnvVars: string[];
availableEnvVars: string[];
missingEnvVars: string[];
constructor(basePathArg: string, envYmlPathArg: any);
}

53
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,5 @@
import "typings-global"; import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export declare let lodash: any;
export import path = require("path");
export import smartfile = require("smartfile"); export import smartfile = require("smartfile");

View File

@ -1,6 +1,8 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.beautylog = require("beautylog"); exports.beautylog = require("beautylog");
exports.lodash = require("lodash");
exports.path = require("path");
exports.smartfile = require("smartfile"); exports.smartfile = require("smartfile");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJ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BvcnQgc21hcnRmaWxlID0gcmVxdWlyZShcInNtYXJ0ZmlsZVwiKTtcbiJdfQ==

View File

@ -1,6 +1,6 @@
{ {
"name": "qenv", "name": "qenv",
"version": "1.0.2", "version": "1.0.5",
"description": "promised environments", "description": "promised environments",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
@ -28,6 +28,7 @@
}, },
"dependencies": { "dependencies": {
"beautylog": "^5.0.12", "beautylog": "^5.0.12",
"lodash": "^4.13.1",
"q": "^1.4.1", "q": "^1.4.1",
"smartfile": "^3.0.10", "smartfile": "^3.0.10",
"typings-global": "^1.0.3" "typings-global": "^1.0.3"

2
test/assets/env.yml Normal file
View File

@ -0,0 +1,2 @@
key1: fromYml
key2: fromYml

4
test/assets/qenv.yml Normal file
View File

@ -0,0 +1,4 @@
vars:
- key1
- key2
- key3

2
test/test.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
import "typings-test";
import "should";

23
test/test.js Normal file
View 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsSUFBWSxJQUFJLFdBQU0sTUFBTSxDQUFDLENBQUE7QUFDN0IsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixzQkFBbUIsZUFBZSxDQUFDLENBQUE7QUFFbkMsT0FBTyxDQUFDLEdBQ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2Fzc2V0cy9cIik7XG59XG5cbnByb2Nlc3MuZW52W1wia2V5MVwiXSA9IFwib3JpZ2luYWxcIlxuXG5sZXQgcWVudlRlc3RPYmplY3Q6UWVudjtcbmRlc2NyaWJlKFwiUWVudiBjbGFzc1wiLGZ1bmN0aW9uKCl7XG4gICAgaXQoXCJzaG91bGQgY3JlYXRlIGEgbmV3IGNsYXNzXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcWVudlRlc3RPYmplY3QgPSBuZXcgUWVudihwcm9jZXNzLmN3ZCgpLHByb2Nlc3MuY3dkKCkpO1xuICAgIH0pO1xuICAgIGl0KFwia2V5MSBzaG91bGQgYmUgbm90IGJlIG92ZXJ3cml0dGVuIHNpbmNlIGl0IGlzIGFscmVhZHkgcHJlc2VudFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIHByb2Nlc3MuZW52LmtleTEuc2hvdWxkLmVxdWFsKFwib3JpZ2luYWxcIik7XG4gICAgfSk7XG4gICAgaXQoXCJrZXkyIHNob3VsZCBiZSByZWFkIGZyb20gWW1sXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgcHJvY2Vzcy5lbnYua2V5Mi5zaG91bGQuZXF1YWwoXCJmcm9tWW1sXCIpO1xuICAgIH0pXG5cbn0pOyJdfQ==

24
test/test.ts Normal file
View File

@ -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");
})
});

View File

@ -1,16 +1,20 @@
import * as plugins from "./qenv.plugins"; import * as plugins from "./qenv.plugins";
export class qenv { export class Qenv {
envVarsRequired:string[]; requiredEnvVars:string[];
envVarsAvailable:string[]; availableEnvVars:string[];
envVarsMissing:string[]; missingEnvVars:string[];
constructor(basePathArg = "./qenv.yml",envYmlPathArg){ constructor(basePathArg = process.cwd(),envYmlPathArg){
this.envVarsRequired = getEnvVarsRequired(basePathArg); this.requiredEnvVars = getRequiredEnvVars(basePathArg);
this.envVarsAvailable; 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!")
}
} }
}; };
let getEnvVarsRequired = (pathArg:string):string[] => { let getRequiredEnvVars = (pathArg:string):string[] => {
let result:string[] = []; let result:string[] = [];
let qenvFilePath = plugins.path.join(pathArg,"qenv.yml"); let qenvFilePath = plugins.path.join(pathArg,"qenv.yml");
let qenvFile = plugins.smartfile.local.toObjectSync(qenvFilePath); let qenvFile = plugins.smartfile.local.toObjectSync(qenvFilePath);
@ -20,15 +24,28 @@ let getEnvVarsRequired = (pathArg:string):string[] => {
return result; return result;
} }
let getEnvVarsAvailable = (requiredEnvVarsArg:string[]):string[] => { let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string):string[] => {
let result = []; let result = [];
envYmlPathArg = plugins.path.join(envYmlPathArg,"env.yml")
let envYml;
try {
envYml = plugins.smartfile.local.toObjectSync(envYmlPathArg);
}
catch(err){
envYml = {};
}
for(let keyArg in requiredEnvVarsArg){ for(let keyArg in requiredEnvVarsArg){
let envVar = requiredEnvVarsArg[keyArg]; let requiredEnvVar:string = requiredEnvVarsArg[keyArg];
if(process.env[envVar]){ if(process.env[requiredEnvVar]){
result.push(envVar); result.push(requiredEnvVar);
} else { } else if(envYml.hasOwnProperty(requiredEnvVar)){
process.env[requiredEnvVar] = envYml[requiredEnvVar];
result.push(requiredEnvVar);
} }
} }
return result; return result;
}
let getMissingEnvVars = (requiredEnvVarsArray:string[],availableEnvVarsArray:string[]) => {
return plugins.lodash.difference(requiredEnvVarsArray,availableEnvVarsArray);
} }

View File

@ -1,4 +1,5 @@
import "typings-global"; import "typings-global";
export import beautylog = require("beautylog"); export import beautylog = require("beautylog");
export let lodash = require("lodash");
export import path = require("path"); export import path = require("path");
export import smartfile = require("smartfile"); export import smartfile = require("smartfile");