mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-11-26 11:25:24 +03:00
support multi package cabal projects
This commit is contained in:
parent
53996020b6
commit
ea43db6bc6
@ -1,5 +1,5 @@
|
||||
# implicit-hie
|
||||
```bash
|
||||
cd your-stack-or-cabal-package
|
||||
gen-hie > hie.yaml
|
||||
gen-hie
|
||||
```
|
||||
|
41
app/Main.hs
41
app/Main.hs
@ -9,19 +9,44 @@ import qualified Data.Text.IO as T
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import System.Directory
|
||||
import System.Directory.Internal
|
||||
import System.FilePath.Posix
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
files <- listDirectory =<< getCurrentDirectory
|
||||
let path = filter ((".cabal" ==) . takeExtension) files
|
||||
sOrC =
|
||||
pwd <- getCurrentDirectory
|
||||
files <- listDirectory pwd
|
||||
cfs <- cabalFiles pwd
|
||||
let sOrC =
|
||||
if | any ((".stack-work" ==) . takeFileName) files -> stackHieYaml
|
||||
| any (("dist-newstyle" ==) . takeFileName) files -> cabalHieYaml
|
||||
| any (("stack.yaml" ==) . takeFileName) files -> stackHieYaml
|
||||
| otherwise -> cabalHieYaml
|
||||
when (null path) $ error "No .cabal file found!\n You may need to run stack build."
|
||||
file <- T.readFile $ head path
|
||||
case parseOnly parsePackage file of
|
||||
Right r -> T.putStr $ sOrC r
|
||||
_ -> error "Could not parse *.cabal file"
|
||||
gen f = do
|
||||
f' <- T.readFile f
|
||||
case parseOnly parsePackage f' of
|
||||
Right r -> do
|
||||
let hiePath = fst (splitFileName f) </> "hie.yaml"
|
||||
T.writeFile hiePath $ sOrC r
|
||||
pure ("wrote " <> hiePath)
|
||||
_ -> pure $ "Could not parse " <> f
|
||||
when (null cfs) $ error $
|
||||
"No .cabal files found under"
|
||||
<> pwd
|
||||
<> "\n You may need to run stack build."
|
||||
mapM_ (putStrLn <=< gen) cfs
|
||||
|
||||
cabalFiles :: FilePath -> IO [FilePath]
|
||||
cabalFiles f = do
|
||||
fs <- listDirectory f
|
||||
case filter ((".cabal" ==) . takeExtension) fs of
|
||||
h : _ -> pure [f </> h]
|
||||
_ ->
|
||||
fmap concat . mapM cabalFiles
|
||||
=<< filterM
|
||||
(fmap (fileTypeIsDirectory . fileTypeFromMetadata) . getFileMetadata)
|
||||
( map (f </>) $
|
||||
filter
|
||||
(`notElem` [".git", "dist", "dist-newstyle", ".stack-work"])
|
||||
fs
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user