Created
May 27, 2018 14:06
-
-
Save Kirill89/690268a041136013bb17be1999b39ebd to your computer and use it in GitHub Desktop.
colorful output from webpack to html stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const {spawn} = require('child_process'); | |
const Convert = require('ansi-to-html'); | |
const express = require('express'); | |
const app = express(); | |
const convert = new Convert({ | |
fg: '#000', | |
newline: true, | |
escapeXML: true | |
}); | |
app.get('/', (req, res) => { | |
const proc = spawn('npm', ['run', 'build:dev:int']); | |
proc.stdout.on('data', (data) => { | |
res.write(convert.toHtml(data.toString())); | |
}); | |
proc.stderr.on('data', (data) => { | |
res.write(` | |
<span style="color: #ff0000;"> | |
${convert.toHtml(data.toString())} | |
</span> | |
`); | |
}); | |
proc.on('close', (code) => { | |
res.write(code); | |
res.end(); | |
}); | |
}); | |
app.listen(3000, () => console.log('Example app listening on port 3000!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment