UNPKG

liferay-npm-bundler-preset-reactjs

Version:

liferay npm bundler preset react

118 lines (117 loc) 3.43 kB
"use strict"; /** * SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> * SPDX-License-Identifier: LGPL-3.0-or-later */ Object.defineProperty(exports, "__esModule", { value: true }); class MessageTweaker { constructor(msg) { this._msg = msg; } linkTo(link) { this._msg.link = link; return this; } linkToCode(code) { let strCode = code.toString(); while (strCode.length < 4) { strCode = `0${strCode}`; } this._msg.link = `https://github.com/liferay/liferay-frontend-projects/tree/master/maintenance/projects/js-toolkit/docs/Report-messages.md#${strCode}`; return this; } linkToIssue(issueNumber) { this._msg.link = `https://github.com/liferay/liferay-js-toolkit/issues/${issueNumber}`; return this; } } /** * An object to hold plugin messages. */ class PluginLogger { constructor() { this._msgs = []; } /** * Log an informational message * @param source the identifier for the source of the message * @param things the objects or strings to print */ info(source, ...things) { const msg = { source, level: 'info', things, }; this._msgs.push(msg); return new MessageTweaker(msg); } /** * Log a warn message * @param source the identifier for the source of the message * @param things the objects or strings to print */ warn(source, ...things) { const msg = { source, level: 'warn', things, }; this._msgs.push(msg); return new MessageTweaker(msg); } /** * Log an error message * @param source the identifier for the source of the message * @param things the objects or strings to print */ error(source, ...things) { const msg = { source, level: 'error', things, }; this._msgs.push(msg); return new MessageTweaker(msg); } /** * Get the list of messages */ get messages() { return this._msgs; } /** * Test if there are warn messages. * @return true if at least one warn message is registered in the logger */ get warnsPresent() { return !!this._msgs.filter((msg) => msg.level === 'warn').length; } /** * Test if there are error messages. * @return true if at least one error message is registered in the logger */ get errorsPresent() { return !!this._msgs.filter((msg) => msg.level === 'error').length; } /** * Return a printable string representation of the messages logged till now */ toString() { return this._msgs.reduce((str, { level, source, things }) => `${str}${source}:${level}: ${things.join(' ')}\n`, ''); } /** * Return an HTML string representation of the messages logged till now * containing one line (<br> separated) per message */ toHtml() { return this._msgs.reduce((str, { level, link, source, things }) => { let html = `${str}${source}:${level}: ${things.join(' ')}<br>`; if (link) { html += ` <a href='${link}' title='Detailed information'>🛈🔗</a>`; } return html; }, ''); } } exports.default = PluginLogger;