@@ -35,6 +35,7 @@ import Control.Monad.Except
35import System.FilePath (takeFileName, takeDirectory)
35import System.FilePath (takeFileName, takeDirectory)
36import System.Exit (exitFailure)
36import System.Exit (exitFailure)
37import System.IO (stderr, hPutStrLn)
37import System.IO (stderr, hPutStrLn)
38+import System.Directory (createDirectoryIfMissing)
39import Language.JavaScript.Parser
40import Language.JavaScript.Parser
@@ -99,6 +100,7 @@ data Module = Module ModuleIdentifier [ModuleElement] deriving Show
99-- | Command line options.
100-- | Command line options.
100data Options = Options
101data Options = Options
101 { optionsInputFiles :: [FilePath]
102 { optionsInputFiles :: [FilePath]
103+ , optionsOutputFile :: Maybe FilePath
102 , optionsEntryPoints :: [String]
104 , optionsEntryPoints :: [String]
103 , optionsMainModule :: Maybe String
105 , optionsMainModule :: Maybe String
104 , optionsNamespace :: String
106 , optionsNamespace :: String
@@ -439,7 +441,7 @@ codeGen Options{..} ms = renderToString (NN (JSSourceElementsTop (prelude ++ con
440 prelude :: [JSNode]
442 prelude :: [JSNode]
441 prelude =
443 prelude =
442− [ NN (JSVariables (NT (JSLiteral "var") tokenPosnEmpty [ CommentA tokenPosnEmpty "// Generated by psc-bundle"
444+ [ NN (JSVariables (NT (JSLiteral "var") tokenPosnEmpty [ CommentA tokenPosnEmpty ("// Generated by psc-bundle " ++ showVersion Paths.version)
443 , WhiteSpace tokenPosnEmpty "\n"
445 , WhiteSpace tokenPosnEmpty "\n"
445 [ NN (JSVarDecl (sp (JSIdentifier optionsNamespace))
447 [ NN (JSVarDecl (sp (JSIdentifier optionsNamespace))
@@ -541,6 +543,7 @@ app opts@Options{..} = do
541-- | Command line options parser.
543-- | Command line options parser.
542options :: Parser Options
544options :: Parser Options
543options = Options <$> some inputFile
545options = Options <$> some inputFile
546+ <*> optional outputFile
544 <*> some entryPoint
547 <*> some entryPoint
545 <*> optional mainModule
548 <*> optional mainModule
546 <*> namespace
549 <*> namespace
@@ -550,6 +553,12 @@ options = Options <$> some inputFile
550 metavar "FILE"
553 metavar "FILE"
551 <> help "The input .js file(s)"
554 <> help "The input .js file(s)"
556+ outputFile :: Parser FilePath
557+ outputFile = strOption $
560+ <> help "The output .js file"
553 entryPoint :: Parser String
562 entryPoint :: Parser String
554 entryPoint = strOption $
563 entryPoint = strOption $
555 short 'm'
564 short 'm'
@@ -579,7 +588,11 @@ main = do
579 hPutStrLn stderr (unlines (printErrorMessage err))
588 hPutStrLn stderr (unlines (printErrorMessage err))
580 exitFailure
589 exitFailure
581 Right js ->
590 Right js ->
591+ case optionsOutputFile opts of
592+ Just outputFile -> do
593+ createDirectoryIfMissing True (takeDirectory outputFile)
594+ writeFile outputFile js
582− putStrLn js
595+ Nothing -> putStrLn js
584 infoModList = fullDesc <> headerInfo <> footerInfo
597 infoModList = fullDesc <> headerInfo <> footerInfo
585 headerInfo = header "psc-bundle - Bundles compiled PureScript modules for the browser"
598 headerInfo = header "psc-bundle - Bundles compiled PureScript modules for the browser"