remove beautylog dependency

This commit is contained in:
Philipp Kunz 2017-01-21 11:51:30 +01:00
parent 7de17bbefa
commit ead69f3bb9
10 changed files with 98 additions and 104 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules/ node_modules/
coverage/ coverage/
pages/ pages/
pubic/ public/

16
dist/index.js vendored
View File

@ -10,14 +10,14 @@ class Qenv {
getRequiredEnvVars(basePathArg, this.requiredEnvVars); getRequiredEnvVars(basePathArg, this.requiredEnvVars);
getAvailableEnvVars(this.requiredEnvVars, envYmlPathArg, this.availableEnvVars, this.keyValueObjectArray); getAvailableEnvVars(this.requiredEnvVars, envYmlPathArg, this.availableEnvVars, this.keyValueObjectArray);
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars, this.availableEnvVars); this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars, this.availableEnvVars);
//handle missing variables // handle missing variables
if (this.missingEnvVars.length > 0) { if (this.missingEnvVars.length > 0) {
plugins.beautylog.info("Required Env Vars are:"); console.info('Required Env Vars are:');
console.log(this.requiredEnvVars); console.log(this.requiredEnvVars);
plugins.beautylog.error("However some Env variables could not be resolved:"); console.error('However some Env variables could not be resolved:');
console.log(this.missingEnvVars); console.log(this.missingEnvVars);
if (failOnMissing) { if (failOnMissing) {
plugins.beautylog.error("Exiting!"); console.error('Exiting!');
process.exit(1); process.exit(1);
} }
} }
@ -27,7 +27,7 @@ class Qenv {
exports.Qenv = Qenv; exports.Qenv = Qenv;
; ;
let getRequiredEnvVars = (pathArg, requiredEnvVarsArray) => { let getRequiredEnvVars = (pathArg, requiredEnvVarsArray) => {
let qenvFilePath = plugins.path.join(pathArg, "qenv.yml"); let qenvFilePath = plugins.path.join(pathArg, 'qenv.yml');
let qenvFile = plugins.smartfile.fs.toObjectSync(qenvFilePath); let qenvFile = plugins.smartfile.fs.toObjectSync(qenvFilePath);
for (let keyArg in qenvFile.vars) { for (let keyArg in qenvFile.vars) {
requiredEnvVarsArray.push(qenvFile.vars[keyArg]); requiredEnvVarsArray.push(qenvFile.vars[keyArg]);
@ -35,13 +35,13 @@ let getRequiredEnvVars = (pathArg, requiredEnvVarsArray) => {
; ;
}; };
let getAvailableEnvVars = (requiredEnvVarsArg, envYmlPathArg, availableEnvVarsArray, keyValueObjectArrayArg) => { let getAvailableEnvVars = (requiredEnvVarsArg, envYmlPathArg, availableEnvVarsArray, keyValueObjectArrayArg) => {
envYmlPathArg = plugins.path.join(envYmlPathArg, "env.yml"); envYmlPathArg = plugins.path.join(envYmlPathArg, 'env.yml');
let envYml; let envYml;
try { try {
envYml = plugins.smartfile.fs.toObjectSync(envYmlPathArg); envYml = plugins.smartfile.fs.toObjectSync(envYmlPathArg);
} }
catch (err) { catch (err) {
plugins.beautylog.log("env file couldn't be found at " + envYmlPathArg); console.log("env file couldn't be found at " + envYmlPathArg);
envYml = {}; envYml = {};
} }
for (let requiredEnvVar of requiredEnvVarsArg) { for (let requiredEnvVar of requiredEnvVarsArg) {
@ -66,4 +66,4 @@ let getAvailableEnvVars = (requiredEnvVarsArg, envYmlPathArg, availableEnvVarsAr
let getMissingEnvVars = (requiredEnvVarsArray, availableEnvVarsArray) => { let getMissingEnvVars = (requiredEnvVarsArray, availableEnvVarsArray) => {
return plugins.lodash.difference(requiredEnvVarsArray, availableEnvVarsArray); return plugins.lodash.difference(requiredEnvVarsArray, availableEnvVarsArray);
}; };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMENBQTBDO0FBS3pDLENBQUM7QUFFRjtJQUtJLFlBQVksV0FBVyxHQUFHLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxhQUFhLEVBQUMsYUFBYSxHQUFHLElBQUk7UUFKMUUsb0JBQWUsR0FBWSxFQUFFLENBQUM7UUFDOUIscUJBQWdCLEd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FBO1FBQ04sQ0FBQztJQUNMLENBQUM7SUFBQSxDQUFDO0FBQ04sQ0FBQyxDQUFBO0FBRUQsSUFBSSxpQkFBaUIsR0FBRyxDQUFDLG9CQUE4QixFQUFDLHFCQUErQjtJQUNuRixNQUFNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsb0JBQW9CLEVBQUMscUJBQXFCLENBQUMsQ0FBQTtBQUNoRixDQUFDLENBQUEifQ==

View File

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

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.beautylog = require("beautylog"); exports.lodash = require('lodash');
exports.lodash = require("lodash");
exports.path = require("path"); exports.path = require("path");
exports.smartfile = require("smartfile"); exports.smartfile = require("smartfile");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicWVudi5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvcWVudi5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBd0I7QUFDeEIseUNBQStDO0FBQ3BDLFFBQUEsTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUN0QywrQkFBcUM7QUFDckMseUNBQStDIn0= //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicWVudi5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvcWVudi5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBd0I7QUFDYixRQUFBLE1BQU0sR0FBRyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFDdEMsK0JBQXFDO0FBQ3JDLHlDQUE4QyJ9

View File

@ -23,15 +23,14 @@
}, },
"homepage": "https://gitlab.com/pushrocks/qenv#README", "homepage": "https://gitlab.com/pushrocks/qenv#README",
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.10", "npmts-g": "^6.0.0",
"should": "^11.1.2", "smartchai": "^1.0.1",
"typings-test": "^1.0.3" "typings-test": "^1.0.3"
}, },
"dependencies": { "dependencies": {
"beautylog": "^6.0.0", "lodash": "^4.17.4",
"lodash": "^4.17.3",
"q": "^1.4.1", "q": "^1.4.1",
"smartfile": "^4.1.0", "smartfile": "^4.1.3",
"typings-global": "^1.0.14" "typings-global": "^1.0.14"
} }
} }

3
test/test.d.ts vendored
View File

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

View File

@ -1,26 +1,26 @@
"use strict"; "use strict";
require("typings-test"); require("typings-test");
const path = require("path"); const path = require("path");
require("should"); const smartchai_1 = require("smartchai");
const index_1 = require("../dist/index"); const index_1 = require("../dist/index");
process.cwd = () => { process.cwd = () => {
return path.join(__dirname, "./assets/"); return path.join(__dirname, './assets/');
}; };
process.env["key1"] = "original"; process.env['key1'] = 'original';
let qenvTestObject; let 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(), false); 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"); smartchai_1.expect(process.env.key1).to.equal('original');
}); });
it("key2 should be read from Yml", function () { it('key2 should be read from Yml', function () {
process.env.key2.should.equal("fromYml"); smartchai_1.expect(process.env.key2).to.equal('fromYml');
}); });
it("keyValueObjectArray should hold all retrieved values", function () { it('keyValueObjectArray should hold all retrieved values', function () {
qenvTestObject.keyValueObjectArray[0].value.should.equal("original"); smartchai_1.expect(qenvTestObject.keyValueObjectArray[0].value).to.equal('original');
qenvTestObject.keyValueObjectArray[1].value.should.equal("fromYml"); smartchai_1.expect(qenvTestObject.keyValueObjectArray[1].value).to.equal('fromYml');
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0Qiw2QkFBNkI7QUFDN0Isa0JBQWdCO0FBQ2hCLHlDQUFtQztBQUVuQyxPQUFPLENBQUMsR0FBRyxHQUFHO0lBQ1YsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLENBQUMsQ0FBQTtBQUVELE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLEdBQUcsVUFBVSxDQUFBO0FBRWhDLElBQUksY0FBbUIsQ0FBQztBQUN4QixRQUFRLENBQUMsWUFBWSxFQUFDO0lBQ2xCLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixjQUFjLEdBQUcsSUFBSSxZQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxLQUFLLENBQUMsQ0FBQztJQUNqRSxDQUFDLENBQUMsQ0FBQztJQUNILEVBQUUsQ0FBQywrREFBK0QsRUFBQztRQUMvRCxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQzlDLENBQUMsQ0FBQyxDQUFDO0lBQ0gsRUFBRSxDQUFDLDhCQUE4QixFQUFDO1FBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FB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RSxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQywrREFBK0QsRUFBQztRQUMvRCxrQkFBTSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUNqRCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyw4QkFBOEIsRUFBQztRQUM5QixrQkFBTSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUMsRUFBRSxDQUFDLEtBQUssQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNoRCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxzREFBc0QsRUFBQztRQUN0RCxrQkFBTSxDQUFDLGNBQWMsQ0FBQyxtQkFBbUIsQ0FBQyxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQ3hFLGtCQUFNLENBQUMsY0FBYyxDQUFDLG1CQUFtQixDQUFDLENBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxDQUFDLEVBQUUsQ0FBQyxLQUFLLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDM0UsQ0FBQyxDQUFDLENBQUE7QUFFTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,28 +1,28 @@
import "typings-test"; import 'typings-test'
import * as path from "path"; import * as path from 'path'
import "should"; import { expect } from 'smartchai'
import {Qenv} from "../dist/index"; import {Qenv} from '../dist/index'
process.cwd = () => { process.cwd = () => {
return path.join(__dirname,"./assets/"); return path.join(__dirname,'./assets/')
} }
process.env["key1"] = "original" 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(),false); 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"); expect(process.env.key1).to.equal('original')
}); })
it("key2 should be read from Yml",function(){ it('key2 should be read from Yml',function(){
process.env.key2.should.equal("fromYml"); expect(process.env.key2).to.equal('fromYml')
}); })
it("keyValueObjectArray should hold all retrieved values",function(){ it('keyValueObjectArray should hold all retrieved values',function(){
qenvTestObject.keyValueObjectArray[0].value.should.equal("original"); expect(qenvTestObject.keyValueObjectArray[0].value).to.equal('original')
qenvTestObject.keyValueObjectArray[1].value.should.equal("fromYml"); expect(qenvTestObject.keyValueObjectArray[1].value).to.equal('fromYml')
}) })
}); })

View File

@ -1,4 +1,4 @@
import * as plugins from "./qenv.plugins"; import * as plugins from "./qenv.plugins"
export interface IKeyValueObject { export interface IKeyValueObject {
key: string, key: string,
@ -6,67 +6,66 @@ export interface IKeyValueObject {
}; };
export class Qenv { export class Qenv {
requiredEnvVars:string[] = []; requiredEnvVars: string[] = []
availableEnvVars:string[] = []; availableEnvVars:string[] = []
missingEnvVars:string[] = []; missingEnvVars:string[] = []
keyValueObjectArray:IKeyValueObject[] = []; keyValueObjectArray:IKeyValueObject[] = []
constructor(basePathArg = process.cwd(),envYmlPathArg,failOnMissing = true){ constructor(basePathArg = process.cwd(),envYmlPathArg,failOnMissing = true){
getRequiredEnvVars(basePathArg,this.requiredEnvVars); getRequiredEnvVars(basePathArg,this.requiredEnvVars)
getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg,this.availableEnvVars,this.keyValueObjectArray); getAvailableEnvVars(this.requiredEnvVars,envYmlPathArg,this.availableEnvVars,this.keyValueObjectArray)
this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars); this.missingEnvVars = getMissingEnvVars(this.requiredEnvVars,this.availableEnvVars)
//handle missing variables // handle missing variables
if (this.missingEnvVars.length > 0){ if (this.missingEnvVars.length > 0){
plugins.beautylog.info("Required Env Vars are:") console.info('Required Env Vars are:')
console.log(this.requiredEnvVars); console.log(this.requiredEnvVars)
plugins.beautylog.error("However some Env variables could not be resolved:"); console.error('However some Env variables could not be resolved:')
console.log(this.missingEnvVars); console.log(this.missingEnvVars)
if(failOnMissing){ if (failOnMissing) {
plugins.beautylog.error("Exiting!") console.error('Exiting!')
process.exit(1); process.exit(1)
} }
} }
}; };
}; };
let getRequiredEnvVars = (pathArg:string, requiredEnvVarsArray:string[]) => { let getRequiredEnvVars = (pathArg: string, requiredEnvVarsArray: string[]) => {
let qenvFilePath = plugins.path.join(pathArg,"qenv.yml"); let qenvFilePath = plugins.path.join(pathArg,'qenv.yml')
let qenvFile = plugins.smartfile.fs.toObjectSync(qenvFilePath); let qenvFile = plugins.smartfile.fs.toObjectSync(qenvFilePath)
for(let keyArg in qenvFile.vars){ for (let keyArg in qenvFile.vars) {
requiredEnvVarsArray.push(qenvFile.vars[keyArg]); requiredEnvVarsArray.push(qenvFile.vars[keyArg])
}; };
} }
let getAvailableEnvVars = (requiredEnvVarsArg:string[],envYmlPathArg:string,availableEnvVarsArray:string[],keyValueObjectArrayArg:IKeyValueObject[]) => { let getAvailableEnvVars = (requiredEnvVarsArg: string[],envYmlPathArg: string,availableEnvVarsArray: string[],keyValueObjectArrayArg: IKeyValueObject[]) => {
envYmlPathArg = plugins.path.join(envYmlPathArg,"env.yml") envYmlPathArg = plugins.path.join(envYmlPathArg,'env.yml')
let envYml; let envYml
try { try {
envYml = plugins.smartfile.fs.toObjectSync(envYmlPathArg); envYml = plugins.smartfile.fs.toObjectSync(envYmlPathArg)
} catch (err) {
console.log("env file couldn't be found at " + envYmlPathArg)
envYml = {}
} }
catch(err){ for (let requiredEnvVar of requiredEnvVarsArg){
plugins.beautylog.log("env file couldn't be found at " + envYmlPathArg) if (process.env[requiredEnvVar]){
envYml = {}; availableEnvVarsArray.push(requiredEnvVar)
}
for(let requiredEnvVar of requiredEnvVarsArg){
if(process.env[requiredEnvVar]){
availableEnvVarsArray.push(requiredEnvVar);
keyValueObjectArrayArg.push({ keyValueObjectArrayArg.push({
key: requiredEnvVar, key: requiredEnvVar,
value: process.env[requiredEnvVar] value: process.env[requiredEnvVar]
}); })
} else if(envYml.hasOwnProperty(requiredEnvVar)){ } else if (envYml.hasOwnProperty(requiredEnvVar)){
process.env[requiredEnvVar] = envYml[requiredEnvVar]; process.env[requiredEnvVar] = envYml[requiredEnvVar]
availableEnvVarsArray.push(requiredEnvVar); availableEnvVarsArray.push(requiredEnvVar)
keyValueObjectArrayArg.push({ keyValueObjectArrayArg.push({
key: requiredEnvVar, key: requiredEnvVar,
value: process.env[requiredEnvVar] value: process.env[requiredEnvVar]
}); })
} }
}; };
}; }
let getMissingEnvVars = (requiredEnvVarsArray:string[],availableEnvVarsArray:string[]) => { let getMissingEnvVars = (requiredEnvVarsArray: string[],availableEnvVarsArray: string[]) => {
return plugins.lodash.difference(requiredEnvVarsArray,availableEnvVarsArray); return plugins.lodash.difference(requiredEnvVarsArray,availableEnvVarsArray)
}; }

View File

@ -1,5 +1,4 @@
import "typings-global"; import 'typings-global';
export import beautylog = require("beautylog"); export let lodash = require('lodash');
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");