aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/ChildProcess.purs
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
committereric thul <thul.eric@gmail.com>2015-08-11 20:57:07 -0400
commit03b840cb5fb8ff5217fefc9e1240a3131db309fc (patch)
tree6183f4453aa15ad67ee0249fb8d35702cef5ecad /src/PursLoader/ChildProcess.purs
parentfa01c5a4cb42d80ac147dc5ab512a0795dbe14da (diff)
downloadpurs-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.purs')
-rw-r--r--src/PursLoader/ChildProcess.purs49
1 files changed, 8 insertions, 41 deletions
diff --git a/src/PursLoader/ChildProcess.purs b/src/PursLoader/ChildProcess.purs
index 34558fa..3bd960b 100644
--- a/src/PursLoader/ChildProcess.purs
+++ b/src/PursLoader/ChildProcess.purs
@@ -3,6 +3,8 @@ module PursLoader.ChildProcess
3 , spawn 3 , spawn
4 ) where 4 ) where
5 5
6import Prelude (Unit(), ($))
7
6import Control.Monad.Aff (Aff(), makeAff) 8import Control.Monad.Aff (Aff(), makeAff)
7import Control.Monad.Eff (Eff()) 9import Control.Monad.Eff (Eff())
8import Control.Monad.Eff.Exception (Error()) 10import Control.Monad.Eff.Exception (Error())
@@ -11,46 +13,11 @@ import Data.Function
11 13
12foreign import data ChildProcess :: ! 14foreign import data ChildProcess :: !
13 15
14spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String 16spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String
15spawn command args = makeAff $ runFn4 spawnFn command args 17spawn command args = makeAff $ runFn4 spawnFn command args
16 18
17foreign import spawnFn """ 19foreign import spawnFn :: forall eff. Fn4 String
18function spawnFn(command, args, errback, callback) { 20 (Array String)
19 return function(){ 21 (Error -> Eff (cp :: ChildProcess | eff) Unit)
20 var child_process = require('child_process'); 22 (String -> Eff (cp :: ChildProcess | eff) Unit)
21 23 (Eff (cp :: ChildProcess | eff) Unit)
22 var process = child_process.spawn(command, args);
23
24 var stdout = new Buffer(0);
25
26 var stderr = new Buffer(0);
27
28 process.stdout.on('data', function(data){
29 stdout = Buffer.concat([stdout, new Buffer(data)]);
30 });
31
32 process.stderr.on('data', function(data){
33 stderr = Buffer.concat([stderr, new Buffer(data)]);
34 });
35
36 process.on('close', function(code){
37 var chalk = require('chalk');
38
39 var output = stdout.toString('utf-8');
40
41 var error = stderr.toString('utf-8');
42
43 if (error.length > 0) {
44 console.error('\n' + chalk.red('*') + ' ' + error);
45 }
46
47 if (code !== 0) errback(new Error('Process terminated with code ' + code))();
48 else callback(output)();
49 });
50 };
51}
52""" :: forall eff. Fn4 String
53 [String]
54 (Error -> Eff (cp :: ChildProcess | eff) Unit)
55 (String -> Eff (cp :: ChildProcess | eff) Unit)
56 (Eff (cp :: ChildProcess | eff) Unit)