added figlet

This commit is contained in:
Philipp Kunz 2016-02-11 04:04:49 +01:00
parent 5c52e6f9ed
commit aa4f3d980a
11 changed files with 121 additions and 14 deletions

View File

@ -6,6 +6,7 @@ beautiful logging
[![Dependency Status](https://david-dm.org/pushrocks/beautylog.svg)](https://david-dm.org/pushrocks/beautylog)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/beautylog/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/beautylog/master/dependencies/npm)
[![bitHound Score](https://www.bithound.io/github/pushrocks/beautylog/badges/score.svg)](https://www.bithound.io/github/pushrocks/beautylog)
[![Coverage Status](https://coveralls.io/repos/github/pushrocks/beautylog/badge.svg?branch=greenkeeper-npmts-2.1.10)](https://coveralls.io/github/pushrocks/beautylog?branch=greenkeeper-npmts-2.1.10)
## Usage
```javascript

5
index.d.ts vendored
View File

@ -26,8 +26,13 @@ declare module BeautylogNodeTable {
var cliTable: any;
function init(): any;
}
declare module BeautylogNodeFiglet {
var init: () => (textArg: string, optionsArg?: any) => void;
}
declare module BeautylogBrowser {
function init(): any;
}
declare module BeautylogPromiseChain {
}
declare var plugins: any;
declare var beautylog: any;

View File

@ -3,10 +3,20 @@
/// <reference path="./index.ts" />
var BeautylogPlugins;
(function (BeautylogPlugins) {
var plugins = {};
BeautylogPlugins.init = function () {
var plugins = {
smartenv: require("smartenv")
plugins = {
lodash: require("lodash"),
smartenv: require("smartenv"),
q: require("q")
};
if (plugins.smartenv.getEnv().isNode) {
plugins = plugins.lodash.assign(plugins, {
colors: require("colors"),
clc: require("cli-color"),
figlet: require("figlet")
});
}
return plugins;
};
})(BeautylogPlugins || (BeautylogPlugins = {}));
@ -63,12 +73,11 @@ var ConsoleTable = (function () {
var BeautylogNode;
(function (BeautylogNode) {
function init() {
plugins.colors = require("colors");
plugins.clc = require("cli-color");
var beautylogNode = {
log: BeautylogNodeLog.init(),
code: BeautylogNodeCode.init()
}; //object to append to all public facing functions
code: BeautylogNodeCode.init(),
figlet: BeautylogNodeFiglet.init()
};
/**
* logs an directory to console
* @param logText
@ -221,6 +230,36 @@ var BeautylogNodeTable;
BeautylogNodeTable.init = init;
})(BeautylogNodeTable || (BeautylogNodeTable = {}));
/// <reference path="./index.ts" />
var BeautylogNodeFiglet;
(function (BeautylogNodeFiglet) {
var figlet = function (textArg, optionsArg) {
var defaultOptions = {
font: "Star Wars",
color: "green",
cb: function () { }
};
var options = plugins.lodash.assign(defaultOptions, optionsArg);
plugins.figlet(textArg, {
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
}, function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data[options.color]);
options.cb();
});
};
BeautylogNodeFiglet.init = function () {
var done = plugins.q.defer();
done.resolve();
return figlet;
};
})(BeautylogNodeFiglet || (BeautylogNodeFiglet = {}));
/// <reference path="./index.ts" />
var BeautylogBrowser;
(function (BeautylogBrowser) {
function init() {
@ -244,6 +283,7 @@ var BeautylogBrowser;
}
BeautylogBrowser.init = init;
})(BeautylogBrowser || (BeautylogBrowser = {}));
/// <reference path="./index.ts" />
/// <reference path="./typings/main.d.ts" />
/// <reference path="./beautylog.plugins.ts" />
/// <reference path="./beautylog.classes.ts" />
@ -251,7 +291,9 @@ var BeautylogBrowser;
/// <reference path="./beautylog.node.log.ts" />
/// <reference path="./beautylog.node.code.ts" />
/// <reference path="./beautylog.node.table.ts" />
/// <reference path="./beautylog.node.figlet.ts" />
/// <reference path="./beautylog.browser.ts" />
/// <reference path="./beautylog.promisechain.ts" />
var plugins = BeautylogPlugins.init();
var beautylog = (function () {
switch (plugins.smartenv.getEnv().runtimeEnv) {

View File

@ -33,7 +33,10 @@
"cli-color": "^1.1.0",
"cli-table2": "^0.2.0",
"colors": "1.1.2",
"figlet": "^1.1.1",
"hlight": "0.0.7",
"lodash": "^4.3.0",
"q": "^1.4.1",
"smartenv": "0.0.15"
},
"devDependencies": {

View File

@ -24,7 +24,7 @@ describe("beautylog", function () {
});
});
describe(".error(message)", function () {
it("sould print a red error message", function () {
it("should print a red error message", function () {
beautylog.error('beautylog.error(), with normal logText, without logType');
});
});
@ -62,6 +62,12 @@ describe("beautylog", function () {
})();
});
});
describe(".figlet", function () {
it("should print nice fonts to console in yellow", function (done) {
this.timeout(10000);
beautylog.figlet("Awesome!", { font: "Star Wars", color: "yellow", cb: done });
});
});
describe(".code", function () {
it("should highlight code", function () {
this.timeout(10000);

View File

@ -0,0 +1,29 @@
/// <reference path="./index.ts" />
module BeautylogNodeFiglet {
var figlet = function(textArg:string,optionsArg?){
var defaultOptions = {
font:"Star Wars",
color: "green",
cb: function(){}
};
var options = plugins.lodash.assign(defaultOptions,optionsArg);
plugins.figlet(textArg,{
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
}, function(err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data[options.color]);
options.cb();
});
}
export var init = function(){
var done = plugins.q.defer();
done.resolve();
return figlet;
};
}

View File

@ -1,13 +1,12 @@
/// <reference path="./index.ts" />
module BeautylogNode {
export function init() {
plugins.colors = require("colors");
plugins.clc = require("cli-color");
var beautylogNode:any = {
log:BeautylogNodeLog.init(),
code:BeautylogNodeCode.init()
}; //object to append to all public facing functions
code:BeautylogNodeCode.init(),
figlet:BeautylogNodeFiglet.init()
};
/**
* logs an directory to console

View File

@ -1,9 +1,19 @@
/// <reference path="./index.ts" />
module BeautylogPlugins {
var plugins:any = {};
export var init = function(){
var plugins:any = {
smartenv: require("smartenv")
plugins = {
lodash: require("lodash"),
smartenv: require("smartenv"),
q: require("q")
};
if (plugins.smartenv.getEnv().isNode){
plugins = plugins.lodash.assign(plugins,{
colors: require("colors"),
clc: require("cli-color"),
figlet: require("figlet")
});
}
return plugins;
};
}

View File

@ -0,0 +1,4 @@
/// <reference path="./index.ts" />
module BeautylogPromiseChain {
}

View File

@ -5,7 +5,9 @@
/// <reference path="./beautylog.node.log.ts" />
/// <reference path="./beautylog.node.code.ts" />
/// <reference path="./beautylog.node.table.ts" />
/// <reference path="./beautylog.node.figlet.ts" />
/// <reference path="./beautylog.browser.ts" />
/// <reference path="./beautylog.promisechain.ts" />
var plugins = BeautylogPlugins.init();
var beautylog = (function() {

View File

@ -23,7 +23,7 @@ describe("beautylog",function(){
})
})
describe(".error(message)",function(){
it("sould print a red error message",function(){
it("should print a red error message",function(){
beautylog.error('beautylog.error(), with normal logText, without logType');
});
});
@ -62,6 +62,12 @@ describe("beautylog",function(){
})();
});
});
describe(".figlet",function(){
it("should print nice fonts to console in yellow",function(done){
this.timeout(10000);
beautylog.figlet("Awesome!",{font:"Star Wars",color:"yellow",cb:done});
})
});
describe(".code",function(){
it("should highlight code",function(){
this.timeout(10000);