Skip to content

Commit

Permalink
Make spago run write a JS file and execute it (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwoo authored and f-f committed Jun 27, 2019
1 parent 0ef0462 commit 127bac9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ runWithNode defaultModuleName maybeSuccessMessage failureMessage maybeModuleName
where
moduleName = fromMaybe defaultModuleName maybeModuleName
args = Text.intercalate " " $ map Purs.unExtraArg nodeArgs
cmd = "node -e \"require('./output/" <> Purs.unModuleName moduleName <> "').main()\" " <> args
contents = "#!/usr/bin/env node\n\n" <> "require('../output/" <> Purs.unModuleName moduleName <> "').main()"
cmd = "node .spago/run.js " <> args
nodeAction = do
echoDebug $ "Writing .spago/run.js"
writeTextFile ".spago/run.js" contents
chmod executable ".spago/run.js"
shell cmd empty >>= \case
ExitSuccess -> fromMaybe (pure ()) (echo <$> maybeSuccessMessage)
ExitFailure n -> die $ failureMessage <> repr n
Expand Down
4 changes: 3 additions & 1 deletion src/Spago/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module Spago.Prelude
, mktree
, mv
, cptree
, chmod
, executable
, readTextFile
, writeTextFile
, atomically
Expand Down Expand Up @@ -97,7 +99,7 @@ import System.FilePath (isAbsolute, pathSeparator, (</>)
import System.IO (hPutStrLn)
import Turtle (ExitCode (..), FilePath, appendonly, mktree, repr,
shell, shellStrict, systemStrictWithErr, testdir,
testfile)
testfile, chmod, executable)
import UnliftIO (MonadUnliftIO, withRunInIO)
import UnliftIO.Directory (getModificationTime, makeAbsolute)
import UnliftIO.Exception (IOException, try)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/run-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Running `getGlobalCacheDir`
Installation complete.
Running command: `purs compile ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"`
Build succeeded.
Writing .spago/run.js

0 comments on commit 127bac9

Please sign in to comment.