Fix add-handler for new routes file path
https://github.com/yesodweb/yesod/pull/1686 recommended `.yesodroutes` as the file extension for the routes file, and https://github.com/yesodweb/yesod-scaffold/pull/203 added that to the scaffolding. But yesod-bin assumes the file is just named `routes`. This PR will check if the old path exists and use that, and if not use the new path. I tested this on the yesod-scaffold repo with both the old and new filename
This commit is contained in:
parent
77e6c3e7c2
commit
7cfda1d650
@ -84,13 +84,22 @@ addHandlerInteractive = do
|
|||||||
methods <- getLine
|
methods <- getLine
|
||||||
addHandlerFiles cabal routePair pattern methods
|
addHandlerFiles cabal routePair pattern methods
|
||||||
|
|
||||||
|
getRoutesFilePath :: IO FilePath
|
||||||
|
getRoutesFilePath = do
|
||||||
|
let oldPath = "config/routes"
|
||||||
|
oldExists <- doesFileExist oldPath
|
||||||
|
pure $ if oldExists
|
||||||
|
then oldPath
|
||||||
|
else "config/routes.yesodroutes"
|
||||||
|
|
||||||
addHandlerFiles :: FilePath -> (String, FilePath) -> String -> String -> IO ()
|
addHandlerFiles :: FilePath -> (String, FilePath) -> String -> String -> IO ()
|
||||||
addHandlerFiles cabal (name, handlerFile) pattern methods = do
|
addHandlerFiles cabal (name, handlerFile) pattern methods = do
|
||||||
src <- getSrcDir cabal
|
src <- getSrcDir cabal
|
||||||
let applicationFile = concat [src, "/Application.hs"]
|
let applicationFile = concat [src, "/Application.hs"]
|
||||||
modify applicationFile $ fixApp name
|
modify applicationFile $ fixApp name
|
||||||
modify cabal $ fixCabal name
|
modify cabal $ fixCabal name
|
||||||
modify "config/routes" $ fixRoutes name pattern methods
|
routesPath <- getRoutesFilePath
|
||||||
|
modify routesPath $ fixRoutes name pattern methods
|
||||||
writeFile handlerFile $ mkHandler name pattern methods
|
writeFile handlerFile $ mkHandler name pattern methods
|
||||||
specExists <- doesFileExist specFile
|
specExists <- doesFileExist specFile
|
||||||
unless specExists $
|
unless specExists $
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user