@@ -12,7 +12,6 @@
13-----------------------------------------------------------------------------
13-----------------------------------------------------------------------------
15−{-# LANGUAGE PatternGuards #-}
16{-# LANGUAGE FlexibleContexts #-}
15{-# LANGUAGE FlexibleContexts #-}
17{-# LANGUAGE ScopedTypeVariables #-}
16{-# LANGUAGE ScopedTypeVariables #-}
18{-# LANGUAGE TupleSections #-}
17{-# LANGUAGE TupleSections #-}
@@ -53,16 +52,16 @@ data Options = Options
54-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
53-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
55guessModuleIdentifier :: (Applicative m, MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
54guessModuleIdentifier :: (Applicative m, MonadError ErrorMessage m) => FilePath -> m ModuleIdentifier
56−guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> (guessModuleType (takeFileName filename))
55+guessModuleIdentifier filename = ModuleIdentifier (takeFileName (takeDirectory filename)) <$> guessModuleType (takeFileName filename)
58 guessModuleType "index.js" = pure Regular
57 guessModuleType "index.js" = pure Regular
59− guessModuleType "foreign.js" = pure Foreign
58+ guessModuleType "foreign.js" = pure Foreign
60 guessModuleType name = throwError $ UnsupportedModulePath name
59 guessModuleType name = throwError $ UnsupportedModulePath name
62-- | The main application function.
61-- | The main application function.
63-- This function parses the input files, performs dead code elimination, filters empty modules
62-- This function parses the input files, performs dead code elimination, filters empty modules
64-- and generates and prints the final Javascript bundle.
63-- and generates and prints the final Javascript bundle.
65−app :: forall m. (Applicative m, MonadError ErrorMessage m, MonadIO m) => Options -> m String
64+app :: (Applicative m, MonadError ErrorMessage m, MonadIO m) => Options -> m String
66app Options{..} = do
65app Options{..} = do
67 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
66 inputFiles <- concat <$> mapM (liftIO . glob) optionsInputFiles
68 when (null inputFiles) . liftIO $ do
67 when (null inputFiles) . liftIO $ do
@@ -72,11 +71,11 @@ app Options{..} = do
72 js <- liftIO (readFile filename)
71 js <- liftIO (readFile filename)
73 mid <- guessModuleIdentifier filename
72 mid <- guessModuleIdentifier filename
74 return (mid, js)
73 return (mid, js)
76− let entryIds = (map (`ModuleIdentifier` Regular) optionsEntryPoints)
75+ let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
78 bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
77 bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
80-- | Command line options parser.
79-- | Command line options parser.
81options :: Parser Options
80options :: Parser Options
82options = Options <$> some inputFile
81options = Options <$> some inputFile
@@ -85,29 +84,29 @@ options = Options <$> some inputFile
85 <*> optional mainModule
84 <*> optional mainModule
86 <*> namespace
85 <*> namespace
87 <*> optional requirePath
86 <*> optional requirePath
89 inputFile :: Parser FilePath
88 inputFile :: Parser FilePath
90 inputFile = strArgument $
89 inputFile = strArgument $
91 metavar "FILE"
90 metavar "FILE"
92 <> help "The input .js file(s)"
91 <> help "The input .js file(s)"
94 outputFile :: Parser FilePath
93 outputFile :: Parser FilePath
95 outputFile = strOption $
94 outputFile = strOption $
97 <> long "output"
96 <> long "output"
98 <> help "The output .js file"
97 <> help "The output .js file"
100 entryPoint :: Parser String
99 entryPoint :: Parser String
101 entryPoint = strOption $
100 entryPoint = strOption $
102 short 'm'
101 short 'm'
103 <> long "module"
102 <> long "module"
104 <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
103 <> help "Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed."
106 mainModule :: Parser String
105 mainModule :: Parser String
107 mainModule = strOption $
106 mainModule = strOption $
108 long "main"
107 long "main"
109 <> help "Generate code to run the main method in the specified module."
108 <> help "Generate code to run the main method in the specified module."
111 namespace :: Parser String
110 namespace :: Parser String
112 namespace = strOption $
111 namespace = strOption $
113 short 'n'
112 short 'n'
@@ -122,8 +121,8 @@ options = Options <$> some inputFile
122 <> long "require-path"
121 <> long "require-path"
123 <> Opts.value ""
122 <> Opts.value ""
124 <> help "The path prefix used in require() calls in the generated JavaScript"
123 <> help "The path prefix used in require() calls in the generated JavaScript"
126−-- | Make it go.
125+-- | Make it go.
127main :: IO ()
126main :: IO ()
129 opts <- execParser (info (version <*> helper <*> options) infoModList)
128 opts <- execParser (info (version <*> helper <*> options) infoModList)