2018-06-08 19:41:07 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
2018-05-16 18:38:00 +03:00
|
|
|
module Data.Project where
|
2018-04-20 21:10:27 +03:00
|
|
|
|
2018-06-08 19:41:07 +03:00
|
|
|
import Data.Blob
|
2018-05-31 01:04:10 +03:00
|
|
|
import Data.Language
|
2018-06-08 19:41:07 +03:00
|
|
|
import qualified Data.Text as T
|
2018-05-31 01:04:10 +03:00
|
|
|
import Prologue
|
2018-06-08 19:41:07 +03:00
|
|
|
import Proto3.Suite
|
2018-05-31 01:04:10 +03:00
|
|
|
import System.FilePath.Posix
|
2018-04-20 21:10:27 +03:00
|
|
|
|
2018-06-08 19:41:07 +03:00
|
|
|
data Project blobs paths path = Project
|
|
|
|
{ projectRootDir :: path
|
|
|
|
, projectBlobs :: blobs Blob
|
2018-05-31 01:04:10 +03:00
|
|
|
, projectLanguage :: Language
|
2018-06-08 19:41:07 +03:00
|
|
|
, projectEntryPaths :: paths path
|
|
|
|
, projectExcludeDirs :: paths path
|
|
|
|
} deriving (Functor, Generic, Named)
|
2018-04-20 23:30:17 +03:00
|
|
|
|
2018-06-08 19:41:07 +03:00
|
|
|
deriving instance ( MessageField path
|
|
|
|
, MessageField (paths path)
|
|
|
|
, MessageField (blobs Blob)
|
|
|
|
) => Message (Project blobs paths path)
|
|
|
|
|
|
|
|
deriving instance (Eq path, Eq (blobs Blob), Eq (paths path)) => Eq (Project blobs paths path)
|
|
|
|
deriving instance (Show path, Show (blobs Blob), Show (paths path)) => Show (Project blobs paths path)
|
|
|
|
|
|
|
|
type Concrete = Project [] [] FilePath
|
|
|
|
type PB = Project NestedVec UnpackedVec Text
|
|
|
|
|
|
|
|
fromPB :: PB -> Concrete
|
|
|
|
fromPB Project {..} = Project
|
|
|
|
{ projectRootDir = T.unpack projectRootDir
|
|
|
|
, projectBlobs = go projectBlobs
|
|
|
|
, projectLanguage = projectLanguage
|
|
|
|
, projectEntryPaths = T.unpack <$> go projectEntryPaths
|
|
|
|
, projectExcludeDirs = T.unpack <$> go projectExcludeDirs
|
|
|
|
} where go :: Foldable f => f a -> [a]
|
|
|
|
go = foldr (:) []
|
|
|
|
|
|
|
|
projectName :: Concrete -> Text
|
2018-05-31 01:04:10 +03:00
|
|
|
projectName = T.pack . dropExtensions . takeFileName . projectRootDir
|
2018-04-20 23:30:17 +03:00
|
|
|
|
2018-06-08 19:41:07 +03:00
|
|
|
projectExtensions :: Concrete -> [String]
|
2018-04-20 23:30:17 +03:00
|
|
|
projectExtensions = extensionsForLanguage . projectLanguage
|
2018-05-16 18:38:00 +03:00
|
|
|
|
2018-06-08 19:41:07 +03:00
|
|
|
projectEntryPoints :: Concrete -> [File]
|
|
|
|
projectEntryPoints (Project {..})= foldr go [] projectBlobs
|
|
|
|
where go b acc =
|
|
|
|
if blobPath b `elem` projectEntryPaths
|
|
|
|
then toFile b : acc
|
|
|
|
else acc
|
|
|
|
|
|
|
|
projectFiles :: Concrete -> [File]
|
|
|
|
projectFiles = fmap toFile . projectBlobs where
|
|
|
|
|
2018-05-16 18:38:00 +03:00
|
|
|
|
|
|
|
data File = File
|
2018-06-04 21:25:17 +03:00
|
|
|
{ filePath :: FilePath
|
|
|
|
, fileLanguage :: Language
|
2018-06-05 01:33:03 +03:00
|
|
|
} deriving (Eq, Ord, Show)
|
2018-05-16 18:38:00 +03:00
|
|
|
|
|
|
|
file :: FilePath -> File
|
|
|
|
file path = File path (languageForFilePath path)
|
|
|
|
where languageForFilePath = languageForType . takeExtension
|
2018-06-08 19:41:07 +03:00
|
|
|
|
|
|
|
toFile :: Blob -> File
|
|
|
|
toFile (Blob _ p l) = File p l
|