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 ```javascript
### Simple Logging ### Simple Logging
var bl = require('beautylog')("os"); //for use in OS console environment var bl = require('beautylog'); //for use in OS console environment AND browser console
var bl = require('beautylog')("browser"); //for use in browser console environment like Google Chrome
bl.log('some log message'); //normal console log message bl.log('some log message'); //normal console log message

View File

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

View File

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

39
test.js
View File

@ -1,38 +1,35 @@
/// <reference path="./typings/tsd.d.ts" /> /// <reference path="./typings/tsd.d.ts" />
var beautyLogOs = require('./index.js')("os"); var smartenv = require("smartenv");
var beautyLogBrowser = require("./index.js")("browser"); var beautyLog = require('./index.js');
console.log('*** start OS console test ***'); console.log('*** start OS console test ***');
console.log(''); console.log('');
console.log('declarative function calls:'); console.log('declarative function calls:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.dir('beautylog.dir(), with normal logText, without logType'); beautyLog.dir('beautylog.dir(), with normal logText, without logType');
beautyLogOs.error('beautylog.error(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLogOs.info('beautylog.dir(), with normal logText, without logType'); beautyLog.info('beautylog.dir(), with normal logText, without logType');
beautyLogOs.ok('beautylog.ok(), with normal logText, without logType'); beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLogOs.success('beautylog.success(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLogOs.warn('beautylog.warn(), with normal logText, without logType'); beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log(''); console.log('');
console.log('logType String:'); console.log('logType String:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "dir"', 'dir'); beautyLog.log('beautylog.log(), with normal logText, with logType "dir"', 'dir');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "error"', 'error'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "info"', 'info'); beautyLog.log('beautylog.log(), with normal logText, with logType "info"', 'info');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "ok"', 'ok'); beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "success"', 'success'); beautyLog.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, with logType "warn"', 'warn');
console.log(''); console.log('');
console.log('*** end OS console test ***'); 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 ***"); console.log("*** start table test ***");
(function () { (function () {
var testTable1 = beautyLogOs.table.new("checks"); var testTable1 = beautyLog.table.new("checks");
testTable1.push(['check1', 'success']); testTable1.push(['check1', 'success']);
testTable1.push(['check2', 'error']); testTable1.push(['check2', 'error']);
testTable1.push(['check3', 'error']); testTable1.push(['check3', 'error']);
testTable1.print(); 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.push(["Hey", "this", "works"]);
testTable2.print(); 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" /> /// <reference path="./index.ts" />
module BeautylogOS { module BeautylogNode {
export function init() { export function init() {
var colors = require("colors"); var colors = require("colors");
var clc = require("cli-color"); 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 var localBl:any; // object to append to all private params and functions
localBl = {}; localBl = {};
@ -22,7 +22,7 @@ module BeautylogOS {
* @param logType * @param logType
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.log = (logText:string = 'empty log', logType:string = 'normal') => { beautylogNode.log = (logText:string = 'empty log', logType:string = 'normal') => {
try { try {
switch (logType) { switch (logType) {
case 'dir': case 'dir':
@ -68,8 +68,8 @@ module BeautylogOS {
* @param logText * @param logText
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.dir = function(logText) { beautylogNode.dir = function(logText) {
return beautylogOS.log(logText, 'dir'); return beautylogNode.log(logText, 'dir');
}; };
@ -78,8 +78,8 @@ module BeautylogOS {
* @param logText * @param logText
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.error = function(logText) { beautylogNode.error = function(logText) {
return beautylogOS.log(logText, 'error'); return beautylogNode.log(logText, 'error');
}; };
/** /**
@ -87,8 +87,8 @@ module BeautylogOS {
* @param logText * @param logText
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.info = function(logText) { beautylogNode.info = function(logText) {
return beautylogOS.log(logText, 'info'); return beautylogNode.log(logText, 'info');
}; };
/** /**
@ -96,8 +96,8 @@ module BeautylogOS {
* @param logText * @param logText
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.ok = function(logText) { beautylogNode.ok = function(logText) {
return beautylogOS.log(logText, 'ok'); return beautylogNode.log(logText, 'ok');
}; };
/** /**
@ -105,8 +105,8 @@ module BeautylogOS {
* @param logText string to log as error * @param logText string to log as error
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.success = function(logText) { beautylogNode.success = function(logText) {
return beautylogOS.log(logText, 'success'); return beautylogNode.log(logText, 'success');
}; };
/** /**
@ -114,12 +114,12 @@ module BeautylogOS {
* @param logText string to log as error * @param logText string to log as error
* @returns {boolean} * @returns {boolean}
*/ */
beautylogOS.warn = function(logText) { beautylogNode.warn = function(logText) {
return beautylogOS.log(logText, 'warn'); 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 // import gulp
var gulp = require("gulp") var gulp = require("gulp")
var gulpTypescript = require("gulp-typescript"); var gulpTypescript = require("gulp-typescript");
var pr = require("pushrocks");
gulp.task('compileTS', function() { gulp.task('compileTS', function() {
var stream = gulp.src('../index.ts') var stream = gulp.src('../index.ts')
@ -21,10 +20,19 @@ gulp.task('compileTestTS', function() {
return stream; return stream;
}); });
gulp.task('default',['compileTS','compileTestTS'], function() { gulp.task('compileTestBrowserTS', function() {
pr.beautylog.success('Typescript compiled'); 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. //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']); gulp.start.apply(gulp, ['default']);

View File

@ -1,13 +1,15 @@
/// <reference path="./typings/tsd.d.ts" /> /// <reference path="./typings/tsd.d.ts" />
/// <reference path="./beautylog.plugins.ts" />
/// <reference path="./beautylog.classes.ts" /> /// <reference path="./beautylog.classes.ts" />
/// <reference path="./beautylog.os.ts" /> /// <reference path="./beautylog.node.ts" />
/// <reference path="./beautylog.os.table.ts" /> /// <reference path="./beautylog.node.table.ts" />
/// <reference path="./beautylog.browser.ts" /> /// <reference path="./beautylog.browser.ts" />
var beautylog = function(logPlatform:string = "os") { var plugins = BeautylogPlugins.init();
switch (logPlatform) { var beautylog = (function() {
case "os": switch (plugins.smartenv.getEnv().runtimeEnv) {
var beautylogOs = BeautylogOS.init(); case "node":
var beautylogOs = BeautylogNode.init();
return beautylogOs; return beautylogOs;
break; break;
case "browser": case "browser":
@ -15,8 +17,8 @@ var beautylog = function(logPlatform:string = "os") {
return beautylogBrowser; return beautylogBrowser;
break; break;
default: 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; break;
} }
}; })();
module.exports = beautylog; module.exports = beautylog;

View File

@ -1,46 +1,42 @@
/// <reference path="./typings/tsd.d.ts" /> /// <reference path="./typings/tsd.d.ts" />
var beautyLogOs = require('./index.js')("os"); var smartenv = require("smartenv");
var beautyLogBrowser = require("./index.js")("browser"); var beautyLog = require('./index.js');
console.log('*** start OS console test ***'); console.log('*** start OS console test ***');
console.log (''); console.log ('');
console.log('declarative function calls:'); console.log('declarative function calls:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.dir('beautylog.dir(), with normal logText, without logType'); beautyLog.dir('beautylog.dir(), with normal logText, without logType');
beautyLogOs.error('beautylog.error(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLogOs.info('beautylog.dir(), with normal logText, without logType'); beautyLog.info('beautylog.dir(), with normal logText, without logType');
beautyLogOs.ok('beautylog.ok(), with normal logText, without logType'); beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLogOs.success('beautylog.success(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLogOs.warn('beautylog.warn(), with normal logText, without logType'); beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log(''); console.log('');
console.log('logType String:'); console.log('logType String:');
beautyLogOs.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "dir"','dir'); beautyLog.log('beautylog.log(), with normal logText, with logType "dir"','dir');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "error"','error'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"','error');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "info"','info'); beautyLog.log('beautylog.log(), with normal logText, with logType "info"','info');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "ok"','ok'); beautyLog.log('beautylog.log(), with normal logText, with logType "ok"','ok');
beautyLogOs.log('beautylog.log(), with normal logText, with logType "success"','success'); beautyLog.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, with logType "warn"','warn');
console.log (''); console.log ('');
console.log('*** end OS console test ***'); 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 ***"); console.log("*** start table test ***");
(function(){ (function(){
var testTable1 = beautyLogOs.table.new("checks"); var testTable1 = beautyLog.table.new("checks");
testTable1.push(['check1','success']); testTable1.push(['check1','success']);
testTable1.push(['check2','error']); testTable1.push(['check2','error']);
testTable1.push(['check3','error']); testTable1.push(['check3','error']);
testTable1.print(); 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.push(["Hey","this","works"]);
testTable2.print(); 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']);