Skip to content

Commit 07a8c8e

Browse files
committed
run npm build script if it exists
1 parent 14cbb60 commit 07a8c8e

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

Diff for: README.md

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ projects root folder.
2424
pscid will show you errors and warnings (one at a time) in whatever file you
2525
edit+save.
2626

27+
If you hit `b` inside pscid's console window it will try to either run `npm run
28+
build` or `pulp build`.
29+
30+
Pressing `q` quits pscid.
31+
2732
### Options
2833
- `-p` The port to use. Defaults to 4243
2934

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"setup": "bower link pscid && bower install",
1313
"compile": "psa -c -f \"src/**/*.js\" -f \"bower_components/purescript-*/src/**/*.js\" \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\"",
1414
"compile-self": "node index.js -c -f \"src/**/*.js\" -f \"bower_components/purescript-*/src/**/*.js\" \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\"",
15-
"prepublish": "rm -rf output && npm run compile"
15+
"prepublish": "rm -rf output && npm run compile",
16+
"build": "npm run compile"
1617
},
1718
"keywords": [
1819
"IDE",

Diff for: src/Main.js

+16
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,19 @@ exports.gaze = function(glob, cb){
2020
exports.clearConsole = function(){
2121
process.stdout.write('\033c');
2222
};
23+
24+
exports.getBuildScriptImpl = function(nothing, just){
25+
try {
26+
var pjson = require(process.cwd() + '/package.json');
27+
if (pjson.scripts && pjson.scripts.build){
28+
return just(pjson.scripts.build);
29+
}
30+
else {
31+
return nothing;
32+
}
33+
34+
} catch (e) {
35+
return nothing;
36+
}
37+
38+
};

Diff for: src/Main.purs

+18-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import Control.Monad.Eff.Class (liftEff)
1212
import Control.Monad.Eff.Exception (catchException, EXCEPTION)
1313
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
1414
import Data.Argonaut (Json)
15+
import Data.Array (uncons)
1516
import Data.Either (Either(Left), either)
1617
import Data.Either.Unsafe (fromRight)
1718
import Data.Function.Eff (runEffFn2, EffFn2)
1819
import Data.Int (floor)
19-
import Data.Maybe (Maybe(Nothing, Just))
20+
import Data.Maybe (fromMaybe, Maybe(Nothing, Just))
21+
import Data.String (split)
2022
import Global (readInt)
2123
import Node.ChildProcess (Exit(Normally), onExit, defaultSpawnOptions, spawn, ChildProcess, CHILD_PROCESS)
2224
import Node.FS (FS)
@@ -63,7 +65,7 @@ main = launchAff do
6365
log ("Watching " <> directory <> " on port " <> show port)
6466
log owl
6567

66-
log "Press b to run \"pulp build\""
68+
log "Press b to build (tries \"npm run build\" then \"pulp build\")"
6769
log "Press q to quit"
6870
pure unit
6971

@@ -78,15 +80,18 @@ owl =
7880

7981
keyHandler e . Key Eff ( console Console.CONSOLE
8082
, cp CHILD_PROCESS
81-
, process Process.PROCESS | e) Unit
83+
, process Process.PROCESS
84+
, fs FS | e) Unit
8285
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
8487
Key {ctrl: false, name: "q", meta: false, shift: false} → Console.log "Bye!" *> Process.exit 0
8588
Key {ctrl, name, meta, shift} → Console.log name
8689

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 " ")
9095
onExit cp \e → case e of
9196
(Normally errcode) → Console.log ("Build exited with status: " <> show errcode)
9297
_ → Console.log "Build terminated by Signal."
@@ -120,3 +125,9 @@ serverRunning (StartError e) = Nothing
120125
foreign import gaze
121126
eff. EffFn2 (fs FS | eff) String (String Eff eff Unit) Unit
122127
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

Comments
 (0)