autoexporter 1.1.4 → 1.1.7
raw patch · 8 files changed
+171/−148 lines, 8 filesdep ~Cabaldep ~basedep ~directorysetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: Cabal, base, directory, filepath
API changes (from Hackage documentation)
- Autoexporter: ExportScopeDeep :: ExportScope
- Autoexporter: ExportScopeShallow :: ExportScope
- Autoexporter: data ExportScope
- Autoexporter: main :: IO ()
+ Autoexporter: defaultMain :: IO ()
Files
- Setup.hs +2/−2
- autoexporter.cabal +15/−12
- executables/Main.hs +4/−0
- library/Autoexporter.hs +121/−0
- package.yaml +28/−23
- source/executable/Main.hs +0/−5
- source/library/Autoexporter.hs +0/−105
- stack.yaml +1/−1
Setup.hs view
@@ -1,4 +1,4 @@-import qualified Distribution.Simple+import qualified Distribution.Simple as Cabal main :: IO ()-main = Distribution.Simple.defaultMain+main = Cabal.defaultMain
autoexporter.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 6a190e6853f9ec9990150e0da0f175b85e6cc8368b98ef113fbcd134e4118087+-- hash: 1e9db3995746e04f9908a67508f57ba69e6db75f57a9cb90eee2305c73b93cae name: autoexporter-version: 1.1.4+version: 1.1.7 synopsis: Automatically re-export modules. description: Autoexporter automatically re-exports modules. category: Utility@@ -29,13 +29,13 @@ library hs-source-dirs:- source/library- ghc-options: -Wall+ library+ ghc-options: -Weverything -Wno-implicit-prelude -Wno-safe -Wno-unsafe build-depends:- Cabal >=1.22 && <1.25 || >=2.0 && <2.3- , base >=4.7 && <4.11- , directory >=1.2.5 && <1.4- , filepath >=1.3 && <1.5+ Cabal >=1.24.0 && <1.25 || >=2.0.1 && <2.3+ , base >=4.9.0 && <4.12+ , directory >=1.2.6 && <1.4+ , filepath >=1.4.1 && <1.5 exposed-modules: Autoexporter other-modules:@@ -45,11 +45,14 @@ executable autoexporter main-is: Main.hs hs-source-dirs:- source/executable- ghc-options: -Wall+ executables+ ghc-options: -Weverything -Wno-implicit-prelude -Wno-safe -Wno-unsafe build-depends:- autoexporter- , base+ Cabal >=1.24.0 && <1.25 || >=2.0.1 && <2.3+ , autoexporter+ , base >=4.9.0 && <4.12+ , directory >=1.2.6 && <1.4+ , filepath >=1.4.1 && <1.5 other-modules: Paths_autoexporter default-language: Haskell2010
+ executables/Main.hs view
@@ -0,0 +1,4 @@+import qualified Autoexporter++main :: IO ()+main = Autoexporter.defaultMain
+ library/Autoexporter.hs view
@@ -0,0 +1,121 @@+-- | This package isn't really meant to be used as a library. It's typically+-- used as a GHC preprocessor, like so:+--+-- > {-# OPTIONS_GHC -F -pgmF autoexporter #-}+--+-- For more information, please see the README on GitHub:+-- <https://github.com/tfausak/autoexporter#readme>.+module Autoexporter+ ( defaultMain+ , mainWithArgs+ , autoexport+ , findFiles+ , findFilesDeep+ , makeModuleName+ , takeWhileEnd+ , isModuleName+ , parseModuleName+ , makeOutput+ , isHaskellFile+ , renderModule+ , unlines'+ , renderExport+ , renderImport+ ) where++import qualified Data.List as List+import qualified Data.Maybe as Maybe+import qualified Data.Traversable as Traversable+import qualified Distribution.ModuleName as ModuleName+import qualified Distribution.Text as Text+import qualified System.Directory as Directory+import qualified System.Environment as Environment+import qualified System.FilePath as FilePath++data ExportScope = ExportScopeShallow+ | ExportScopeDeep++defaultMain :: IO ()+defaultMain = do+ args <- Environment.getArgs+ mainWithArgs args++mainWithArgs :: [String] -> IO ()+mainWithArgs args =+ case args of+ [name, inputFile, outputFile, "--deep"] ->+ autoexport ExportScopeDeep name inputFile outputFile+ [name, inputFile, outputFile] ->+ autoexport ExportScopeShallow name inputFile outputFile+ _ -> fail ("unexpected arguments: " ++ show args)++autoexport :: ExportScope -> String -> FilePath -> FilePath -> IO ()+autoexport exportScope name inputFile outputFile = do+ let moduleName = makeModuleName name+ let directory = FilePath.dropExtension inputFile+ files <- findFiles exportScope directory+ let output = makeOutput moduleName directory files+ writeFile outputFile output++findFiles :: ExportScope -> FilePath -> IO [FilePath]+findFiles exportScope dir =+ case exportScope of+ ExportScopeShallow ->+ fmap (filter isHaskellFile) (Directory.listDirectory dir)+ ExportScopeDeep ->+ findFilesDeep dir++findFilesDeep :: FilePath -> IO [FilePath]+findFilesDeep dir = do+ rootItems <- Directory.listDirectory dir+ childItems <- Traversable.for rootItems $ \item -> do+ let path = dir FilePath.</> item+ dirExists <- Directory.doesDirectoryExist path+ if dirExists+ then fmap (fmap (item FilePath.</>)) (findFilesDeep path)+ else pure []+ pure $ mconcat (filter isHaskellFile rootItems : childItems)++makeModuleName :: FilePath -> String+makeModuleName name =+ let path = FilePath.dropExtension name+ parts = FilePath.splitDirectories path+ rest = takeWhileEnd isModuleName parts+ in List.intercalate "." rest++takeWhileEnd :: (a -> Bool) -> [a] -> [a]+takeWhileEnd p xs = reverse (takeWhile p (reverse xs))++isModuleName :: String -> Bool+isModuleName x = Maybe.isJust (parseModuleName x)++parseModuleName :: String -> Maybe ModuleName.ModuleName+parseModuleName = Text.simpleParse++makeOutput :: String -> FilePath -> [FilePath] -> String+makeOutput moduleName directory files =+ let haskellFiles = filter isHaskellFile files+ paths = map (directory FilePath.</>) haskellFiles+ modules = List.sort (map makeModuleName paths)+ in renderModule moduleName modules++isHaskellFile :: FilePath -> Bool+isHaskellFile x = List.isSuffixOf ".hs" x || List.isSuffixOf ".lhs" x++renderModule :: String -> [String] -> String+renderModule name modules =+ unlines'+ [ unwords ["module", name, "("]+ , unlines' (map renderExport modules)+ , ") where"+ , unlines' (map renderImport modules)+ ]++unlines' :: [String] -> String+unlines' = List.intercalate "\n"++renderExport :: String -> String+renderExport x = " module " ++ x ++ ","++renderImport :: String -> String+renderImport x = "import " ++ x
package.yaml view
@@ -1,30 +1,35 @@+name: autoexporter+version: 1.1.7+ category: Utility description: Autoexporter automatically re-exports modules.-executables:- autoexporter:- dependencies:- - base- - autoexporter- main: Main.hs- source-dirs: source/executable extra-source-files:-- CHANGELOG.markdown-- package.yaml-- README.markdown-- stack.yaml-ghc-options:-- -Wall+ - CHANGELOG.markdown+ - package.yaml+ - README.markdown+ - stack.yaml github: tfausak/autoexporter-library:- dependencies:- - base >=4.7 && <4.11- - Cabal >=1.22 && <1.25 || >=2.0 && <2.3- - directory >=1.2.5 && <1.4- - filepath >=1.3 && <1.5- source-dirs: source/library-license: MIT license-file: LICENSE.markdown+license: MIT maintainer: Taylor Fausak-name: autoexporter synopsis: Automatically re-export modules.-version: '1.1.4'++dependencies:+ base: '>= 4.9.0 && < 4.12'+ Cabal: '>= 1.24.0 && < 1.25 || >= 2.0.1 && < 2.3'+ directory: '>= 1.2.6 && < 1.4'+ filepath: '>= 1.4.1 && < 1.5'+ghc-options:+ - -Weverything+ - -Wno-implicit-prelude+ - -Wno-safe+ - -Wno-unsafe++library:+ source-dirs: library++executable:+ dependencies:+ autoexporter: -any+ main: Main.hs+ source-dirs: executables
− source/executable/Main.hs
@@ -1,5 +0,0 @@-module Main- ( module Autoexporter- ) where--import Autoexporter (main)
− source/library/Autoexporter.hs
@@ -1,105 +0,0 @@--- | This package isn't really meant to be used as a library. It's typically--- used as a GHC preprocessor, like so:------ > {-# OPTIONS_GHC -F -pgmF autoexporter #-}------ For more information, please see the README on GitHub:--- <https://github.com/tfausak/autoexporter#readme>.-module Autoexporter where--import qualified Data.List as List-import qualified Data.Maybe as Maybe-import qualified Data.Traversable as Traversable-import qualified Distribution.ModuleName as ModuleName-import qualified Distribution.Text as Text-import qualified System.Directory as Directory-import qualified System.Environment as Environment-import qualified System.FilePath as FilePath--data ExportScope = ExportScopeShallow- | ExportScopeDeep--main :: IO ()-main = do- args <- Environment.getArgs- mainWithArgs args--mainWithArgs :: [String] -> IO ()-mainWithArgs args =- case args of- [name, inputFile, outputFile, "--deep"] ->- autoexport ExportScopeDeep name inputFile outputFile- [name, inputFile, outputFile] ->- autoexport ExportScopeShallow name inputFile outputFile- _ -> fail ("unexpected arguments: " ++ show args)--autoexport :: ExportScope -> String -> FilePath -> FilePath -> IO ()-autoexport exportScope name inputFile outputFile = do- let moduleName = makeModuleName name- let directory = FilePath.dropExtension inputFile- files <- findFiles exportScope directory- let output = makeOutput moduleName directory files- writeFile outputFile output--findFiles :: ExportScope -> FilePath -> IO [FilePath]-findFiles exportScope dir =- case exportScope of- ExportScopeShallow ->- fmap (filter isHaskellFile) (Directory.listDirectory dir)- ExportScopeDeep ->- findFilesDeep dir--findFilesDeep :: FilePath -> IO [FilePath]-findFilesDeep dir = do- rootItems <- Directory.listDirectory dir- childItems <- Traversable.for rootItems $ \item -> do- let path = dir FilePath.</> item- dirExists <- Directory.doesDirectoryExist path- if dirExists- then fmap (fmap (item FilePath.</>)) (findFilesDeep path)- else pure []- pure $ mconcat (filter isHaskellFile rootItems : childItems)--makeModuleName :: FilePath -> String-makeModuleName name =- let path = FilePath.dropExtension name- parts = FilePath.splitDirectories path- rest = takeWhileEnd isModuleName parts- in List.intercalate "." rest--takeWhileEnd :: (a -> Bool) -> [a] -> [a]-takeWhileEnd p xs = reverse (takeWhile p (reverse xs))--isModuleName :: String -> Bool-isModuleName x = Maybe.isJust (parseModuleName x)--parseModuleName :: String -> Maybe ModuleName.ModuleName-parseModuleName = Text.simpleParse--makeOutput :: String -> FilePath -> [FilePath] -> String-makeOutput moduleName directory files =- let haskellFiles = filter isHaskellFile files- paths = map (directory FilePath.</>) haskellFiles- modules = List.sort (map makeModuleName paths)- in renderModule moduleName modules--isHaskellFile :: FilePath -> Bool-isHaskellFile x = List.isSuffixOf ".hs" x || List.isSuffixOf ".lhs" x--renderModule :: String -> [String] -> String-renderModule name modules =- unlines'- [ unwords ["module", name, "("]- , unlines' (map renderExport modules)- , ") where"- , unlines' (map renderImport modules)- ]--unlines' :: [String] -> String-unlines' = List.intercalate "\n"--renderExport :: String -> String-renderExport x = " module " ++ x ++ ","--renderImport :: String -> String-renderImport x = "import " ++ x
stack.yaml view
@@ -1,1 +1,1 @@-resolver: lts-10.0+resolver: lts-11.0