Skip to content

Commit

Permalink
feat(dinghy): add ability to write dinghyfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dogonthehorizon committed Jul 19, 2021
1 parent 9b59de2 commit de24f3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 6 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ extra-source-files:

dependencies:
- base >= 4.7 && < 5
- text
- yaml
- aeson
- aeson-pretty
- bytestring
- directory
- unordered-containers
- filepath
- hashable
- optparse-applicative
- text
- unordered-containers
- yaml

ghc-options:
- -Wall
Expand Down
14 changes: 14 additions & 0 deletions src/Dinghy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ Stability : experimental

module Dinghy where

import qualified Data.Text as T
import qualified Data.Aeson.Encode.Pretty as Json
import Data.Aeson (ToJSON (toEncoding), Value, defaultOptions,
fieldLabelModifier, genericToEncoding,
omitNothingFields)
import Data.Text (Text)
import Dinghy.Application
import GHC.Generics (Generic)
import qualified System.Directory as Dir
import System.FilePath.Posix ((</>))
import qualified Data.ByteString.Lazy as BS

-- | Subset of the Dinghyfile spec.
--
Expand All @@ -32,6 +37,15 @@ data Dinghyfile = Dinghyfile {
instance ToJSON Dinghyfile where
toEncoding = genericToEncoding $ defaultOptions { omitNothingFields = True }

writeDinghyfile :: Text -> Dinghyfile -> IO ()
writeDinghyfile outputPath dinghyfile = do
_ <- Dir.createDirectory dir
BS.writeFile fname $ Json.encodePretty dinghyfile
where
name = T.unpack $ application dinghyfile
dir = (T.unpack outputPath) </> name
fname = dir </> "Dinghyfile"

-- | Subset of a Pipeline representation in Dinghy.
--
-- TODO
Expand Down
8 changes: 5 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ module Main where
import Cli (Command (..), inputPath, outputPath)
import qualified Cli
import Control.Monad (join)
import Data.Foldable (traverse_)
import qualified Data.Text as T
import qualified Migrate
import Pacrd
import qualified Dinghy
import qualified System.Directory as Dir
import Wrapper

main :: IO ()
main = do
-- TODO consider adding logging here
Command { inputPath, outputPath } <- Cli.parseCli
files <- filter isYamlFile <$> Dir.listDirectory (T.unpack inputPath)
manifests <- join <$> mapM readManifest files
let (apps, pipes) = splitWrapper manifests
print . Migrate.convertPacrdTree $ pacrdTree apps pipes
-- TODO
putStrLn $ "Writing Dinghyfile to ... '" <> T.unpack outputPath <> "'"
(flip traverse_) (Migrate.convertPacrdTree $ pacrdTree apps pipes) $ \d ->
Dinghy.writeDinghyfile outputPath d

0 comments on commit de24f3d

Please sign in to comment.