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C,AACF;;AAED,MAAM,AAAM,SAAI,AAAO,QAAC,AAAc,OAAC,AAAK,QAAG,IAAI,AAAS,UAAC,AAAO,QAAC,AAAM,AAAC,UAAG,IAAI,AAAM,OAAC,AAAO,QAAC,AAAM,AAAC,AAEzG,AAAM;cAAe,AAAe;AAClC,AAAM,WAAC,AAAI,KAAC,AAAO,AAAC,AACtB;AAAC,AAED,AAAM;aAAc,AAAe;AACjC,AAAM,WAAC,AAAG,IAAC,AAAO,AAAC,AACrB;AAAC,AAED,AAAM;iBAAkB,AAAa,OAAE,AAA4C;AACjF,AAAM,WAAC,AAAM,OAAC,AAAO,QAAC,AAAK,OAAE,AAAO,AAAC,AACvC;AAAC,AAED,AAAM;cAAe,AAAa,OAAE,AAA4C;AAC9E,AAAM,WAAC,AAAM,OAAC,AAAI,KAAC,AAAK,OAAE,AAAO,AAAC,AACpC;AAAC","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { yellow } from \"chalk\"\nimport { get as getEmoji } from \"node-emoji\"\nimport WritableStream = NodeJS.WritableStream\n\nlet printer: ((message: string) => void) | null = null\n\nexport function setPrinter(value: ((message: string) => void) | null) {\n printer = value\n}\n\nclass Logger {\n constructor(protected readonly stream: WritableStream) {\n }\n\n warn(message: string): void {\n this.log(yellow(`Warning: ${message}`))\n }\n\n log(message: string): void {\n if (printer == null) {\n this.stream.write(`${message}\\n`)\n }\n else {\n printer(message)\n }\n }\n\n subTask(title: string, _promise: BluebirdPromise<any> | Promise<any>): BluebirdPromise<any> {\n this.log(` ${title}`)\n return _promise as BluebirdPromise<any>\n }\n\n task(title: string, _promise: BluebirdPromise<any> | Promise<any>): BluebirdPromise<any> {\n const promise = _promise as BluebirdPromise<any>\n this.log(title)\n return promise\n }\n}\n\nclass TtyLogger extends Logger {\n constructor(stream: WritableStream) {\n super(stream)\n }\n\n warn(message: string): void {\n this.log(`${getEmoji(\"warning\")} ${yellow(message)}`)\n }\n}\n\nconst logger = (process.stdout as any).isTTY ? new TtyLogger(process.stdout) : new Logger(process.stdout)\n\nexport function warn(message: string) {\n logger.warn(message)\n}\n\nexport function log(message: string) {\n logger.log(message)\n}\n\nexport function subTask(title: string, promise: BluebirdPromise<any> | Promise<any>): BluebirdPromise<any> {\n return logger.subTask(title, promise)\n}\n\nexport function task(title: string, promise: BluebirdPromise<any> | Promise<any>): BluebirdPromise<any> {\n return logger.task(title, promise)\n}"]}