From de41d3bbc60e71bd25e01ef3b99427e53cfbde27 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Sat, 7 May 2022 12:21:10 +0200 Subject: [PATCH 1/2] Recognize /dev/stdout as a valid value to gren make. --- terminal/src/Main.hs | 2 +- terminal/src/Make.hs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/terminal/src/Main.hs b/terminal/src/Main.hs index 1c88e1b65..eadc54264 100644 --- a/terminal/src/Main.hs +++ b/terminal/src/Main.hs @@ -138,7 +138,7 @@ make = flags Make.Flags |-- onOff "debug" "Turn on the time-travelling debugger. It allows you to rewind and replay events. The events can be imported/exported into a file, which makes for very precise bug reports!" |-- onOff "optimize" "Turn on optimizations to make code smaller and faster. For example, the compiler renames record fields to be as short as possible and unboxes values to reduce allocation." - |-- flag "output" Make.output "Specify the name of the resulting JS file. For example --output=assets/gren.js to generate the JS at assets/gren.js or --output=/dev/null to generate no output at all!" + |-- flag "output" Make.output "Specify the name of the resulting JS file. For example --output=assets/gren.js to generate the JS at assets/gren.js. You can also use --output=/dev/stdout to output the JS to the terminal, or --output=/dev/null to generate no output at all!" |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!" |-- flag "docs" Make.docsFile "Generate a JSON file of documentation for a package. Eventually it will be possible to preview docs with `reactor` because it is quite hard to deal with these JSON files directly." in Terminal.Command "make" Uncommon details example (zeroOrMore grenFile) makeFlags Make.run diff --git a/terminal/src/Make.hs b/terminal/src/Make.hs index ab20fd00c..cbbc7ff90 100644 --- a/terminal/src/Make.hs +++ b/terminal/src/Make.hs @@ -44,6 +44,7 @@ data Output = JS FilePath | Html FilePath | DevNull + | DevStdOut data ReportType = Json @@ -91,6 +92,8 @@ runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs) = do builder <- toBuilder root details desiredMode artifacts generate style "gren.js" builder (NE.List name names) + Just DevStdOut -> + return () Just DevNull -> return () Just (JS target) -> @@ -239,11 +242,12 @@ output = _plural = "output files", _parser = parseOutput, _suggest = \_ -> return [], - _examples = \_ -> return ["gren.js", "index.html", "/dev/null"] + _examples = \_ -> return ["gren.js", "index.html", "/dev/null", "/dev/stdout"] } parseOutput :: String -> Maybe Output parseOutput name + | name == "/dev/stdout" = Just DevStdOut | isDevNull name = Just DevNull | hasExt ".html" name = Just (Html name) | hasExt ".js" name = Just (JS name) From ff6033c3cb64062033ebb0acde3761add7758516 Mon Sep 17 00:00:00 2001 From: Robin Heggelund Hansen Date: Sat, 7 May 2022 12:50:36 +0200 Subject: [PATCH 2/2] Implement print to stdout. --- terminal/src/Make.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/terminal/src/Make.hs b/terminal/src/Make.hs index cbbc7ff90..64d897cfd 100644 --- a/terminal/src/Make.hs +++ b/terminal/src/Make.hs @@ -28,6 +28,7 @@ import qualified Reporting.Exit as Exit import qualified Reporting.Task as Task import qualified System.Directory as Dir import qualified System.FilePath as FP +import qualified System.IO as IO import Terminal (Parser (..)) -- FLAGS @@ -93,7 +94,13 @@ runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs) = builder <- toBuilder root details desiredMode artifacts generate style "gren.js" builder (NE.List name names) Just DevStdOut -> - return () + case getMains artifacts of + [] -> + return () + _ -> + do + builder <- toBuilder root details desiredMode artifacts + Task.io $ B.hPutBuilder IO.stdout builder Just DevNull -> return () Just (JS target) ->