mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-09-11 09:05:25 +03:00
it works
This commit is contained in:
parent
f5706f0eca
commit
a3c3360bbc
21
app/Main.hs
21
app/Main.hs
@ -1,17 +1,26 @@
|
||||
{-# LANGUAGE MultiWayIf #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Control.Monad
|
||||
import Data.Attoparsec.Text
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import System.Environment
|
||||
import System.Directory
|
||||
import System.FilePath.Posix
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
file <- T.readFile $ head args
|
||||
files <- listDirectory =<< getCurrentDirectory
|
||||
let path = filter ((".cabal" ==) . takeExtension) files
|
||||
sOrC =
|
||||
if | any ((".stack-work" ==) . takeFileName) files -> stackHieYaml
|
||||
| any (("dist-newstyle" ==) . takeFileName) files -> cabalHieYaml
|
||||
| otherwise -> stackHieYaml
|
||||
when (null path) $ error "No .cabal file found!\n You may need to run stack build."
|
||||
file <- T.readFile $ head path
|
||||
case parseOnly parseSec file of
|
||||
Right r -> do
|
||||
T.putStr $ cabalHieYaml r
|
||||
T.putStr $ stackHieYaml r
|
||||
Right r -> T.writeFile "hie.yaml" $ sOrC r
|
||||
_ -> error "Could not parse *.cabal file"
|
||||
|
12
hie.yaml
12
hie.yaml
@ -1,8 +1,8 @@
|
||||
cradle:
|
||||
stack:
|
||||
- path: ./src
|
||||
component: "implicit-hie:lib"
|
||||
- path: ./app
|
||||
component: "implicit-hie:exe:implicit-hie-exe"
|
||||
- path: ./test
|
||||
component: "implicit-hie:test:implicit-hie-test"
|
||||
- path: "src"
|
||||
component: "implicit-hie:lib"
|
||||
- path: "app"
|
||||
component: "implicit-hie:exe:implicit-hie-exe"
|
||||
- path: "test"
|
||||
component: "implicit-hie:test:implicit-hie-test"
|
||||
|
@ -4,7 +4,7 @@ cabal-version: 1.12
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: bc348cef928e75313b689d7626632633e11398ad278358aea4933e83a9564985
|
||||
-- hash: f941332727b491b78a5ecc8465f43d3597766e4d3363a1d76d459e4a84515b5f
|
||||
|
||||
name: implicit-hie
|
||||
version: 0.1.0.0
|
||||
@ -51,6 +51,8 @@ executable implicit-hie-exe
|
||||
build-depends:
|
||||
attoparsec
|
||||
, base >=4.7 && <5
|
||||
, directory
|
||||
, filepath
|
||||
, implicit-hie
|
||||
, text
|
||||
, yaml
|
||||
|
@ -51,6 +51,8 @@ executables:
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- implicit-hie
|
||||
- directory
|
||||
- filepath
|
||||
|
||||
tests:
|
||||
implicit-hie-test:
|
||||
|
@ -29,8 +29,8 @@ 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
|
||||
stackComponent n (Exe cn p) = component p $ n <> ":exe:" <> cn
|
||||
stackComponent n (Test cn p) = component p $ n <> ":test:" <> cn
|
||||
|
||||
component :: T.Text -> T.Text -> T.Text
|
||||
component p c =
|
||||
|
35
test/Spec.hs
35
test/Spec.hs
@ -1,8 +1,10 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import Data.Attoparsec.Text
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
import Hie.Cabal.Parser
|
||||
import Hie.Yaml
|
||||
import Test.Hspec
|
||||
import Test.Hspec.Attoparsec
|
||||
|
||||
@ -25,20 +27,25 @@ spec = do
|
||||
`shouldParse` Lib "src"
|
||||
describe "Should Succeed"
|
||||
$ it "successfully parses library section"
|
||||
$ ("name: implicit-hie\n" <> exeSection <> testSection <> libSection)
|
||||
~> parseSec
|
||||
`shouldParse` Package
|
||||
"implicit-hie"
|
||||
[ Exe "implicit-hie-exe" "app",
|
||||
Test "implicit-hie-test" "test",
|
||||
Lib "src"
|
||||
]
|
||||
$ fullFile ~> parseSec
|
||||
`shouldParse` Package
|
||||
"implicit-hie"
|
||||
[ Lib "src",
|
||||
Exe "implicit-hie-exe" "app",
|
||||
Test "implicit-hie-test" "test"
|
||||
]
|
||||
describe "Should Succeed"
|
||||
$ it
|
||||
"successfully parses library section"
|
||||
$ let r = "test\n"
|
||||
in (libSection <> r) ~?> parseLib 0
|
||||
`leavesUnconsumed` r
|
||||
describe "Should Succeed"
|
||||
$ it "successfully generates stack hie.yaml"
|
||||
$ (stackHieYaml <$> parseOnly parseSec fullFile) `shouldBe` Right stackHie
|
||||
|
||||
fullFile :: Text
|
||||
fullFile = "name: implicit-hie\n" <> libSection <> exeSection <> testSection
|
||||
|
||||
exeSection :: Text
|
||||
exeSection =
|
||||
@ -85,3 +92,15 @@ libSection =
|
||||
\ , text\n\
|
||||
\ default-language: Haskell2010\n\
|
||||
\"
|
||||
|
||||
stackHie :: Text
|
||||
stackHie =
|
||||
"cradle:\n\
|
||||
\ stack:\n\
|
||||
\ - path: \"src\"\n\
|
||||
\ component: \"implicit-hie:lib\"\n\
|
||||
\ - path: \"app\"\n\
|
||||
\ component: \"implicit-hie:exe:implicit-hie-exe\"\n\
|
||||
\ - path: \"test\"\n\
|
||||
\ component: \"implicit-hie:test:implicit-hie-test\"\n\
|
||||
\"
|
||||
|
Loading…
Reference in New Issue
Block a user