system change
This commit is contained in:
parent
7c1eb711da
commit
127476c86e
@ -7,7 +7,6 @@ cache:
|
||||
key: "$CI_BUILD_STAGE"
|
||||
|
||||
stages:
|
||||
- mirror
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
@ -15,13 +14,13 @@ stages:
|
||||
- pages
|
||||
|
||||
mirror:
|
||||
stage: mirror
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
|
||||
security:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci command yarn global add snyk
|
||||
|
10
package.json
10
package.json
@ -37,13 +37,13 @@
|
||||
"lodash": "^4.17.5",
|
||||
"ora": "^2.0.0",
|
||||
"smartenv": "^4.0.3",
|
||||
"smartlog-interfaces": "^1.0.5",
|
||||
"smartlog-interfaces": "^1.0.8",
|
||||
"smartq": "^1.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"qenv": "^1.1.3",
|
||||
"smartchai": "^1.0.3",
|
||||
"smartdelay": "^1.0.1",
|
||||
"tapbundle": "^1.0.5"
|
||||
"qenv": "^1.1.7",
|
||||
"smartchai": "^2.0.1",
|
||||
"smartdelay": "^1.0.4",
|
||||
"tapbundle": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
29
test/test.ts
29
test/test.ts
@ -10,14 +10,6 @@ tap.test('.log(message) should print a blue Dir message', async () => {
|
||||
beautylog.log('beautylog.log(), with normal logText, without logType');
|
||||
});
|
||||
|
||||
tap.test('.dir(message) should print a blue Dir message', async () => {
|
||||
beautylog.dir('beautylog.dir(), with normal logText, without logType');
|
||||
});
|
||||
|
||||
tap.test('.error(message) should print a red error message', async () => {
|
||||
beautylog.error('beautylog.error(), with normal logText, without logType');
|
||||
});
|
||||
|
||||
tap.test('.figlet should print nice fonts to console in yellow', async () => {
|
||||
return beautylog.figlet('Async!', { font: 'Star Wars', color: 'orange' });
|
||||
});
|
||||
@ -26,10 +18,6 @@ tap.test('.figletSync should print nice fonts to console in yellow', async () =>
|
||||
beautylog.figletSync('Sync!', { font: 'Star Wars', color: 'blue' });
|
||||
});
|
||||
|
||||
tap.test('.info(message) should display a purple info message', async () => {
|
||||
beautylog.info('beautylog.dir(), with normal logText, without logType');
|
||||
});
|
||||
|
||||
tap.test('.logReduced(message) should only log two messages', async () => {
|
||||
beautylog.logReduced('Message 1');
|
||||
beautylog.logReduced('Message 1');
|
||||
@ -39,10 +27,6 @@ tap.test('.logReduced(message) should only log two messages', async () => {
|
||||
beautylog.logReduced('Message 2');
|
||||
});
|
||||
|
||||
tap.test('.ok(message) should display a green ok message', async () => {
|
||||
beautylog.ok('beautylog.ok() works!');
|
||||
});
|
||||
|
||||
tap.test('.newLine(number) create specified amount of new lines', async () => {
|
||||
beautylog.newLine(1);
|
||||
});
|
||||
@ -52,7 +36,6 @@ tap.test('.ora(text,color) should display, update, and end a message', async ()
|
||||
await smartdelay.delayFor(2000);
|
||||
beautylog.ora.text('updated text!');
|
||||
await smartdelay.delayFor(2000);
|
||||
beautylog.info('another log message that uses the normal log function');
|
||||
await smartdelay.delayFor(2000);
|
||||
beautylog.ora.endOk('Allright, ora works!');
|
||||
});
|
||||
@ -63,14 +46,4 @@ tap.test('.ora(text,color) should display an error message when ended with error
|
||||
beautylog.ora.endError('Allright, ora displays an error!');
|
||||
});
|
||||
|
||||
tap.test('.success(message) should display an orange warn message', async () => {
|
||||
beautylog.success('beautylog.success() works!');
|
||||
});
|
||||
|
||||
tap.test('.warn should display a orange warn message', async () => {
|
||||
beautylog.warn('beautylog.warn() works!');
|
||||
});
|
||||
|
||||
tap.test('.note should display a pink note', async () => {
|
||||
beautylog.note('beautylog.note() works!');
|
||||
});
|
||||
tap.start();
|
||||
|
159
ts/beautylog.classes.beautylog.ts
Normal file
159
ts/beautylog.classes.beautylog.ts
Normal file
@ -0,0 +1,159 @@
|
||||
import * as plugins from './beautylog.plugins';
|
||||
import { ILogDestination, ILogPackage } from 'smartlog-interfaces';
|
||||
|
||||
// other beautylog classes
|
||||
import { Ora } from './beautylog.classes.ora';
|
||||
|
||||
export interface IBeautyLogObject {
|
||||
logType: string;
|
||||
logString: string;
|
||||
}
|
||||
|
||||
export class Beautylog implements ILogDestination {
|
||||
private oraInstance: Ora;
|
||||
handleLog(logPackage: ILogPackage) {
|
||||
this.logToConsole(this.parseLog(logPackage.message));
|
||||
}
|
||||
|
||||
get ora(): Ora {
|
||||
if (!this.oraInstance) {
|
||||
this.oraInstance = new Ora(this);
|
||||
}
|
||||
return this.oraInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse logs for display
|
||||
*/
|
||||
private parseLog = (stringToParseArg: string): IBeautyLogObject => {
|
||||
const parseLogRegex = /^(success|ok|info|warn|error):\s(.*)/;
|
||||
const regexResult = parseLogRegex.exec(stringToParseArg);
|
||||
if (regexResult && regexResult.length === 3) {
|
||||
return {
|
||||
logType: regexResult[1],
|
||||
logString: regexResult[2]
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
logType: 'log',
|
||||
logString: stringToParseArg
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a new empty line
|
||||
* @param linesArg
|
||||
* @returns void
|
||||
*/
|
||||
newLine(linesArg: number = 1) {
|
||||
for (let i = 0; i < linesArg; i++) {
|
||||
console.log('\n');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* logs a reduced log that only logs changes of consequential log messages
|
||||
*/
|
||||
logReduced(logTextArg: string, repeatEveryTimesArg: number = 0) {
|
||||
if (
|
||||
logTextArg === this.previousMessage &&
|
||||
(repeatEveryTimesArg === 0 || this.sameMessageCounter !== repeatEveryTimesArg)
|
||||
) {
|
||||
this.sameMessageCounter++;
|
||||
} else {
|
||||
this.sameMessageCounter = 0;
|
||||
this.previousMessage = logTextArg;
|
||||
this.logToConsole({
|
||||
logType: 'log',
|
||||
logString: logTextArg
|
||||
});
|
||||
}
|
||||
}
|
||||
private previousMessage: string = '';
|
||||
private sameMessageCounter: number = 0;
|
||||
|
||||
// default logging
|
||||
logToConsole(beautlogObject: IBeautyLogObject) {
|
||||
let { logType, logString } = beautlogObject;
|
||||
try {
|
||||
switch (logType) {
|
||||
case 'dir':
|
||||
logString = this.localBl.dirPrefix + plugins.beautycolor.coloredString(logString, 'blue');
|
||||
break;
|
||||
case 'error':
|
||||
logString =
|
||||
this.localBl.errorPrefix + plugins.beautycolor.coloredString(logString, 'red');
|
||||
break;
|
||||
case 'info':
|
||||
logString =
|
||||
this.localBl.infoPrefix + plugins.beautycolor.coloredString(logString, 'blue');
|
||||
break;
|
||||
case 'normal':
|
||||
logString = this.localBl.logPrefix + plugins.beautycolor.coloredString(logString, 'cyan');
|
||||
break;
|
||||
case 'note':
|
||||
logString =
|
||||
this.localBl.notePrefix + plugins.beautycolor.coloredString(logString, 'pink');
|
||||
break;
|
||||
case 'ok':
|
||||
logString = this.localBl.okPrefix + plugins.beautycolor.coloredString(logString, 'green');
|
||||
break;
|
||||
case 'success':
|
||||
logString =
|
||||
this.localBl.successPrefix + plugins.beautycolor.coloredString(logString, 'green');
|
||||
break;
|
||||
case 'warn':
|
||||
logString =
|
||||
this.localBl.warnPrefix + plugins.beautycolor.coloredString(logString, 'orange');
|
||||
break;
|
||||
case 'log':
|
||||
logString = this.localBl.logPrefix + plugins.beautycolor.coloredString(logString, 'cyan');
|
||||
break;
|
||||
default:
|
||||
plugins.beautycolor.coloredString(logString, 'blue');
|
||||
console.log('unknown logType for "' + logString + '"');
|
||||
break;
|
||||
}
|
||||
console.log(logString);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log(
|
||||
this.localBl.errorPrefix + 'You seem to have tried logging something strange' + error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private localBl = {
|
||||
dirPrefix: plugins.beautycolor.coloredString(' DIR ', 'white', 'blue') + ' ',
|
||||
errorPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'red', 'red') +
|
||||
plugins.beautycolor.coloredString(' ERROR! ', 'red', 'black') +
|
||||
' ',
|
||||
infoPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'blue', 'blue') +
|
||||
plugins.beautycolor.coloredString(' INFO: ', 'blue', 'black') +
|
||||
' ',
|
||||
logPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'white', 'cyan') +
|
||||
plugins.beautycolor.coloredString(' LOG: ', 'cyan', 'black') +
|
||||
' ',
|
||||
notePrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'pink', 'pink') +
|
||||
plugins.beautycolor.coloredString(' NOTE -> ', 'pink', 'black') +
|
||||
' ',
|
||||
okPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'green', 'green') +
|
||||
plugins.beautycolor.coloredString(' OK! ', 'green', 'black') +
|
||||
' ',
|
||||
successPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'green', 'green') +
|
||||
plugins.beautycolor.coloredString(' SUCCESS! ', 'green', 'black') +
|
||||
' ',
|
||||
warnPrefix:
|
||||
plugins.beautycolor.coloredString(' ', 'orange', 'orange') +
|
||||
plugins.beautycolor.coloredString(' WARN: -> ', 'orange', 'black') +
|
||||
' '
|
||||
};
|
||||
}
|
@ -1,22 +1,16 @@
|
||||
import 'typings-global';
|
||||
import * as plugins from './beautylog.plugins';
|
||||
import { logNode } from './beautylog.log.helpers';
|
||||
|
||||
export let oraActive: boolean = false; // when an Ora is active (e.g. start()) this is true
|
||||
export let activeOra: Ora; // points to the currently active Ora object
|
||||
import { Beautylog } from './beautylog.classes.beautylog';
|
||||
|
||||
export class Ora {
|
||||
beautylog: Beautylog;
|
||||
state: string;
|
||||
private _oraObject;
|
||||
constructor(textArg: string, colorArg: string, startArg: boolean = false) {
|
||||
constructor(beautylogInstanceArg: Beautylog = new Beautylog()) {
|
||||
this._oraObject = plugins.ora({
|
||||
spinner: 'dots',
|
||||
text: textArg,
|
||||
color: colorArg
|
||||
text: '',
|
||||
color: 'blue'
|
||||
});
|
||||
if (startArg) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
text(textArg) {
|
||||
this._oraObject.text = textArg;
|
||||
@ -29,15 +23,11 @@ export class Ora {
|
||||
if (colorArg) {
|
||||
this._oraObject.color = colorArg;
|
||||
}
|
||||
activeOra = this;
|
||||
oraActive = true;
|
||||
this._oraObject.start();
|
||||
}
|
||||
end() {
|
||||
this._oraObject.stop();
|
||||
this._oraObject.clear();
|
||||
activeOra = undefined;
|
||||
oraActive = false;
|
||||
}
|
||||
endOk(textArg) {
|
||||
this.end();
|
||||
@ -55,5 +45,3 @@ export class Ora {
|
||||
this.end();
|
||||
}
|
||||
}
|
||||
|
||||
export let ora = new Ora('init...', 'blue', false);
|
||||
|
@ -1,4 +1,6 @@
|
||||
import 'typings-global';
|
||||
// ======
|
||||
// monkeypatch logging, so console logs are controled by beautylog
|
||||
// ======
|
||||
import plugins = require('./beautylog.plugins');
|
||||
import { activeOra, oraActive } from './beautylog.classes.ora';
|
||||
let nativeLog = console.log;
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'typings-global';
|
||||
import plugins = require('./beautylog.plugins');
|
||||
|
||||
export interface IFigletOptions {
|
||||
|
@ -1,116 +0,0 @@
|
||||
import * as plugins from './beautylog.plugins';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param logText
|
||||
* @param logType
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let internalLog = function(logType: string = 'normal', logText: string = 'empty log') {
|
||||
switch ((new plugins.smartenv.Smartenv()).runtimeEnv) {
|
||||
case 'node':
|
||||
logNode(logType, logText);
|
||||
break;
|
||||
case 'browser':
|
||||
logBrowser(logText, logType);
|
||||
break;
|
||||
default:
|
||||
console.log('something is strange about the platform in which you try to use beautylog');
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let coloredString = plugins.beautycolor.coloredString;
|
||||
|
||||
let localBl = {
|
||||
dirPrefix: coloredString(' DIR ', 'white', 'blue') + ' ',
|
||||
errorPrefix: coloredString(' ', 'red', 'red') + coloredString(' ERROR! ', 'red', 'black') + ' ',
|
||||
infoPrefix: coloredString(' ', 'blue', 'blue') + coloredString(' INFO: ', 'blue', 'black') + ' ',
|
||||
logPrefix: coloredString(' ', 'white', 'cyan') + coloredString(' LOG: ', 'cyan', 'black') + ' ',
|
||||
notePrefix:
|
||||
coloredString(' ', 'pink', 'pink') + coloredString(' NOTE -> ', 'pink', 'black') + ' ',
|
||||
okPrefix: coloredString(' ', 'green', 'green') + coloredString(' OK! ', 'green', 'black') + ' ',
|
||||
successPrefix:
|
||||
coloredString(' ', 'green', 'green') + coloredString(' SUCCESS! ', 'green', 'black') + ' ',
|
||||
warnPrefix:
|
||||
coloredString(' ', 'orange', 'orange') + coloredString(' WARN: -> ', 'orange', 'black') + ' '
|
||||
};
|
||||
|
||||
export let logNode = function(logType: string, logText: string) {
|
||||
try {
|
||||
switch (logType) {
|
||||
case 'dir':
|
||||
logText = localBl.dirPrefix + coloredString(logText, 'blue');
|
||||
break;
|
||||
case 'error':
|
||||
logText = localBl.errorPrefix + coloredString(logText, 'red');
|
||||
break;
|
||||
case 'info':
|
||||
logText = localBl.infoPrefix + coloredString(logText, 'blue');
|
||||
break;
|
||||
case 'normal':
|
||||
logText = localBl.logPrefix + coloredString(logText, 'cyan');
|
||||
break;
|
||||
case 'note':
|
||||
logText = localBl.notePrefix + coloredString(logText, 'pink');
|
||||
break;
|
||||
case 'ok':
|
||||
logText = localBl.okPrefix + coloredString(logText, 'green');
|
||||
break;
|
||||
case 'success':
|
||||
logText = localBl.successPrefix + coloredString(logText, 'green');
|
||||
break;
|
||||
case 'warn':
|
||||
logText = localBl.warnPrefix + coloredString(logText, 'orange');
|
||||
break;
|
||||
case 'log':
|
||||
logText = localBl.logPrefix + coloredString(logText, 'cyan');
|
||||
break;
|
||||
default:
|
||||
coloredString(logText, 'blue');
|
||||
console.log('unknown logType for "' + logText + '"');
|
||||
break;
|
||||
}
|
||||
console.log(logText);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log(localBl.errorPrefix + 'You seem to have tried logging something strange' + error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
let logBrowser = function(logText, logType) {
|
||||
switch (logType) {
|
||||
case 'dir':
|
||||
logText = localBl.dirPrefix + coloredString(logText, 'blue');
|
||||
break;
|
||||
case 'error':
|
||||
logText = localBl.errorPrefix + logText.red.bold;
|
||||
break;
|
||||
case 'info':
|
||||
console.log('%c Info: %c ' + logText, 'background:#EC407A;color:#ffffff;', 'color:#EC407A;');
|
||||
break;
|
||||
case 'normal':
|
||||
logText = localBl.logPrefix + logText.cyan.bold;
|
||||
break;
|
||||
case 'ok':
|
||||
console.log('%c OK: %c ' + logText, 'background:#000000;color:#8BC34A;', 'color:#000000;');
|
||||
break;
|
||||
case 'success':
|
||||
console.log(
|
||||
'%c Success: %c ' + logText,
|
||||
'background:#8BC34A;color:#ffffff;',
|
||||
'color:#8BC34A;'
|
||||
);
|
||||
break;
|
||||
case 'warn':
|
||||
console.log('%c Warn: %c ' + logText, 'background:#000000;color:#FB8C00;', 'color:#000000;');
|
||||
break;
|
||||
case 'log':
|
||||
console.log('%c Log: %c ' + logText, 'background:#42A5F5;color:#ffffff', 'color:#42A5F5;');
|
||||
break;
|
||||
default:
|
||||
console.log('unknown logType for "' + logText + '"');
|
||||
break;
|
||||
}
|
||||
};
|
@ -1,98 +0,0 @@
|
||||
import 'typings-global';
|
||||
|
||||
import { internalLog } from './beautylog.log.helpers';
|
||||
|
||||
/**
|
||||
* logs an info to console
|
||||
* @param logText
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
export let log = logText => {
|
||||
return internalLog('log', logText);
|
||||
};
|
||||
|
||||
export let info = logText => {
|
||||
return internalLog('info', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* logs an 'OK!' message to console
|
||||
* @param logText
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let ok = logText => {
|
||||
return internalLog('ok', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* logs a success to console
|
||||
* @param logText string to log as error
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let success = logText => {
|
||||
return internalLog('success', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* logs a 'warn:' message to console
|
||||
* @param logText string to log as error
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let warn = logText => {
|
||||
return internalLog('warn', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* logs an error to console
|
||||
* @param logText
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let error = logText => {
|
||||
return internalLog('error', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* logs an directory to console
|
||||
* @param logText
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export let dir = logText => {
|
||||
return internalLog('dir', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* note
|
||||
*/
|
||||
export let note = logText => {
|
||||
return internalLog('note', logText);
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a new empty line
|
||||
* @param linesArg
|
||||
* @returns void
|
||||
*/
|
||||
export let newLine = (linesArg: number = 1) => {
|
||||
for (let i = 0; i < linesArg; i++) {
|
||||
console.log('\n');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* logs a reduced log that only logs changes of consequential log messages
|
||||
*/
|
||||
export let logReduced = (logTextArg: string, repeatEveryTimesArg: number = 0) => {
|
||||
if (
|
||||
logTextArg === previousMessage &&
|
||||
(repeatEveryTimesArg === 0 || sameMessageCounter !== repeatEveryTimesArg)
|
||||
) {
|
||||
sameMessageCounter++;
|
||||
} else {
|
||||
sameMessageCounter = 0;
|
||||
previousMessage = logTextArg;
|
||||
log(logTextArg);
|
||||
}
|
||||
};
|
||||
let previousMessage: string = '';
|
||||
let sameMessageCounter: number = 0;
|
13
ts/index.ts
13
ts/index.ts
@ -6,16 +6,5 @@ import * as plugins from './beautylog.plugins';
|
||||
export { ora } from './beautylog.classes.ora';
|
||||
|
||||
// export methods
|
||||
export {
|
||||
dir,
|
||||
error,
|
||||
info,
|
||||
log,
|
||||
logReduced,
|
||||
note,
|
||||
ok,
|
||||
success,
|
||||
warn,
|
||||
newLine
|
||||
} from './beautylog.log';
|
||||
export { log, logReduced, newLine } from './beautylog.log';
|
||||
export { figlet, figletSync } from './beautylog.figlet';
|
||||
|
Loading…
Reference in New Issue
Block a user