]>
git.immae.eu Git - github/fretlink/purs-loader.git/blob - src/PursLoader/ChildProcess.js
3 // module PursLoader.ChildProcess
5 var child_process
= require('child_process');
7 var chalk
= require('chalk');
9 function spawnFn(command
, args
, errback
, callback
) {
11 var process
= child_process
.spawn(command
, args
);
13 var stdout
= new Buffer(0);
15 var stderr
= new Buffer(0);
17 process
.stdout
.on('data', function(data
){
18 stdout
= Buffer
.concat([stdout
, new Buffer(data
)]);
21 process
.stderr
.on('data', function(data
){
22 stderr
= Buffer
.concat([stderr
, new Buffer(data
)]);
25 process
.on('close', function(code
){
26 var output
= stdout
.toString('utf-8');
28 var error
= stderr
.toString('utf-8');
30 if (error
.length
> 0) {
31 console
.error('\n' + chalk
.red('*') + ' ' + error
);
34 if (code
!== 0) errback(new Error('Process terminated with code ' + code
))();
35 else callback(output
)();
40 exports
.spawnFn
= spawnFn
;