git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add version to psc-bundle output, add -o option
commit7ef18b791ccd22305beb8c3f066bc3122414d1d5 authorPhil Freeman <paf31@cantab.net> dateSun 28 Jun 2015, 15:22 (11 years ago) parentc92c7a6
1 file changed+15−2
psc-bundle/Main.hs+15−2
psc-bundle/Main.hs+15−2
@@ -35,6 +35,7 @@ import Control.Monad.Except
3535import System.FilePath (takeFileName, takeDirectory)
3636import System.Exit (exitFailure)
3737import System.IO (stderr, hPutStrLn)
38+import System.Directory (createDirectoryIfMissing)
3839
3940import Language.JavaScript.Parser
4041
@@ -99,6 +100,7 @@ data Module = Module ModuleIdentifier [ModuleElement] deriving Show
99100-- | Command line options.
100101data Options = Options
101102 { optionsInputFiles :: [FilePath]
103+ , optionsOutputFile :: Maybe FilePath
102104 , optionsEntryPoints :: [String]
103105 , optionsMainModule :: Maybe String
104106 , optionsNamespace :: String
@@ -439,7 +441,7 @@ codeGen Options{..} ms = renderToString (NN (JSSourceElementsTop (prelude ++ con
439441
440442 prelude :: [JSNode]
441443 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)
443445 , WhiteSpace tokenPosnEmpty "\n"
444446 ])
445447 [ NN (JSVarDecl (sp (JSIdentifier optionsNamespace))
@@ -541,6 +543,7 @@ app opts@Options{..} = do
541543-- | Command line options parser.
542544options :: Parser Options
543545options = Options <$> some inputFile
546+ <*> optional outputFile
544547 <*> some entryPoint
545548 <*> optional mainModule
546549 <*> namespace
@@ -550,6 +553,12 @@ options = Options <$> some inputFile
550553 metavar "FILE"
551554 <> help "The input .js file(s)"
552555
556+ outputFile :: Parser FilePath
557+ outputFile = strOption $
558+ short 'o'
559+ <> long "output"
560+ <> help "The output .js file"
561+
553562 entryPoint :: Parser String
554563 entryPoint = strOption $
555564 short 'm'
@@ -579,7 +588,11 @@ main = do
579588 hPutStrLn stderr (unlines (printErrorMessage err))
580589 exitFailure
581590 Right js ->
582− putStrLn js
591+ case optionsOutputFile opts of
592+ Just outputFile -> do
593+ createDirectoryIfMissing True (takeDirectory outputFile)
594+ writeFile outputFile js
595+ Nothing -> putStrLn js
583596 where
584597 infoModList = fullDesc <> headerInfo <> footerInfo
585598 headerInfo = header "psc-bundle - Bundles compiled PureScript modules for the browser"