1const NPMLOG = require('npmlog') 2const PROCLOG = require('proc-log') 3 4// Sets getter and optionally a setter 5// otherwise setting should throw 6const accessors = (obj, set) => (k) => ({ 7 get: () => obj[k], 8 set: set ? (v) => (obj[k] = v) : () => { 9 throw new Error(`Cant set ${k}`) 10 }, 11}) 12 13// Set the value to a bound function on the object 14const value = (obj) => (k) => ({ 15 value: (...args) => obj[k].apply(obj, args), 16}) 17 18const properties = { 19 // npmlog getters/setters 20 level: accessors(NPMLOG, true), 21 heading: accessors(NPMLOG, true), 22 levels: accessors(NPMLOG), 23 gauge: accessors(NPMLOG), 24 stream: accessors(NPMLOG), 25 tracker: accessors(NPMLOG), 26 progressEnabled: accessors(NPMLOG), 27 // npmlog methods 28 useColor: value(NPMLOG), 29 enableColor: value(NPMLOG), 30 disableColor: value(NPMLOG), 31 enableUnicode: value(NPMLOG), 32 disableUnicode: value(NPMLOG), 33 enableProgress: value(NPMLOG), 34 disableProgress: value(NPMLOG), 35 clearProgress: value(NPMLOG), 36 showProgress: value(NPMLOG), 37 newItem: value(NPMLOG), 38 newGroup: value(NPMLOG), 39 // proclog methods 40 notice: value(PROCLOG), 41 error: value(PROCLOG), 42 warn: value(PROCLOG), 43 info: value(PROCLOG), 44 verbose: value(PROCLOG), 45 http: value(PROCLOG), 46 silly: value(PROCLOG), 47 pause: value(PROCLOG), 48 resume: value(PROCLOG), 49} 50 51const descriptors = Object.entries(properties).reduce((acc, [k, v]) => { 52 acc[k] = { enumerable: true, ...v(k) } 53 return acc 54}, {}) 55 56// Create an object with the allowed properties rom npm log and all 57// the logging methods from proc log 58// XXX: this should go away and requires of this should be replaced with proc-log + new display 59module.exports = Object.freeze(Object.defineProperties({}, descriptors)) 60