Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added compilation tooling to keep an eye on errors/success of compila…
…tions
- Loading branch information
Showing
3 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const spawn = require('child_process').spawn; | ||
const EventEmitter = require('events'); | ||
|
||
class CompileEmitter extends EventEmitter {} | ||
|
||
const compileEmitter = new CompileEmitter(); | ||
|
||
const bsb = spawn('npm', ['run', 'dev:bsb']); | ||
|
||
const webpack = spawn('npm', ['run', 'dev:webpack']); | ||
|
||
const berror = spawn('berror', ['--path-to-refmttype', 'refmttype']); | ||
|
||
const compileStatus = { | ||
bsb: { | ||
status: 'success', | ||
msg: 'OK', | ||
}, | ||
webpack: { | ||
status: 'success', | ||
msg: 'OK', | ||
}, | ||
} | ||
|
||
function clearConsole() { | ||
process.stdout.write( | ||
process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H' | ||
); | ||
} | ||
|
||
bsb.stdout.on('data', (data) => { | ||
berror.stdin.write(data); | ||
}); | ||
|
||
bsb.stderr.on('data', (data) => { | ||
berror.stdin.write(data); | ||
}); | ||
|
||
webpack.stdout.on('data', (data) => { | ||
const str = data.toString(); | ||
if (str.includes('ERROR')) { | ||
compileStatus.webpack = { | ||
status: 'error', | ||
msg: str, | ||
}; | ||
compileEmitter.emit('log'); | ||
} else if (str.includes('webpack: Compiled successfully')) { | ||
compileStatus.webpack = { | ||
status: 'success', | ||
msg: 'OK', | ||
}; | ||
compileEmitter.emit('log'); | ||
} | ||
}); | ||
|
||
webpack.stderr.on('data', (data) => { | ||
compileStatus.webpack = { | ||
status: 'error', | ||
msg: data.toString(), | ||
}; | ||
compileEmitter.emit('log'); | ||
}); | ||
|
||
berror.stdout.on('data', (data) => { | ||
const str = data.toString(); | ||
if (str.includes('.re:')) { | ||
compileStatus.bsb = { | ||
status: 'error', | ||
msg: str, | ||
}; | ||
compileEmitter.emit('log'); | ||
} else if (str.includes('>>>> Finish compiling') && !str.includes('ninja: build stopped: subcommand failed.')) { | ||
compileStatus.bsb = { | ||
status: 'success', | ||
msg: 'OK', | ||
}; | ||
compileEmitter.emit('log'); | ||
} | ||
}); | ||
|
||
compileEmitter.on('log', () => { | ||
clearConsole(); | ||
const { bsb, webpack } = compileStatus; | ||
|
||
process.stdout.write(chalk.yellow('[BUCKLESCRIPT]')); | ||
process.stdout.write('\n'); | ||
|
||
if (bsb.status === 'error') { | ||
process.stdout.write(chalk.red('Compilation Error')); | ||
process.stdout.write('\n\n'); | ||
process.stdout.write(bsb.msg); | ||
} else if (bsb.status === 'success') { | ||
process.stdout.write(chalk.green('Compilation Success')); | ||
} else { | ||
process.stdout.write(chalk.yellow('Compilation Status Unknown')); | ||
} | ||
|
||
process.stdout.write('\n\n'); | ||
|
||
process.stdout.write(chalk.yellow('[WEBPACK]')); | ||
process.stdout.write('\n'); | ||
|
||
if (webpack.status === 'error') { | ||
process.stdout.write(chalk.red('Compilation Error')); | ||
process.stdout.write('\n\n'); | ||
process.stdout.write(webpack.msg); | ||
} else if (webpack.status === 'success') { | ||
process.stdout.write(chalk.green('Compilation Success')); | ||
} else { | ||
process.stdout.write(chalk.yellow('Compilation Status Unknown')); | ||
} | ||
}) |
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