foliage/app/Foliage/Package.hs
Andrea Bedini 080197e9e2
Big rewrite
1. Foliage takes as input a complete description of the index, where
   source distributions and revisions come with a timestamp. This allows
   us to recreate the entire index in a reproducible way.

2. Added a experimental command to import an index from a Hackage (as
   downloaded with Cabal). This was originally a testing/development
   need but there might be different use cases.
2022-03-28 17:18:27 +08:00

38 lines
1.0 KiB
Haskell

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
module Foliage.Package
( PackageId (..),
parsePkgId,
pkgIdToTarGzName,
pkgIdToString,
pkgIdToHackageUrl,
)
where
import Data.Bifunctor
import Data.Tuple
import Development.Shake.Classes
import GHC.Generics
import System.FilePath
data PackageId = PackageId {pkgName :: String, pkgVersion :: String}
deriving (Eq, Ord, Show, Generic)
deriving anyclass (Binary, NFData, Hashable)
parsePkgId :: String -> PackageId
parsePkgId fn = PackageId (init pn) pv
where
(pn, pv) = swap $ bimap reverse reverse $ break (== '-') $ reverse fn
pkgIdToTarGzName :: PackageId -> FilePath
pkgIdToTarGzName pkgId = pkgIdToString pkgId <.> "tar.gz"
pkgIdToString :: PackageId -> String
pkgIdToString (PackageId name version) = name <> "-" <> version
pkgIdToHackageUrl :: PackageId -> String
pkgIdToHackageUrl pkgId =
"https://hackage.haskell.org/package" </> pkgIdToString pkgId </> pkgIdToString pkgId <.> "tar.gz"