added automatic env detection

This commit is contained in:
Phil Kunz 2015-12-26 01:51:04 +01:00
parent 6163e9f57d
commit c256c4b840
15 changed files with 25357 additions and 106 deletions

View File

@ -11,8 +11,7 @@ beautiful logging
```javascript
### Simple Logging
var bl = require('beautylog')("os"); //for use in OS console environment
var bl = require('beautylog')("browser"); //for use in browser console environment like Google Chrome
var bl = require('beautylog'); //for use in OS console environment AND browser console
bl.log('some log message'); //normal console log message

View File

@ -1,4 +1,14 @@
/// <reference path="./index.ts" />
var BeautylogPlugins;
(function (BeautylogPlugins) {
BeautylogPlugins.init = function () {
var plugins = {
smartenv: require("smartenv")
};
return plugins;
};
})(BeautylogPlugins || (BeautylogPlugins = {}));
/// <reference path="./index.ts" />
var tableHelpers = {
makeRow: function (cellCounterArg, colorArg) {
if (cellCounterArg === void 0) { cellCounterArg = 2; }
@ -48,12 +58,12 @@ var ConsoleTable = (function () {
return ConsoleTable;
})();
/// <reference path="./index.ts" />
var BeautylogOS;
(function (BeautylogOS) {
var BeautylogNode;
(function (BeautylogNode) {
function init() {
var colors = require("colors");
var clc = require("cli-color");
var beautylogOS = {}; //object to append to all public facing functions
var beautylogNode = {}; //object to append to all public facing functions
var localBl; // object to append to all private params and functions
localBl = {};
localBl.dirPrefix = clc.bgXterm(39).xterm(231).bold(' DIR ') + ' ';
@ -69,7 +79,7 @@ var BeautylogOS;
* @param logType
* @returns {boolean}
*/
beautylogOS.log = function (logText, logType) {
beautylogNode.log = function (logText, logType) {
if (logText === void 0) { logText = 'empty log'; }
if (logType === void 0) { logType = 'normal'; }
try {
@ -114,54 +124,54 @@ var BeautylogOS;
* @param logText
* @returns {boolean}
*/
beautylogOS.dir = function (logText) {
return beautylogOS.log(logText, 'dir');
beautylogNode.dir = function (logText) {
return beautylogNode.log(logText, 'dir');
};
/**
* logs an error to console
* @param logText
* @returns {boolean}
*/
beautylogOS.error = function (logText) {
return beautylogOS.log(logText, 'error');
beautylogNode.error = function (logText) {
return beautylogNode.log(logText, 'error');
};
/**
* logs an info to console
* @param logText
* @returns {boolean}
*/
beautylogOS.info = function (logText) {
return beautylogOS.log(logText, 'info');
beautylogNode.info = function (logText) {
return beautylogNode.log(logText, 'info');
};
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
beautylogOS.ok = function (logText) {
return beautylogOS.log(logText, 'ok');
beautylogNode.ok = function (logText) {
return beautylogNode.log(logText, 'ok');
};
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
beautylogOS.success = function (logText) {
return beautylogOS.log(logText, 'success');
beautylogNode.success = function (logText) {
return beautylogNode.log(logText, 'success');
};
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
beautylogOS.warn = function (logText) {
return beautylogOS.log(logText, 'warn');
beautylogNode.warn = function (logText) {
return beautylogNode.log(logText, 'warn');
};
beautylogOS.table = BeautylogOsTable.init();
return beautylogOS;
beautylogNode.table = BeautylogOsTable.init();
return beautylogNode;
}
BeautylogOS.init = init;
})(BeautylogOS || (BeautylogOS = {}));
BeautylogNode.init = init;
})(BeautylogNode || (BeautylogNode = {}));
/// <reference path="./index.ts" />
var BeautylogOsTable;
(function (BeautylogOsTable) {
@ -201,15 +211,16 @@ var BeautylogBrowser;
BeautylogBrowser.init = init;
})(BeautylogBrowser || (BeautylogBrowser = {}));
/// <reference path="./typings/tsd.d.ts" />
/// <reference path="./beautylog.plugins.ts" />
/// <reference path="./beautylog.classes.ts" />
/// <reference path="./beautylog.os.ts" />
/// <reference path="./beautylog.os.table.ts" />
/// <reference path="./beautylog.node.ts" />
/// <reference path="./beautylog.node.table.ts" />
/// <reference path="./beautylog.browser.ts" />
var beautylog = function (logPlatform) {
if (logPlatform === void 0) { logPlatform = "os"; }
switch (logPlatform) {
case "os":
var beautylogOs = BeautylogOS.init();
var plugins = BeautylogPlugins.init();
var beautylog = (function () {
switch (plugins.smartenv.getEnv().runtimeEnv) {
case "node":
var beautylogOs = BeautylogNode.init();
return beautylogOs;
break;
case "browser":
@ -217,8 +228,8 @@ var beautylog = function (logPlatform) {
return beautylogBrowser;
break;
default:
console.log("something is strange about the way you required beautylog");
console.log("something is strange about the platform in which you try to use beautylog");
break;
}
};
})();
module.exports = beautylog;

View File

@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "(cd ts/compile && node compile.js) && (node ./test.js)",
"testbrowser": "(npm test) && (node testbrowser.js)",
"gitsetup": "(git config push.followTags true)",
"push": "(git push origin master && git push origin release && git push --follow-tags)",
"reinstall": "(rm -r node_modules && npm install)",
@ -31,11 +32,13 @@
"dependencies": {
"cli-color": "^1.1.0",
"cli-table2": "^0.1.9",
"colors": "1.1.2"
"colors": "1.1.2",
"smartenv": "0.0.15"
},
"devDependencies": {
"easyserve": "0.0.4",
"gulp": "^3.9.0",
"gulp-typescript": "^2.10.0",
"pushrocks": "^1.0.25"
"gulp-browser": "0.0.18",
"gulp-typescript": "^2.10.0"
}
}

39
test.js
View File

@ -1,38 +1,35 @@
/// <reference path="./typings/tsd.d.ts" />
var beautyLogOs = require('./index.js')("os");
var beautyLogBrowser = require("./index.js")("browser");
var smartenv = require("smartenv");
var beautyLog = require('./index.js');
console.log('*** start OS console test ***');
console.log('');
console.log('declarative function calls:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.dir('beautylog.dir(), with normal logText, without logType');
beautyLogOs.error('beautylog.error(), with normal logText, without logType');
beautyLogOs.info('beautylog.dir(), with normal logText, without logType');
beautyLogOs.ok('beautylog.ok(), with normal logText, without logType');
beautyLogOs.success('beautylog.success(), with normal logText, without logType');
beautyLogOs.warn('beautylog.warn(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.dir('beautylog.dir(), with normal logText, without logType');
beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLog.info('beautylog.dir(), with normal logText, without logType');
beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log('');
console.log('logType String:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "dir"', 'dir');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "error"', 'error');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "info"', 'info');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "ok"', 'ok');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "success"', 'success');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "warn"', 'warn');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, with logType "dir"', 'dir');
beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error');
beautyLog.log('beautylog.log(), with normal logText, with logType "info"', 'info');
beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok');
beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success');
beautyLog.log('beautylog.log(), with normal logText, with logType "warn"', 'warn');
console.log('');
console.log('*** end OS console test ***');
console.log("*** start browser console test (Might look weird in OS console and travis log...) ***");
beautyLogBrowser.log("hello");
console.log("*** end browser console test ***");
console.log("*** start table test ***");
(function () {
var testTable1 = beautyLogOs.table.new("checks");
var testTable1 = beautyLog.table.new("checks");
testTable1.push(['check1', 'success']);
testTable1.push(['check2', 'error']);
testTable1.push(['check3', 'error']);
testTable1.print();
var testTable2 = beautyLogOs.table.new("custom", ["Column1".red, "Column2".blue, "Column3".cyan]);
var testTable2 = beautyLog.table.new("custom", ["Column1".red, "Column2".blue, "Column3".cyan]);
testTable2.push(["Hey", "this", "works"]);
testTable2.print();
})();

File diff suppressed because it is too large Load Diff

6
test/browser/index.html Normal file
View File

@ -0,0 +1,6 @@
<head>
<script async src="browserified/index.js"></script>
</head>
<body>
</body>

4
test/browser/index.js Normal file
View File

@ -0,0 +1,4 @@
var beautylog = require("./index.js");
console.log("*** start browser console test (Might look weird in OS console and travis log...) ***");
beautylog.log("hello");
console.log("*** end browser console test ***");

17
testbrowser.js Normal file
View File

@ -0,0 +1,17 @@
/// <reference path="typings/tsd.d.ts" />
var plugins = {
gulp: require("gulp"),
gulpBrowser: require("gulp-browser"),
easyserve: require("easyserve")
};
plugins.gulp.task('compileBrowserJS', function () {
var stream = plugins.gulp.src('test/browser/index.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("test/browser/browserified/"));
return stream;
});
plugins.gulp.task('default', ['compileBrowserJS'], function () {
console.log('browserJS has been browserified');
plugins.easyserve("test/browser/");
});
plugins.gulp.start.apply(plugins.gulp, ['default']);

View File

@ -1,10 +1,10 @@
/// <reference path="./index.ts" />
module BeautylogOS {
module BeautylogNode {
export function init() {
var colors = require("colors");
var clc = require("cli-color");
var beautylogOS:any = {}; //object to append to all public facing functions
var beautylogNode:any = {}; //object to append to all public facing functions
var localBl:any; // object to append to all private params and functions
localBl = {};
@ -22,7 +22,7 @@ module BeautylogOS {
* @param logType
* @returns {boolean}
*/
beautylogOS.log = (logText:string = 'empty log', logType:string = 'normal') => {
beautylogNode.log = (logText:string = 'empty log', logType:string = 'normal') => {
try {
switch (logType) {
case 'dir':
@ -68,8 +68,8 @@ module BeautylogOS {
* @param logText
* @returns {boolean}
*/
beautylogOS.dir = function(logText) {
return beautylogOS.log(logText, 'dir');
beautylogNode.dir = function(logText) {
return beautylogNode.log(logText, 'dir');
};
@ -78,8 +78,8 @@ module BeautylogOS {
* @param logText
* @returns {boolean}
*/
beautylogOS.error = function(logText) {
return beautylogOS.log(logText, 'error');
beautylogNode.error = function(logText) {
return beautylogNode.log(logText, 'error');
};
/**
@ -87,8 +87,8 @@ module BeautylogOS {
* @param logText
* @returns {boolean}
*/
beautylogOS.info = function(logText) {
return beautylogOS.log(logText, 'info');
beautylogNode.info = function(logText) {
return beautylogNode.log(logText, 'info');
};
/**
@ -96,8 +96,8 @@ module BeautylogOS {
* @param logText
* @returns {boolean}
*/
beautylogOS.ok = function(logText) {
return beautylogOS.log(logText, 'ok');
beautylogNode.ok = function(logText) {
return beautylogNode.log(logText, 'ok');
};
/**
@ -105,8 +105,8 @@ module BeautylogOS {
* @param logText string to log as error
* @returns {boolean}
*/
beautylogOS.success = function(logText) {
return beautylogOS.log(logText, 'success');
beautylogNode.success = function(logText) {
return beautylogNode.log(logText, 'success');
};
/**
@ -114,12 +114,12 @@ module BeautylogOS {
* @param logText string to log as error
* @returns {boolean}
*/
beautylogOS.warn = function(logText) {
return beautylogOS.log(logText, 'warn');
beautylogNode.warn = function(logText) {
return beautylogNode.log(logText, 'warn');
};
beautylogOS.table = BeautylogOsTable.init();
beautylogNode.table = BeautylogOsTable.init();
return beautylogOS;
return beautylogNode;
}
}

9
ts/beautylog.plugins.ts Normal file
View File

@ -0,0 +1,9 @@
/// <reference path="./index.ts" />
module BeautylogPlugins {
export var init = function(){
var plugins = {
smartenv: require("smartenv")
};
return plugins;
};
}

View File

@ -1,7 +1,6 @@
// import gulp
var gulp = require("gulp")
var gulpTypescript = require("gulp-typescript");
var pr = require("pushrocks");
gulp.task('compileTS', function() {
var stream = gulp.src('../index.ts')
@ -21,10 +20,19 @@ gulp.task('compileTestTS', function() {
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
pr.beautylog.success('Typescript compiled');
gulp.task('compileTestBrowserTS', function() {
var stream = gulp.src('../testbrowser.ts')
.pipe(gulpTypescript({
out: "testbrowser.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS','compileTestBrowserTS'], function() {
console.log('Typescript compiled');
});
//lets tell gulp to start with the default task.
pr.beautylog.log('Starting Gulp to compile TypeScript');
console.log('Starting Gulp to compile TypeScript');
gulp.start.apply(gulp, ['default']);

View File

@ -1,13 +1,15 @@
/// <reference path="./typings/tsd.d.ts" />
/// <reference path="./beautylog.plugins.ts" />
/// <reference path="./beautylog.classes.ts" />
/// <reference path="./beautylog.os.ts" />
/// <reference path="./beautylog.os.table.ts" />
/// <reference path="./beautylog.node.ts" />
/// <reference path="./beautylog.node.table.ts" />
/// <reference path="./beautylog.browser.ts" />
var beautylog = function(logPlatform:string = "os") {
switch (logPlatform) {
case "os":
var beautylogOs = BeautylogOS.init();
var plugins = BeautylogPlugins.init();
var beautylog = (function() {
switch (plugins.smartenv.getEnv().runtimeEnv) {
case "node":
var beautylogOs = BeautylogNode.init();
return beautylogOs;
break;
case "browser":
@ -15,8 +17,8 @@ var beautylog = function(logPlatform:string = "os") {
return beautylogBrowser;
break;
default:
console.log("something is strange about the way you required beautylog");
console.log("something is strange about the platform in which you try to use beautylog");
break;
}
};
})();
module.exports = beautylog;

View File

@ -1,46 +1,42 @@
/// <reference path="./typings/tsd.d.ts" />
var beautyLogOs = require('./index.js')("os");
var beautyLogBrowser = require("./index.js")("browser");
var smartenv = require("smartenv");
var beautyLog = require('./index.js');
console.log('*** start OS console test ***');
console.log ('');
console.log('declarative function calls:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.dir('beautylog.dir(), with normal logText, without logType');
beautyLogOs.error('beautylog.error(), with normal logText, without logType');
beautyLogOs.info('beautylog.dir(), with normal logText, without logType');
beautyLogOs.ok('beautylog.ok(), with normal logText, without logType');
beautyLogOs.success('beautylog.success(), with normal logText, without logType');
beautyLogOs.warn('beautylog.warn(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.dir('beautylog.dir(), with normal logText, without logType');
beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLog.info('beautylog.dir(), with normal logText, without logType');
beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log('');
console.log('logType String:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "dir"','dir');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "error"','error');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "info"','info');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "ok"','ok');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "success"','success');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "warn"','warn');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, with logType "dir"','dir');
beautyLog.log('beautylog.log(), with normal logText, with logType "error"','error');
beautyLog.log('beautylog.log(), with normal logText, with logType "info"','info');
beautyLog.log('beautylog.log(), with normal logText, with logType "ok"','ok');
beautyLog.log('beautylog.log(), with normal logText, with logType "success"','success');
beautyLog.log('beautylog.log(), with normal logText, with logType "warn"','warn');
console.log ('');
console.log('*** end OS console test ***');
console.log("*** start browser console test (Might look weird in OS console and travis log...) ***");
beautyLogBrowser.log("hello");
console.log("*** end browser console test ***");
console.log("*** start table test ***");
(function(){
var testTable1 = beautyLogOs.table.new("checks");
var testTable1 = beautyLog.table.new("checks");
testTable1.push(['check1','success']);
testTable1.push(['check2','error']);
testTable1.push(['check3','error']);
testTable1.print();
var testTable2 = beautyLogOs.table.new("custom",["Column1".red,"Column2".blue,"Column3".cyan]);
var testTable2 = beautyLog.table.new("custom",["Column1".red,"Column2".blue,"Column3".cyan]);
testTable2.push(["Hey","this","works"]);
testTable2.print();
})();

20
ts/testbrowser.ts Normal file
View File

@ -0,0 +1,20 @@
/// <reference path="typings/tsd.d.ts" />
var plugins = {
gulp: require("gulp"),
gulpBrowser: require("gulp-browser"),
easyserve: require("easyserve")
};
plugins.gulp.task('compileBrowserJS', function() {
var stream = plugins.gulp.src('test/browser/index.js')
.pipe(plugins.gulpBrowser.browserify())
.pipe(plugins.gulp.dest("test/browser/browserified/"));
return stream;
});
plugins.gulp.task('default',['compileBrowserJS'], function() {
console.log('browserJS has been browserified');
plugins.easyserve("test/browser/");
});
plugins.gulp.start.apply(plugins.gulp, ['default']);