Adds WIP Tailwind and Auth recipes

This commit is contained in:
Mihovil Ilakovac 2023-09-25 12:40:52 +02:00
parent 3e95782821
commit e58f4ecacc
4 changed files with 89 additions and 18 deletions

View File

@ -22,23 +22,24 @@ instance Interactive.Option Recipe where
useRecipe :: [String] -> Command ()
useRecipe _args = do
InWaspProject _waspProjectDir <- require
InWaspProject waspProjectDir <- require
recipe <- liftIO selectRecipe
let recipes =
[ Recipe
{ recipeName = "tailwind",
execute = useTailwind waspProjectDir
},
Recipe
{ recipeName = "auth",
execute = useAuth
}
]
recipe <- liftIO $ selectRecipe recipes
execute recipe
where
recipes =
[ Recipe
{ recipeName = "tailwind",
execute = useTailwind
},
Recipe
{ recipeName = "auth",
execute = useAuth
}
]
selectRecipe =
selectRecipe recipes =
Interactive.askToChoose
"What do you want to use?"
(fromList recipes)

View File

@ -0,0 +1,32 @@
module Wasp.Cli.Command.UseRecipe.Common where
import Control.Monad (unless)
import StrongPath (Abs, Dir, File, Path', Rel, reldir, toFilePath, (</>))
import System.Directory (copyFile, createDirectoryIfMissing, doesFileExist)
import System.FilePath (takeDirectory)
import qualified Wasp.Data
data RecipesDir
-- | Path where the recipes are stored in the data dir.
recipesDirPathInDataDir :: Path' (Rel Wasp.Data.DataDir) (Dir RecipesDir)
recipesDirPathInDataDir = [reldir|Cli/recipes|]
getRecipesDir :: IO (Path' Abs (Dir RecipesDir))
getRecipesDir = (</> recipesDirPathInDataDir) <$> Wasp.Data.getAbsDataDirPath
copyFileIfDoesNotExist ::
Path' (Rel RecipesDir) (File f) ->
Path' Abs (File f) ->
IO ()
copyFileIfDoesNotExist pathInRecipesDir pathInProjectDir = do
recipesDir <- getRecipesDir
let pathInProjectDirStr = toFilePath pathInProjectDir
let pathInRecipesDirStr = toFilePath $ recipesDir </> pathInRecipesDir
-- _ <- error $ "Copying " <> pathInRecipesDirStr <> " to " <> pathInProjectDirStr
isExistingFile <- doesFileExist pathInProjectDirStr
unless isExistingFile $ do
createDirectoryIfMissing True $ takeDirectory pathInProjectDirStr
copyFile pathInRecipesDirStr pathInProjectDirStr

View File

@ -1,13 +1,50 @@
module Wasp.Cli.Command.UseRecipe.Tailwind where
import Control.Monad.Cont (MonadIO (liftIO))
import StrongPath
( Abs,
Dir,
Path',
Rel,
reldir,
relfile,
(</>),
)
import Wasp.Cli.Command (Command)
import Wasp.Cli.Command.Message (cliSendMessageC)
import Wasp.Cli.Command.UseRecipe.Common
( RecipesDir,
copyFileIfDoesNotExist,
)
import Wasp.Cli.Common (WaspProjectDir)
import qualified Wasp.Message as Msg
useTailwind :: Command ()
useTailwind = do
cliSendMessageC $ Msg.Start "Installing Tailwind..."
data TailwindDir
-- TODO: copy the config files from the Cli/recipes/tailwind folder to the project dir.
tailwindDirInRecipesDir :: Path' (Rel RecipesDir) (Dir TailwindDir)
tailwindDirInRecipesDir = [reldir|tailwind|]
cliSendMessageC $ Msg.Success "Installed tailwind!"
useTailwind :: Path' Abs (Dir WaspProjectDir) -> Command ()
useTailwind waspProjectDir = do
cliSendMessageC $ Msg.Start "Setting up Tailwind config files..."
liftIO $ do
copyFileIfDoesNotExist (tailwindDirInRecipesDir </> tailwindConfigPath) (tailwindTargetDir </> tailwindConfigPath)
copyFileIfDoesNotExist (tailwindDirInRecipesDir </> postcssConfigPath) (tailwindTargetDir </> postcssConfigPath)
cliSendMessageC $
Msg.Info $
unlines
[ "Make sure the following to your Main.css file:",
"",
"@tailwind base;",
"@tailwind components;",
"@tailwind utilities;",
"",
"You can now use Tailwind classes in your CSS files."
]
where
tailwindTargetDir = waspProjectDir
tailwindConfigPath = [relfile|tailwind.config.cjs|]
postcssConfigPath = [relfile|postcss.config.cjs|]

View File

@ -479,6 +479,7 @@ library cli-lib
Wasp.Cli.Command.UseRecipe
Wasp.Cli.Command.UseRecipe.Auth
Wasp.Cli.Command.UseRecipe.Tailwind
Wasp.Cli.Command.UseRecipe.Common
Wasp.Cli.Common
Wasp.Cli.Terminal
Wasp.Cli.Command.Message