@@ -15,33 +15,38 @@ module Stack.New
15
15
, templatesHelp
16
16
) where
17
17
18
- import Stack.Prelude
19
18
import Control.Monad.Trans.Writer.Strict
20
19
import Data.Aeson as A
21
20
import qualified Data.Aeson.KeyMap as KeyMap
22
21
import qualified Data.ByteString.Base64 as B64
23
- import Data.ByteString.Builder (lazyByteString )
22
+ import Data.ByteString.Builder ( lazyByteString )
24
23
import qualified Data.ByteString.Lazy as LB
25
24
import Data.Conduit
26
25
import qualified Data.List as L
27
26
import qualified Data.Map.Strict as M
28
27
import qualified Data.Set as S
29
28
import qualified Data.Text as T
30
- import qualified Data.Text.Lazy as TL
31
29
import qualified Data.Text.Encoding as T
30
+ import qualified Data.Text.Lazy as TL
32
31
import qualified Data.Text.Lazy.Encoding as TLE
33
32
import Data.Time.Calendar
34
33
import Data.Time.Clock
35
- import Network.HTTP.StackClient (VerifiedDownloadException (.. ), Response (.. ), HttpException (.. ), HttpExceptionContent (.. ),
36
- getResponseBody , httpLbs , mkDownloadRequest , notFound404 , parseRequest , parseUrlThrow ,
37
- setForceDownload , setGitHubHeaders , setRequestCheckStatus , verifiedDownloadWithProgress )
34
+ import Network.HTTP.StackClient
35
+ ( HttpException (.. ), HttpExceptionContent (.. )
36
+ , Response (.. ), VerifiedDownloadException (.. )
37
+ , getResponseBody , httpLbs , mkDownloadRequest , notFound404
38
+ , parseRequest , parseUrlThrow , setForceDownload
39
+ , setGitHubHeaders , setRequestCheckStatus
40
+ , verifiedDownloadWithProgress
41
+ )
38
42
import Path
39
43
import Path.IO
44
+ import RIO.Process
40
45
import Stack.Constants
41
46
import Stack.Constants.Config
47
+ import Stack.Prelude
42
48
import Stack.Types.Config
43
49
import Stack.Types.TemplateName
44
- import RIO.Process
45
50
import qualified Text.Mustache as Mustache
46
51
import qualified Text.Mustache.Render as Mustache
47
52
import Text.ProjectTemplate
@@ -306,7 +311,8 @@ loadTemplate
306
311
loadTemplate name logIt = do
307
312
templateDir <- view $ configL. to templatesDir
308
313
case templatePath name of
309
- AbsPath absFile -> logIt LocalTemp >> loadLocalFile absFile eitherByteStringToText
314
+ AbsPath absFile ->
315
+ logIt LocalTemp >> loadLocalFile absFile eitherByteStringToText
310
316
UrlPath s -> do
311
317
let settings = asIsFromUrl s
312
318
downloadFromUrl settings templateDir
@@ -328,7 +334,9 @@ loadTemplate name logIt = do
328
334
downloadFromUrl settings templateDir
329
335
330
336
where
331
- loadLocalFile :: Path b File -> (ByteString -> Either String Text ) -> RIO env Text
337
+ loadLocalFile :: Path b File
338
+ -> (ByteString -> Either String Text )
339
+ -> RIO env Text
332
340
loadLocalFile path extract = do
333
341
logDebug (" Opening local template: \" " <> fromString (toFilePath path)
334
342
<> " \" " )
@@ -352,10 +360,15 @@ loadTemplate name logIt = do
352
360
let url = tplDownloadUrl settings
353
361
rel = fromMaybe backupUrlRelPath (parseRelFile url)
354
362
downloadTemplate url (tplExtract settings) (templateDir </> rel)
355
- downloadTemplate :: String -> (ByteString -> Either String Text ) -> Path Abs File -> RIO env Text
363
+ downloadTemplate :: String
364
+ -> (ByteString
365
+ -> Either String Text )
366
+ -> Path Abs File
367
+ -> RIO env Text
356
368
downloadTemplate url extract path = do
357
369
req <- parseRequest url
358
- let dReq = setForceDownload True $ mkDownloadRequest (setRequestCheckStatus req)
370
+ let dReq = setForceDownload True $
371
+ mkDownloadRequest (setRequestCheckStatus req)
359
372
logIt RemoteTemp
360
373
catch
361
374
(void $ do
@@ -364,7 +377,10 @@ loadTemplate name logIt = do
364
377
(useCachedVersionOrThrow url path)
365
378
366
379
loadLocalFile path extract
367
- useCachedVersionOrThrow :: String -> Path Abs File -> VerifiedDownloadException -> RIO env ()
380
+ useCachedVersionOrThrow :: String
381
+ -> Path Abs File
382
+ -> VerifiedDownloadException
383
+ -> RIO env ()
368
384
useCachedVersionOrThrow url path exception = do
369
385
exists <- doesFileExist path
370
386
@@ -396,7 +412,12 @@ settingsFromRepoTemplatePath :: RepoTemplatePath -> TemplateDownloadSettings
396
412
settingsFromRepoTemplatePath (RepoTemplatePath GitHub user name) =
397
413
-- T.concat ["https://raw.githubusercontent.com", "/", user, "/stack-templates/master/", name]
398
414
TemplateDownloadSettings
399
- { tplDownloadUrl = concat [" https://api.github.com/repos/" , T. unpack user, " /stack-templates/contents/" , T. unpack name]
415
+ { tplDownloadUrl = concat
416
+ [ " https://api.github.com/repos/"
417
+ , T. unpack user
418
+ , " /stack-templates/contents/"
419
+ , T. unpack name
420
+ ]
400
421
, tplExtract = \ bs -> do
401
422
decodedJson <- eitherDecode (LB. fromStrict bs)
402
423
case decodedJson of
@@ -409,9 +430,21 @@ settingsFromRepoTemplatePath (RepoTemplatePath GitHub user name) =
409
430
}
410
431
411
432
settingsFromRepoTemplatePath (RepoTemplatePath GitLab user name) =
412
- asIsFromUrl $ concat [" https://gitlab.com" , " /" , T. unpack user, " /stack-templates/raw/master/" , T. unpack name]
433
+ asIsFromUrl $ concat
434
+ [ " https://gitlab.com"
435
+ , " /"
436
+ , T. unpack user
437
+ , " /stack-templates/raw/master/"
438
+ , T. unpack name
439
+ ]
413
440
settingsFromRepoTemplatePath (RepoTemplatePath Bitbucket user name) =
414
- asIsFromUrl $ concat [" https://bitbucket.org" , " /" , T. unpack user, " /stack-templates/raw/master/" , T. unpack name]
441
+ asIsFromUrl $ concat
442
+ [ " https://bitbucket.org"
443
+ , " /"
444
+ , T. unpack user
445
+ , " /stack-templates/raw/master/"
446
+ , T. unpack name
447
+ ]
415
448
416
449
-- | Apply and unpack a template into a directory.
417
450
applyTemplate
@@ -431,7 +464,8 @@ applyTemplate project template nonceParams dir templateText = do
431
464
let context = M. unions [nonceParams, nameParams, configParams, yearParam]
432
465
where
433
466
nameAsVarId = T. replace " -" " _" $ T. pack $ packageNameString project
434
- nameAsModule = T. filter (/= ' ' ) $ T. toTitle $ T. replace " -" " " $ T. pack $ packageNameString project
467
+ nameAsModule = T. filter (/= ' ' ) $ T. toTitle $ T. replace " -" " " $
468
+ T. pack $ packageNameString project
435
469
nameParams = M. fromList [ (" name" , T. pack $ packageNameString project)
436
470
, (" name-as-varid" , nameAsVarId)
437
471
, (" name-as-module" , nameAsModule) ]
0 commit comments