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I,IAAI,GAAG,CAAA;iBACZ;qBAAM;oBACL,IAAI,IAAI,IAAI,GAAG,YAAY,CAAA;iBAC5B;aACF;SACF;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAA;SAClC;aAAM;YACL,OAAO,CAAC,OAAO,CAAC,CAAA;SACjB;IACH,CAAC;CACF;AA/FD,wBA+FC;AAED,MAAM,cAAc,GAA+B;IACjD,IAAI,EAAE,KAAK,CAAC,IAAI;IAChB,IAAI,EAAE,KAAK,CAAC,MAAM;IAClB,KAAK,EAAE,KAAK,CAAC,GAAG;IAChB,KAAK,EAAE,KAAK,CAAC,KAAK;CACnB,CAAA;AAEY,QAAA,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import { Chalk } from \"chalk\"\nimport * as chalk from \"chalk\"\nimport _debug from \"debug\"\nimport WritableStream = NodeJS.WritableStream\n\nlet printer: ((message: string) => void) | null = null\n\nexport const debug = _debug(\"electron-builder\")\n\nexport interface Fields {\n [index: string]: any\n}\n\nexport function setPrinter(value: ((message: string) => void) | null) {\n printer = value\n}\n\nexport type LogLevel = \"info\" | \"warn\" | \"debug\" | \"notice\" | \"error\"\n\nexport const PADDING = 2\n\nexport class Logger {\n constructor(protected readonly stream: WritableStream) {}\n\n messageTransformer: (message: string, level: LogLevel) => string = it => it\n\n filePath(file: string) {\n const cwd = process.cwd()\n return file.startsWith(cwd) ? file.substring(cwd.length + 1) : file\n }\n\n // noinspection JSMethodCanBeStatic\n get isDebugEnabled() {\n return debug.enabled\n }\n\n info(messageOrFields: Fields | null | string, message?: string) {\n this.doLog(message, messageOrFields, \"info\")\n }\n\n error(messageOrFields: Fields | null | string, message?: string) {\n this.doLog(message, messageOrFields, \"error\")\n }\n\n warn(messageOrFields: Fields | null | string, message?: string): void {\n this.doLog(message, messageOrFields, \"warn\")\n }\n\n debug(fields: Fields | null, message: string) {\n if (debug.enabled) {\n this._doLog(message, fields, \"debug\")\n }\n }\n\n private doLog(message: string | undefined | Error, messageOrFields: Fields | null | string, level: LogLevel) {\n if (message === undefined) {\n this._doLog(messageOrFields as string, null, level)\n } else {\n this._doLog(message, messageOrFields as Fields | null, level)\n }\n }\n\n private _doLog(message: string | Error, fields: Fields | null, level: LogLevel) {\n // noinspection SuspiciousInstanceOfGuard\n if (message instanceof Error) {\n message = message.stack || message.toString()\n } else {\n message = message.toString()\n }\n\n const levelIndicator = level === \"error\" ? \"⨯\" : \"•\"\n const color = LEVEL_TO_COLOR[level]\n this.stream.write(`${\" \".repeat(PADDING)}${color(levelIndicator)} `)\n this.stream.write(Logger.createMessage(this.messageTransformer(message, level), fields, level, color, PADDING + 2 /* level indicator and space */))\n this.stream.write(\"\\n\")\n }\n\n static createMessage(message: string, fields: Fields | null, level: LogLevel, color: (it: string) => string, messagePadding = 0): string {\n if (fields == null) {\n return message\n }\n\n const fieldPadding = \" \".repeat(Math.max(2, 16 - message.length))\n let text = (level === \"error\" ? color(message) : message) + fieldPadding\n const fieldNames = Object.keys(fields)\n let counter = 0\n for (const name of fieldNames) {\n let fieldValue = fields[name]\n let valuePadding: string | null = null\n // Remove unnecessary line breaks\n if (fieldValue != null && typeof fieldValue === \"string\" && fieldValue.includes(\"\\n\")) {\n valuePadding = \" \".repeat(messagePadding + message.length + fieldPadding.length + 2)\n fieldValue = fieldValue.replace(/\\n\\s*\\n/g, `\\n${valuePadding}`)\n } else if (Array.isArray(fieldValue)) {\n fieldValue = JSON.stringify(fieldValue)\n }\n\n text += `${color(name)}=${fieldValue}`\n if (++counter !== fieldNames.length) {\n if (valuePadding == null) {\n text += \" \"\n } else {\n text += \"\\n\" + valuePadding\n }\n }\n }\n return text\n }\n\n log(message: string): void {\n if (printer == null) {\n this.stream.write(`${message}\\n`)\n } else {\n printer(message)\n }\n }\n}\n\nconst LEVEL_TO_COLOR: { [index: string]: Chalk } = {\n info: chalk.blue,\n warn: chalk.yellow,\n error: chalk.red,\n debug: chalk.white,\n}\n\nexport const log = new Logger(process.stdout)\n"]}