From fa01c5a4cb42d80ac147dc5ab512a0795dbe14da Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 20:27:04 -0400 Subject: Moving files to match module --- src/PursLoader/ChildProcess.purs | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/PursLoader/ChildProcess.purs (limited to 'src/PursLoader/ChildProcess.purs') diff --git a/src/PursLoader/ChildProcess.purs b/src/PursLoader/ChildProcess.purs new file mode 100644 index 0000000..34558fa --- /dev/null +++ b/src/PursLoader/ChildProcess.purs @@ -0,0 +1,56 @@ +module PursLoader.ChildProcess + ( ChildProcess() + , spawn + ) where + +import Control.Monad.Aff (Aff(), makeAff) +import Control.Monad.Eff (Eff()) +import Control.Monad.Eff.Exception (Error()) + +import Data.Function + +foreign import data ChildProcess :: ! + +spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String +spawn command args = makeAff $ runFn4 spawnFn command args + +foreign import spawnFn """ +function spawnFn(command, args, errback, callback) { + return function(){ + var child_process = require('child_process'); + + var process = child_process.spawn(command, args); + + var stdout = new Buffer(0); + + var stderr = new Buffer(0); + + process.stdout.on('data', function(data){ + stdout = Buffer.concat([stdout, new Buffer(data)]); + }); + + process.stderr.on('data', function(data){ + stderr = Buffer.concat([stderr, new Buffer(data)]); + }); + + process.on('close', function(code){ + var chalk = require('chalk'); + + var output = stdout.toString('utf-8'); + + var error = stderr.toString('utf-8'); + + if (error.length > 0) { + console.error('\n' + chalk.red('*') + ' ' + error); + } + + if (code !== 0) errback(new Error('Process terminated with code ' + code))(); + else callback(output)(); + }); + }; +} +""" :: forall eff. Fn4 String + [String] + (Error -> Eff (cp :: ChildProcess | eff) Unit) + (String -> Eff (cp :: ChildProcess | eff) Unit) + (Eff (cp :: ChildProcess | eff) Unit) -- cgit v1.2.3 From 03b840cb5fb8ff5217fefc9e1240a3131db309fc Mon Sep 17 00:00:00 2001 From: eric thul Date: Tue, 11 Aug 2015 20:57:07 -0400 Subject: PureScript 0.7 updates and migration to pulp --- src/PursLoader/ChildProcess.purs | 49 +++++++--------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'src/PursLoader/ChildProcess.purs') 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 , spawn ) where +import Prelude (Unit(), ($)) + import Control.Monad.Aff (Aff(), makeAff) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Exception (Error()) @@ -11,46 +13,11 @@ import Data.Function foreign import data ChildProcess :: ! -spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String +spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String spawn command args = makeAff $ runFn4 spawnFn command args -foreign import spawnFn """ -function spawnFn(command, args, errback, callback) { - return function(){ - var child_process = require('child_process'); - - var process = child_process.spawn(command, args); - - var stdout = new Buffer(0); - - var stderr = new Buffer(0); - - process.stdout.on('data', function(data){ - stdout = Buffer.concat([stdout, new Buffer(data)]); - }); - - process.stderr.on('data', function(data){ - stderr = Buffer.concat([stderr, new Buffer(data)]); - }); - - process.on('close', function(code){ - var chalk = require('chalk'); - - var output = stdout.toString('utf-8'); - - var error = stderr.toString('utf-8'); - - if (error.length > 0) { - console.error('\n' + chalk.red('*') + ' ' + error); - } - - if (code !== 0) errback(new Error('Process terminated with code ' + code))(); - else callback(output)(); - }); - }; -} -""" :: forall eff. Fn4 String - [String] - (Error -> Eff (cp :: ChildProcess | eff) Unit) - (String -> Eff (cp :: ChildProcess | eff) Unit) - (Eff (cp :: ChildProcess | eff) Unit) +foreign import spawnFn :: forall eff. Fn4 String + (Array String) + (Error -> Eff (cp :: ChildProcess | eff) Unit) + (String -> Eff (cp :: ChildProcess | eff) Unit) + (Eff (cp :: ChildProcess | eff) Unit) -- cgit v1.2.3