UNPKG

@quadnix/octo-build

Version:

Octo-Build is a CLI tool to build Octo projects.

35 lines 1.2 kB
import { createWriteStream } from 'fs'; import { join, resolve } from 'path'; import chalk, {} from 'chalk'; export class StreamManager { constructor() { this.colors = { BLUE: chalk.blue, CYAN: chalk.cyan, GREEN: chalk.green, MAGENTA: chalk.magenta, YELLOW: chalk.yellow, }; } registerStream(jobName, stream, options) { const colorKeys = Object.keys(this.colors); const randomColor = this.colors[colorKeys[(colorKeys.length * Math.random()) << 0]]; stream.stdout.on('data', (data) => { console.log(randomColor(data.toString())); }); stream.stderr.on('error', (error) => { console.log(chalk.red(error)); }); stream.on('close', () => { stream.removeAllListeners(); }); if (options.logsPathPrefix) { const writeStream = createWriteStream(resolve(join(options.logsPathPrefix, `${jobName}.log`)), { flags: 'w', }); stream.stdout.pipe(writeStream); stream.stderr.pipe(writeStream); } } } //# sourceMappingURL=stream-manager.js.map