diff options
author | eric thul <thul.eric@gmail.com> | 2015-08-11 20:57:07 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-08-11 20:57:07 -0400 |
commit | 03b840cb5fb8ff5217fefc9e1240a3131db309fc (patch) | |
tree | 6183f4453aa15ad67ee0249fb8d35702cef5ecad /src/PursLoader/ChildProcess.js | |
parent | fa01c5a4cb42d80ac147dc5ab512a0795dbe14da (diff) | |
download | purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.gz purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.tar.zst purs-loader-03b840cb5fb8ff5217fefc9e1240a3131db309fc.zip |
PureScript 0.7 updates and migration to pulp
Diffstat (limited to 'src/PursLoader/ChildProcess.js')
-rw-r--r-- | src/PursLoader/ChildProcess.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/PursLoader/ChildProcess.js b/src/PursLoader/ChildProcess.js new file mode 100644 index 0000000..d62aef6 --- /dev/null +++ b/src/PursLoader/ChildProcess.js | |||
@@ -0,0 +1,40 @@ | |||
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; | ||