forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.hs
More file actions
41 lines (33 loc) · 1.28 KB
/
Utils.hs
File metadata and controls
41 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Language.PureScript.Publish.Utils where
import Prelude.Compat
import Data.Either (partitionEithers)
import Data.List
import System.Directory
import System.Exit (exitFailure)
import System.FilePath (pathSeparator)
import System.IO (hPutStrLn, stderr)
import qualified System.FilePath.Glob as Glob
-- | Glob relative to the current directory, and produce relative pathnames.
globRelative :: Glob.Pattern -> IO [FilePath]
globRelative pat = do
currentDir <- getCurrentDirectory
filesAbsolute <- Glob.globDir1 pat currentDir
let prefix = currentDir ++ [pathSeparator]
let (fails, paths) = partitionEithers . map (stripPrefix' prefix) $ filesAbsolute
if null fails
then return paths
else do
let p = hPutStrLn stderr
p "Internal error in Language.PureScript.Publish.Utils.globRelative"
p "Unmatched files:"
mapM_ p fails
exitFailure
where
stripPrefix' prefix dir =
maybe (Left dir) Right $ stripPrefix prefix dir
-- | Glob pattern for PureScript source files.
purescriptSourceFiles :: Glob.Pattern
purescriptSourceFiles = Glob.compile "src/**/*.purs"
-- | Glob pattern for PureScript dependency files.
purescriptDepsFiles :: Glob.Pattern
purescriptDepsFiles = Glob.compile "bower_components/*/src/**/*.purs"