From 652c2030c5ef39bf1dd34d26064e1059431898f0 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 9 Nov 2021 20:24:17 +0100 Subject: first example of a map adjustment this also includes some more monad plumbing, and an option for the linter to actually write things out again. Some of the previous commit was reverted a bit since it turned out to be stupid, but overall it was suprisingly easy once I got around to it, so yay! i guess Also includes a fairly silly example of how to use it. --- lib/CheckDir.hs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/CheckDir.hs') diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs index d651815..4654051 100644 --- a/lib/CheckDir.hs +++ b/lib/CheckDir.hs @@ -6,17 +6,17 @@ {-# LANGUAGE TupleSections #-} -- | Module that contains high-level checking for an entire directory -module CheckDir (recursiveCheckDir) where +module CheckDir (recursiveCheckDir, writeAdjustedRepository) where -import CheckMap (MapResult (mapresultProvides), +import CheckMap (MapResult (mapresultAdjusted, mapresultProvides), loadAndLintMap, mapresultDepends) import Control.Monad (void) import Control.Monad.Extra (mapMaybeM) -import Data.Aeson (ToJSON, (.=)) +import Data.Aeson (ToJSON, encodeFile, (.=)) import qualified Data.Aeson as A import Data.Foldable (fold) import Data.Functor ((<&>)) -import Data.Map (Map) +import Data.Map (Map, toList) import qualified Data.Map as M import Data.Map.Strict (mapKeys, (\\)) import Data.Maybe (mapMaybe) @@ -43,8 +43,11 @@ listFromSet = map fst . M.toList -- | Result of linting an entire directory / repository data DirResult = DirResult { dirresultMaps :: Map FilePath MapResult + -- ^ all maps of this respository, by (local) filepath , dirresultDeps :: [MissingDep] + -- ^ all dependencies to things outside this repository , dirresultMissingAssets :: [MissingAsset] + -- ^ local things that are referred to but missing } deriving (Generic) data MissingDep = MissingDep @@ -176,10 +179,10 @@ recursiveCheckDir' prefix paths done acc = do let mapdeps = concatMap - (\(m,res) -> + (\(m,lintresult) -> let ps = mapMaybe (\case {LocalMap p -> Just p; _ -> Nothing}) - (mapresultDepends res) + (mapresultDepends lintresult) in map (FP.normalise . normalise (takeDirectory m)) ps ) lints @@ -199,3 +202,12 @@ recursiveCheckDir' prefix paths done acc = do case unknowns of [] -> pure acc' _ -> recursiveCheckDir' prefix unknowns knowns acc' + + + + +writeAdjustedRepository :: FilePath -> DirResult -> IO () +writeAdjustedRepository outPath result = + mapM_ + (\(path,out) -> encodeFile (outPath path) $ mapresultAdjusted out) + (toList $ dirresultMaps result) -- cgit v1.2.3