UNPKG

@salesforce/templates

Version:

Salesforce JS library for templates

130 lines 3.57 kB
/* * Copyright (c) 2021, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getYeomanLogger = exports.Log = void 0; const util = require("util"); const padding = ' '; const statuses = [ 'skip', 'force', 'create', 'invoke', 'conflict', 'identical', 'info', ]; class Log { constructor() { this.output = ''; this.cleanOutput = []; for (const status of statuses) { this[status] = (arg) => { if (status !== 'identical' && status !== 'conflict') { this.cleanOutput.push(arg); } this.write(this.pad(status)).write(padding); this.write(`${arg}\n`); return this; }; } } getOutput() { return this.output; } getCleanOutput() { return this.cleanOutput; } write(...args) { /* eslint prefer-spread: off */ this.output = this.output + util.format.apply(util, args); return this; } pad(status) { const max = 'identical'.length; const delta = max - status.length; return delta ? new Array(delta + 1).join(' ') + status : status; } setOutput(text) { this.output = text; } setCleanOutput(cleanText) { this.cleanOutput = cleanText; } clear() { this.output = ''; this.cleanOutput = []; } } exports.Log = Log; /** * The Yeoman adapter had a log property that has the unusual * requirement of being both a function and an object. See the yeoman * environment log implementation * https://github.com/yeoman/environment/blob/5f0e87b696c4926ba69b9fbd83e4486a02492fcc/lib/util/log.js#L59 * * @param log The Log instance for the Yeoman logger to utilize. * @returns The log instance that is both a function and an object. */ const getYeomanLogger = (log) => { const yeomanLogger = (args) => { log.info(args); }; yeomanLogger.skip = (args) => { log.skip(args); return yeomanLogger; }; yeomanLogger.force = (args) => { log.force(args); return yeomanLogger; }; yeomanLogger.create = (args) => { log.create(args); return yeomanLogger; }; yeomanLogger.invoke = (args) => { log.invoke(args); return yeomanLogger; }; yeomanLogger.conflict = (args) => { log.conflict(args); return yeomanLogger; }; yeomanLogger.identical = (args) => { log.identical(args); return yeomanLogger; }; yeomanLogger.info = (args) => { log.info(args); return yeomanLogger; }; yeomanLogger.clear = () => { log.clear(); }; yeomanLogger.setCleanOutput = (...args) => { log.setCleanOutput(args); }; yeomanLogger.setOutput = (text) => { log.setOutput(text); }; yeomanLogger.pad = (status) => { return log.pad(status); }; yeomanLogger.write = (...args) => { log.write(...args); return yeomanLogger; }; yeomanLogger.getCleanOutput = () => { return log.getCleanOutput(); }; yeomanLogger.getOutput = () => { return log.getOutput(); }; return yeomanLogger; }; exports.getYeomanLogger = getYeomanLogger; //# sourceMappingURL=logger.js.map