]> git.immae.eu Git - github/fretlink/purs-loader.git/blob - src/PursLoader/ChildProcess.js
Fixing compiler warnings
[github/fretlink/purs-loader.git] / src / PursLoader / ChildProcess.js
1 'use strict';
2
3 // module PursLoader.ChildProcess
4
5 var child_process = require('child_process');
6
7 var chalk = require('chalk');
8
9 function spawnFn(command, args, errback, callback) {
10 return function(){
11 var process = child_process.spawn(command, args);
12
13 var stdout = new Buffer(0);
14
15 var stderr = new Buffer(0);
16
17 process.stdout.on('data', function(data){
18 stdout = Buffer.concat([stdout, new Buffer(data)]);
19 });
20
21 process.stderr.on('data', function(data){
22 stderr = Buffer.concat([stderr, new Buffer(data)]);
23 });
24
25 process.on('close', function(code){
26 var output = stdout.toString('utf-8');
27
28 var error = stderr.toString('utf-8');
29
30 if (error.length > 0) {
31 console.error('\n' + chalk.red('*') + ' ' + error);
32 }
33
34 if (code !== 0) errback(new Error('Process terminated with code ' + code))();
35 else callback(output)();
36 });
37 };
38 }
39
40 exports.spawnFn = spawnFn;