Skip to content

Commit

Permalink
Merge pull request #61 from hqm42/master
Browse files Browse the repository at this point in the history
do not traverse ignored directories
  • Loading branch information
aviaviavi authored Jan 28, 2019
2 parents 3326c80 + ba7f358 commit 3f95f9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ library:
- blaze-html ==0.9.1.1
- cmdargs ==0.10.20
- directory ==1.3.1.5
- extra ==1.6.13
- megaparsec ==6.5.0
- regex-posix ==0.95.2
- servant ==0.14.1
Expand Down Expand Up @@ -83,6 +84,7 @@ executables:
- blaze-html ==0.9.1.1
- cmdargs ==0.10.20
- directory ==1.3.1.5
- extra ==1.6.13
- megaparsec ==6.5.0
- regex-posix ==0.95.2
- servant ==0.14.1
Expand Down Expand Up @@ -114,6 +116,7 @@ tests:
- blaze-html ==0.9.1.1
- cmdargs ==0.10.20
- directory ==1.3.1.5
- extra ==1.6.13
- megaparsec ==6.5.0
- regex-posix ==0.95.2
- servant ==0.14.1
Expand Down
26 changes: 12 additions & 14 deletions src/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import qualified Data.Text as T
import qualified Data.Yaml as Y
import Servant
import System.Directory
import System.IO.HVFS
import System.Directory.Extra
import qualified System.IO.Strict as SIO
import System.Path
import System.Path.NameManip
import Text.Blaze.Html5 (Html)
import qualified Text.Blaze.Html5 as BZ
Expand Down Expand Up @@ -319,7 +318,7 @@ getAllFiles :: ToodlesConfig -> FilePath -> IO [SourceFile]
getAllFiles (ToodlesConfig ignoredPaths _) basePath =
E.catch
(do putStrLn $ printf "Running toodles for path: %s" basePath
files <- recurseDir SystemFS basePath
files <- listFilesInside (return . not . ignorePath) basePath
let validFiles = filter isValidFile files
mapM
(\f ->
Expand All @@ -333,20 +332,19 @@ getAllFiles (ToodlesConfig ignoredPaths _) basePath =

where

isValidFile :: FilePath -> Bool
isValidFile path = fileHasValidExtension && not ignoreFile
ignorePath :: FilePath -> Bool
ignorePath path =
let p = T.pack path
in T.isInfixOf "node_modules" p || T.isSuffixOf "pb.go" p ||
T.isSuffixOf "_pb2.py" p ||
any (\r -> path =~ r :: Bool) ignoredPaths

where
fileHasValidExtension :: FilePath -> Bool
fileHasValidExtension path = any (\ext -> ext `T.isSuffixOf` T.pack path) (map extension fileTypeToComment)

fileHasValidExtension :: Bool
fileHasValidExtension = any (\ext -> ext `T.isSuffixOf` T.pack path) (map extension fileTypeToComment)
isValidFile :: FilePath -> Bool
isValidFile path = (not $ ignorePath path) && fileHasValidExtension path

ignoreFile :: Bool
ignoreFile =
let p = T.pack path
in T.isInfixOf "node_modules" p || T.isSuffixOf "pb.go" p ||
T.isSuffixOf "_pb2.py" p ||
any (\r -> path =~ r :: Bool) ignoredPaths

mapHead :: (a -> a) -> [a] -> [a]
mapHead f (x:xs) = f x : xs
Expand Down
7 changes: 5 additions & 2 deletions toodles.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.0.
-- This file has been generated from package.yaml by hpack version 0.31.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: eca068224b8e938feec8b371e63c8819e81e6d2030806c1f220e08823596b7f7
-- hash: 1b4520f165439b7fb3fce7f9d4d7a56afe20ac9ae86140d2b337e14f0517cbb6

name: toodles
version: 1.0.2
Expand Down Expand Up @@ -56,6 +56,7 @@ library
, blaze-html ==0.9.1.1
, cmdargs ==0.10.20
, directory ==1.3.1.5
, extra ==1.6.13
, hspec >=2.4.4
, hspec-expectations >=0.8.2
, megaparsec ==6.5.0
Expand Down Expand Up @@ -90,6 +91,7 @@ executable toodles
, blaze-html ==0.9.1.1
, cmdargs ==0.10.20
, directory ==1.3.1.5
, extra ==1.6.13
, hspec >=2.4.4
, hspec-expectations >=0.8.2
, megaparsec ==6.5.0
Expand Down Expand Up @@ -125,6 +127,7 @@ test-suite toodles-test
, blaze-html ==0.9.1.1
, cmdargs ==0.10.20
, directory ==1.3.1.5
, extra ==1.6.13
, hspec >=2.4.4
, hspec-expectations >=0.8.2
, megaparsec ==6.5.0
Expand Down

0 comments on commit 3f95f9d

Please sign in to comment.