2020-05-01 03:48:32 +03:00
|
|
|
{-# LANGUAGE MultiWayIf #-}
|
|
|
|
|
2020-04-24 03:48:49 +03:00
|
|
|
module Main where
|
|
|
|
|
2020-05-01 03:48:32 +03:00
|
|
|
import Control.Monad
|
2020-05-12 23:11:36 +03:00
|
|
|
import Control.Monad.Trans.Maybe
|
2020-04-25 07:28:20 +03:00
|
|
|
import Data.Attoparsec.Text
|
2020-05-09 06:05:54 +03:00
|
|
|
import Data.List
|
|
|
|
import Data.Maybe
|
2020-05-01 03:48:32 +03:00
|
|
|
import qualified Data.Text as T
|
2020-04-25 07:28:20 +03:00
|
|
|
import qualified Data.Text.IO as T
|
2020-05-01 02:35:00 +03:00
|
|
|
import Hie.Cabal.Parser
|
2020-05-09 09:10:48 +03:00
|
|
|
import Hie.Locate
|
2020-05-12 23:11:36 +03:00
|
|
|
import Hie.Yaml
|
2020-05-01 03:48:32 +03:00
|
|
|
import System.Directory
|
2020-05-02 03:28:14 +03:00
|
|
|
import System.Directory.Internal
|
2020-05-01 03:48:32 +03:00
|
|
|
import System.FilePath.Posix
|
2020-04-24 03:48:49 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2020-04-25 07:28:20 +03:00
|
|
|
main = do
|
2020-05-02 03:28:14 +03:00
|
|
|
pwd <- getCurrentDirectory
|
|
|
|
files <- listDirectory pwd
|
2020-05-09 08:26:07 +03:00
|
|
|
let name =
|
|
|
|
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal"
|
|
|
|
| any ((".stack-work" ==) . takeFileName) files -> "stack"
|
2020-05-13 03:29:25 +03:00
|
|
|
| any (("cabal.project" ==) . takeFileName) files -> "cabal"
|
2020-05-09 08:26:07 +03:00
|
|
|
| any (("stack.yaml" ==) . takeFileName) files -> "stack"
|
|
|
|
| otherwise -> "cabal"
|
2020-05-12 23:11:36 +03:00
|
|
|
cfs <- runMaybeT $ case name of
|
|
|
|
"cabal" -> cabalPkgs pwd
|
|
|
|
_ -> stackYamlPkgs pwd
|
2020-05-02 03:28:14 +03:00
|
|
|
when (null cfs) $ error $
|
|
|
|
"No .cabal files found under"
|
|
|
|
<> pwd
|
|
|
|
<> "\n You may need to run stack build."
|
2020-05-12 23:11:36 +03:00
|
|
|
pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs)
|
2020-05-09 08:26:07 +03:00
|
|
|
putStr <$> hieYaml name $ fmtPkgs name pkgs
|