mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-09-11 09:05:25 +03:00
Generate stack and cabal hie.yamls
This commit is contained in:
parent
48fda59602
commit
f5706f0eca
@ -2,7 +2,8 @@ module Main where
|
||||
|
||||
import Data.Attoparsec.Text
|
||||
import qualified Data.Text.IO as T
|
||||
import Lib
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import System.Environment
|
||||
|
||||
main :: IO ()
|
||||
@ -10,5 +11,7 @@ main = do
|
||||
args <- getArgs
|
||||
file <- T.readFile $ head args
|
||||
case parseOnly parseSec file of
|
||||
Right r -> print r
|
||||
Right r -> do
|
||||
T.putStr $ cabalHieYaml r
|
||||
T.putStr $ stackHieYaml r
|
||||
_ -> error "Could not parse *.cabal file"
|
||||
|
@ -4,7 +4,7 @@ cabal-version: 1.12
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: 43f070b60e4bc798c52d79691e2dcdd543171eeee553cd2f28579bf9e3b6e10a
|
||||
-- hash: bc348cef928e75313b689d7626632633e11398ad278358aea4933e83a9564985
|
||||
|
||||
name: implicit-hie
|
||||
version: 0.1.0.0
|
||||
@ -27,7 +27,8 @@ source-repository head
|
||||
|
||||
library
|
||||
exposed-modules:
|
||||
Lib
|
||||
Hie.Cabal.Parser
|
||||
Hie.Yaml
|
||||
other-modules:
|
||||
Paths_implicit_hie
|
||||
hs-source-dirs:
|
||||
@ -37,6 +38,7 @@ library
|
||||
attoparsec
|
||||
, base >=4.7 && <5
|
||||
, text
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
||||
executable implicit-hie-exe
|
||||
@ -51,6 +53,7 @@ executable implicit-hie-exe
|
||||
, base >=4.7 && <5
|
||||
, implicit-hie
|
||||
, text
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite implicit-hie-test
|
||||
@ -68,4 +71,5 @@ test-suite implicit-hie-test
|
||||
, hspec-attoparsec
|
||||
, implicit-hie
|
||||
, text
|
||||
, yaml
|
||||
default-language: Haskell2010
|
||||
|
@ -23,6 +23,7 @@ dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- text
|
||||
- attoparsec
|
||||
- yaml
|
||||
|
||||
ghc-options:
|
||||
# - -O2
|
||||
|
@ -1,6 +1,6 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Lib where
|
||||
module Hie.Cabal.Parser where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
44
src/Hie/Yaml.hs
Normal file
44
src/Hie/Yaml.hs
Normal file
@ -0,0 +1,44 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Hie.Yaml
|
||||
( cabalHieYaml,
|
||||
stackHieYaml,
|
||||
)
|
||||
where
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Hie.Cabal.Parser
|
||||
|
||||
cabalHieYaml :: Package -> T.Text
|
||||
cabalHieYaml (Package n cs) =
|
||||
"cradle:\n"
|
||||
<> indentT ("cabal:\n" <> indentT (T.unlines (map (cabalComponent n) cs)))
|
||||
|
||||
stackHieYaml :: Package -> T.Text
|
||||
stackHieYaml (Package n cs) =
|
||||
"cradle:\n"
|
||||
<> indentT ("stack:\n" <> indentT (T.unlines (map (stackComponent n) cs)))
|
||||
|
||||
indentT :: T.Text -> T.Text
|
||||
indentT = T.unlines . map (" " <>) . T.lines
|
||||
|
||||
cabalComponent :: Name -> Component -> T.Text
|
||||
cabalComponent n (Lib p) = component p $ "lib:" <> n
|
||||
cabalComponent _ (Exe p cn) = component p $ "exe:" <> cn
|
||||
cabalComponent _ (Test p cn) = component p $ "test:" <> cn
|
||||
|
||||
stackComponent :: Name -> Component -> T.Text
|
||||
stackComponent n (Lib p) = component p $ n <> ":lib"
|
||||
stackComponent n (Exe p cn) = component p $ n <> ":exe:" <> cn
|
||||
stackComponent n (Test p cn) = component p $ n <> ":test:" <> cn
|
||||
|
||||
component :: T.Text -> T.Text -> T.Text
|
||||
component p c =
|
||||
"- path: "
|
||||
<> dQuote p
|
||||
<> "\n "
|
||||
<> "component: "
|
||||
<> dQuote c
|
||||
|
||||
dQuote :: T.Text -> T.Text
|
||||
dQuote t = T.cons '"' t `T.snoc` '"'
|
@ -2,7 +2,7 @@
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
import Lib
|
||||
import Hie.Cabal.Parser
|
||||
import Test.Hspec
|
||||
import Test.Hspec.Attoparsec
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user