Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Bugfixes:

New features:
- Add option to clear the screen to spago build/run (#209)
- Add option to pass args to node when doing spago test/run (#267)

Bugfixes:
- Produce an error message when asserting directory permissions (#250)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ $ spago run --main ModulePath.To.Main

# And pass arguments through to `purs compile`
$ spago run --main ModulePath.To.Main -- --verbose-errors

# Or pass arguments to node
$ spago run --node-args "arg1 arg2"
```


Expand Down
13 changes: 7 additions & 6 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ data Command
| VerifySet (Maybe Int) (Maybe CacheFlag)

-- | Test the project with some module, default Test.Main
| Test (Maybe ModuleName) BuildOptions
| Test (Maybe ModuleName) BuildOptions [ExtraArg]

-- | Run the project with some module, default Main
| Run (Maybe ModuleName) BuildOptions
| Run (Maybe ModuleName) BuildOptions [ExtraArg]

-- | Bundle the project into an executable
-- Builds the project before bundling
Expand Down Expand Up @@ -117,6 +117,7 @@ parser = do
noInstallBool = CLI.switch "no-install" 'n' "Don't run the automatic installation of packages"
clearScreenBool = CLI.switch "clear-screen" 'l' "Clear the screen on rebuild (watch mode only)"
noBuildBool = CLI.switch "no-build" 's' "Skip build step"
nodeArgs = CLI.many $ CLI.opt (Just . ExtraArg) "node-args" 'n' "Argument to pass to node (run/test only)"
watch = do
res <- watchBool
pure $ case res of
Expand Down Expand Up @@ -197,13 +198,13 @@ parser = do
test =
( "test"
, "Test the project with some module, default Test.Main"
, Test <$> mainModule <*> buildOptions
, Test <$> mainModule <*> buildOptions <*> nodeArgs
)

run =
( "run"
, "Runs the project with some module, default Main"
, Run <$> mainModule <*> buildOptions
, Run <$> mainModule <*> buildOptions <*> nodeArgs
)

bundleApp =
Expand Down Expand Up @@ -348,8 +349,8 @@ main = do
PackageSetUpgrade -> Spago.Packages.upgradePackageSet
Freeze -> Spago.Packages.freeze
Build buildOptions -> Spago.Build.build buildOptions Nothing
Test modName buildOptions -> Spago.Build.test modName buildOptions
Run modName buildOptions -> Spago.Build.run modName buildOptions
Test modName buildOptions nodeArgs -> Spago.Build.test modName buildOptions nodeArgs
Run modName buildOptions nodeArgs -> Spago.Build.run modName buildOptions nodeArgs
Repl paths pursArgs -> Spago.Build.repl paths pursArgs
BundleApp modName tPath shouldBuild buildOptions
-> Spago.Build.bundleApp WithMain modName tPath shouldBuild buildOptions
Expand Down
10 changes: 6 additions & 4 deletions src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ repl sourcePaths passthroughArgs = do

-- | Test the project: compile and run "Test.Main"
-- (or the provided module name) with node
test :: Spago m => Maybe Purs.ModuleName -> BuildOptions -> m ()
test :: Spago m => Maybe Purs.ModuleName -> BuildOptions -> [Purs.ExtraArg] -> m ()
test = runWithNode (Purs.ModuleName "Test.Main") (Just "Tests succeeded.") "Tests failed: "

-- | Run the project: compile and run "Main"
-- (or the provided module name) with node
run :: Spago m => Maybe Purs.ModuleName -> BuildOptions -> m ()
run :: Spago m => Maybe Purs.ModuleName -> BuildOptions -> [Purs.ExtraArg] -> m ()
run = runWithNode (Purs.ModuleName "Main") Nothing "Running failed, exit code: "

-- | Run the project with node: compile and run with the provided ModuleName
Expand All @@ -111,13 +111,15 @@ runWithNode
-> Text
-> Maybe Purs.ModuleName
-> BuildOptions
-> [Purs.ExtraArg]
-> m ()
runWithNode defaultModuleName maybeSuccessMessage failureMessage maybeModuleName buildOpts = do
runWithNode defaultModuleName maybeSuccessMessage failureMessage maybeModuleName buildOpts nodeArgs = do
echoDebug "Running NodeJS"
build buildOpts (Just nodeAction)
where
moduleName = fromMaybe defaultModuleName maybeModuleName
cmd = "node -e \"require('./output/" <> Purs.unModuleName moduleName <> "').main()\""
args = Text.intercalate " " $ map Purs.unExtraArg nodeArgs
cmd = "node -e \"require('./output/" <> Purs.unModuleName moduleName <> "').main()\" " <> args
nodeAction = do
shell cmd empty >>= \case
ExitSuccess -> fromMaybe (pure ()) (echo <$> maybeSuccessMessage)
Expand Down