Skip to content

Commit cda2f05

Browse files
authored
Write add from bower to local (#93)
* read and write add-from-bower from local package set * make add-from-bower write to local package set updates lts to use newer aeson-pretty to use trailing newline formatting
1 parent bc10f2f commit cda2f05

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

app/Main.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Data.Aeson.Encode.Pretty
1717
import Data.Foldable (fold, foldMap, traverse_)
1818
import qualified Data.Bifunctor as Bifunctor
1919
import qualified Data.Graph as G
20-
import Data.List (maximumBy, nub)
20+
import Data.List (maximumBy)
2121
import qualified Data.List as List
2222
import qualified Data.Map as Map
2323
import Data.Maybe (fromMaybe, mapMaybe)
@@ -92,6 +92,7 @@ packageConfigToJSON =
9292
, "depends"
9393
]
9494
, confIndent = Spaces 2
95+
, confTrailingNewline = True
9596
}
9697

9798
packageSetToJSON :: PackageSet -> Text
@@ -100,7 +101,11 @@ packageSetToJSON =
100101
. TB.toLazyText
101102
. encodePrettyToTextBuilder' config
102103
where
103-
config = defConfig { confCompare = compare, confIndent = Spaces 2 }
104+
config = defConfig
105+
{ confCompare = compare
106+
, confIndent = Spaces 2
107+
, confTrailingNewline = True
108+
}
104109

105110
writePackageFile :: PackageConfig -> IO ()
106111
writePackageFile =
@@ -188,7 +193,7 @@ performInstall set pkgName PackageInfo{ repo, version } = do
188193

189194
getReverseDeps :: PackageSet -> PackageName -> IO [(PackageName, PackageInfo)]
190195
getReverseDeps db dep =
191-
nub <$> foldMap go (Map.toList db)
196+
List.nub <$> foldMap go (Map.toList db)
192197
where
193198
go pair@(packageName, PackageInfo {dependencies}) =
194199
case List.find (== dep) dependencies of
@@ -270,7 +275,7 @@ install pkgName' = do
270275
echoT "Install complete"
271276
Just str -> do
272277
pkgName <- packageNameFromString str
273-
let pkg' = pkg { depends = nub (pkgName : depends pkg) }
278+
let pkg' = pkg { depends = List.nub (pkgName : depends pkg) }
274279
updateAndWritePackageFile pkg'
275280

276281
uninstall :: String -> IO ()
@@ -522,9 +527,8 @@ addFromBower name = do
522527
)
523528
case result' of
524529
Right (pkgName, info) -> do
525-
pkg <- readPackageFile
526-
db <- readPackageSet pkg
527-
writePackageSet pkg $ Map.insert pkgName info db
530+
db <- readLocalPackageSet
531+
writeLocalPackageSet $ Map.insert pkgName info db
528532
echoT $ "Successfully wrote " <> runPackageName pkgName <> " to package set."
529533
Left errors -> echoT $ "Errors processing Bower Info: " <> (T.pack errors)
530534
where

psc-package.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ executable psc-package
2525
process -any,
2626
system-filepath -any,
2727
text -any,
28-
turtle ==1.3.*
28+
turtle <1.6
2929
main-is: Main.hs
3030
other-modules: Paths_psc_package
3131
Types

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-8.15
1+
resolver: lts-11.1
22
packages:
33
- '.'
44
extra-deps: []

0 commit comments

Comments
 (0)