never executed always true always false
1 module CommandLine.Filesystem where
2
3 import CommandLine.World
4 import System.FilePath ((</>))
5 import qualified System.FilePath as FilePath
6
7
8 collectFiles :: Monad m => (a -> m [a]) -> a -> m [a]
9 collectFiles children root =
10 do
11 xs <- children root
12 subChildren <- mapM (collectFiles children) xs
13 return $ root : concat subChildren
14
15
16 listDir :: World m => FilePath -> m [FilePath]
17 listDir path =
18 map (path </>) <$> listDirectory path
19
20
21 fileList :: World m => FilePath -> m [FilePath]
22 fileList =
23 let
24 children path =
25 if isSkippable path then
26 return []
27 else
28 do
29 directory <- doesDirectoryExist path
30 if directory then listDir path else return []
31 in
32 collectFiles children
33
34
35 isSkippable :: FilePath -> Bool
36 isSkippable path =
37 or
38 [ hasFilename "elm-stuff" path
39 , hasFilename "node_modules" path
40 , hasFilename ".git" path
41 ]
42
43 hasExtension :: String -> FilePath -> Bool
44 hasExtension ext path =
45 ext == FilePath.takeExtension path
46
47
48 findAllElmFiles :: World m => FilePath -> m [FilePath]
49 findAllElmFiles inputFile =
50 filter (hasExtension ".elm") <$> fileList inputFile
51
52
53 hasFilename :: String -> FilePath -> Bool
54 hasFilename name path =
55 name == FilePath.takeFileName path