@betterer/logger
Advanced tools
Comparing version 0.2.0 to 0.3.0
export declare function mute(): void; | ||
export declare function header(head: string): void; | ||
export declare function br(): void; | ||
export declare const success: (...args: string[]) => void; | ||
@@ -8,2 +10,3 @@ export declare const info: (...args: string[]) => void; | ||
export declare type LoggerCodeInfo = { | ||
message: string; | ||
filePath: string; | ||
@@ -10,0 +13,0 @@ fileText: string; |
@@ -5,61 +5,40 @@ "use strict"; | ||
var code_frame_1 = require("@babel/code-frame"); | ||
var chalk_1 = require("chalk"); | ||
var lines_and_columns_1 = require("lines-and-columns"); | ||
var npmlog_1 = require("npmlog"); | ||
var path = require("path"); | ||
var IS_JS_REGEXP = /.t|jsx?$/; | ||
// HACK: | ||
// Need to import npmlog as a module to override global settings. | ||
var npmlog = require("npmlog"); | ||
assign(npmlog, 'heading', '☀️ betterer'); | ||
assign(npmlog, 'headingStyle', { | ||
fg: 'yellow' | ||
}); | ||
npmlog_1.enableColor(); | ||
npmlog_1.enableUnicode(); | ||
function mute() { | ||
assign(npmlog, 'level', 'silent'); | ||
// HACK: | ||
// There seems to be an issue with this lint rule for *assigning*. | ||
// Should file an issue... | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
console.log = function () { }; | ||
console['log'] = function () { }; | ||
} | ||
exports.mute = mute; | ||
var SUCCESS_LEVEL = 2500; | ||
var SUCCESS_STYLE = { | ||
bg: 'green', | ||
fg: 'black' | ||
}; | ||
exports.success = createLogger('good ❤️ ', SUCCESS_LEVEL, SUCCESS_STYLE); | ||
var INFO_LEVEL = 2000; | ||
var INFO_STYLE = { | ||
bg: 'black', | ||
fg: 'white' | ||
}; | ||
exports.info = createLogger('info 💬 ', INFO_LEVEL, INFO_STYLE); | ||
var WARN_LEVEL = 3000; | ||
var WARN_STYLE = { | ||
bg: 'yellow', | ||
fg: 'black' | ||
}; | ||
exports.warn = createLogger('warn ⚠️ ', WARN_LEVEL, WARN_STYLE); | ||
var ERROR_LEVEL = 4000; | ||
var ERROR_STYLE = { | ||
bg: 'red', | ||
fg: 'white' | ||
}; | ||
exports.error = createLogger('baad 💀 ', ERROR_LEVEL, ERROR_STYLE); | ||
function createLogger(name, level, style) { | ||
var loggerName = "betterer-" + name; | ||
npmlog_1.addLevel(loggerName, level, style, " " + name + " "); | ||
return function (message) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
function header(head) { | ||
console.log(chalk_1.default.yellowBright(head)); | ||
} | ||
exports.header = header; | ||
function br() { | ||
console.log(''); | ||
} | ||
exports.br = br; | ||
var HEADING = chalk_1.default.bgBlack.yellowBright.bold(" \u2600\uFE0F betterer "); | ||
var previousLogger = 'LOG'; | ||
exports.success = createLogger(chalk_1.default.bgGreenBright.black(' succ '), chalk_1.default.bgBlack(' ✅ ')); | ||
exports.info = createLogger(chalk_1.default.bgWhiteBright.black(' info '), chalk_1.default.bgBlack(' 💬 ')); | ||
exports.warn = createLogger(chalk_1.default.bgYellowBright.black(' warn '), chalk_1.default.bgBlack(' ⚠️ ')); | ||
exports.error = createLogger(chalk_1.default.bgRedBright.white(' erro '), chalk_1.default.bgBlack(' 🔥 ')); | ||
var SPACER = chalk_1.default.bgBlack.yellowBright(' - '); | ||
function createLogger(name, icon) { | ||
return function () { | ||
var messages = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
messages[_i] = arguments[_i]; | ||
} | ||
npmlog_1.log.apply(void 0, tslib_1.__spreadArrays([loggerName, '-', message], args)); | ||
if (previousLogger === 'CODE') { | ||
br(); | ||
} | ||
console.log.apply(console, tslib_1.__spreadArrays(["" + HEADING + name + icon + SPACER], messages.map(function (m) { return chalk_1.default.whiteBright(m); }))); | ||
previousLogger = 'LOG'; | ||
}; | ||
} | ||
exports.code = function (codeInfo) { | ||
var filePath = codeInfo.filePath, fileText = codeInfo.fileText; | ||
var filePath = codeInfo.filePath, fileText = codeInfo.fileText, message = codeInfo.message; | ||
var isJS = IS_JS_REGEXP.exec(path.extname(filePath)); | ||
@@ -80,7 +59,6 @@ var options = { | ||
}; | ||
console.log(code_frame_1.codeFrameColumns(fileText, { start: start, end: end }, options) + "\n"); | ||
var codeFrame = code_frame_1.codeFrameColumns(fileText, { start: start, end: end }, options); | ||
console.log("\n" + chalk_1.default.bgRed(' ') + chalk_1.default.bgBlack.white(" " + message + " \n") + codeFrame); | ||
previousLogger = 'CODE'; | ||
}; | ||
function assign(object, property, value) { | ||
object[property] = value; | ||
} | ||
//# sourceMappingURL=logger.js.map |
{ | ||
"name": "@betterer/logger", | ||
"description": "logger for @betterer/betterer", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -28,2 +28,3 @@ "publishConfig": { | ||
"@babel/code-frame": "^7.5.5", | ||
"chalk": "^2.4.2", | ||
"lines-and-columns": "^1.1.6", | ||
@@ -37,3 +38,3 @@ "npmlog": "^4.1.2", | ||
}, | ||
"gitHead": "a04aad0c3e1d977edbb3a56431db740d6743a7ae" | ||
"gitHead": "3c68551aa5f124166607b43e2da9936a6fb0b6a0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9250
5
85
+ Addedchalk@^2.4.2
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)