@@ -12,11 +12,13 @@ import Control.Monad.Eff.Class (liftEff)
12
12
import Control.Monad.Eff.Exception (catchException , EXCEPTION )
13
13
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff )
14
14
import Data.Argonaut (Json )
15
+ import Data.Array (uncons )
15
16
import Data.Either (Either (Left), either )
16
17
import Data.Either.Unsafe (fromRight )
17
18
import Data.Function.Eff (runEffFn2 , EffFn2 )
18
19
import Data.Int (floor )
19
- import Data.Maybe (Maybe (Nothing, Just))
20
+ import Data.Maybe (fromMaybe , Maybe (Nothing, Just))
21
+ import Data.String (split )
20
22
import Global (readInt )
21
23
import Node.ChildProcess (Exit (Normally), onExit , defaultSpawnOptions , spawn , ChildProcess , CHILD_PROCESS )
22
24
import Node.FS (FS )
@@ -63,7 +65,7 @@ main = launchAff do
63
65
log (" Watching " <> directory <> " on port " <> show port)
64
66
log owl
65
67
66
- log " Press b to run \" pulp build\" "
68
+ log " Press b to build (tries \" npm run build \" then \" pulp build\" ) "
67
69
log " Press q to quit"
68
70
pure unit
69
71
@@ -78,15 +80,18 @@ owl =
78
80
79
81
keyHandler ∷ ∀ e . Key → Eff ( console ∷ Console.CONSOLE
80
82
, cp ∷ CHILD_PROCESS
81
- , process ∷ Process.PROCESS | e ) Unit
83
+ , process ∷ Process.PROCESS
84
+ , fs ∷ FS | e ) Unit
82
85
keyHandler k = case k of
83
- Key {ctrl: false , name: " b" , meta: false , shift: false } → buildProject
86
+ Key {ctrl: false , name: " b" , meta: false , shift: false } → getBuildScript >>= buildProject
84
87
Key {ctrl: false , name: " q" , meta: false , shift: false } → Console .log " Bye!" *> Process .exit 0
85
88
Key {ctrl, name, meta, shift} → Console .log name
86
89
87
- buildProject ∷ ∀ e . Eff (cp ∷ CHILD_PROCESS , console ∷ Console.CONSOLE | e ) Unit
88
- buildProject = do
89
- cp ← spawn " pulp" [" build" ] defaultSpawnOptions
90
+ buildProject ∷ ∀ e . Maybe String → Eff (cp ∷ CHILD_PROCESS , console ∷ Console.CONSOLE | e ) Unit
91
+ buildProject buildScript = do
92
+ cp <- fromMaybe
93
+ (spawn " pulp" [" build" ] defaultSpawnOptions) $
94
+ (\{head, tail} → spawn head tail defaultSpawnOptions) <$> (buildScript >>= uncons <<< split " " )
90
95
onExit cp \e → case e of
91
96
(Normally errcode) → Console .log (" Build exited with status: " <> show errcode)
92
97
_ → Console .log " Build terminated by Signal."
@@ -120,3 +125,9 @@ serverRunning (StartError e) = Nothing
120
125
foreign import gaze
121
126
∷ ∀ eff . EffFn2 (fs ∷ FS | eff ) String (String → Eff eff Unit ) Unit
122
127
foreign import clearConsole ∷ ∀ e . Eff (console ∷ Console.CONSOLE | e ) Unit
128
+
129
+ foreign import getBuildScriptImpl ∷ ∀ e . EffFn2 (fs ∷ FS | e ) (Maybe String ) (String → Maybe String ) (Maybe String )
130
+
131
+ getBuildScript ∷ ∀ e . Eff (fs ∷ FS | e ) (Maybe String )
132
+ getBuildScript = runEffFn2 getBuildScriptImpl Nothing Just
133
+
0 commit comments