Skip to content
Snippets Groups Projects
Commit 64d2cd05 authored by Eduardo Trujillo's avatar Eduardo Trujillo
Browse files

feat(Server): Add exterimental web server

parent 89e5d59e
No related branches found
No related tags found
Loading
...@@ -21,6 +21,7 @@ library ...@@ -21,6 +21,7 @@ library
, Shift.Parsers , Shift.Parsers
, Shift.Processing , Shift.Processing
, Shift.Rendering , Shift.Rendering
, Shift.Server
, Shift.Types , Shift.Types
, Shift.Utilities , Shift.Utilities
, GitHub.UserSearch , GitHub.UserSearch
...@@ -48,6 +49,7 @@ library ...@@ -48,6 +49,7 @@ library
, exceptions , exceptions
, semigroups , semigroups
, cmark-gfm , cmark-gfm
, scotty
default-language: Haskell2010 default-language: Haskell2010
executable shift executable shift
......
...@@ -11,6 +11,7 @@ import Shift.CLI as X ...@@ -11,6 +11,7 @@ import Shift.CLI as X
import Shift.Git as X import Shift.Git as X
import Shift.Rendering as X import Shift.Rendering as X
import Shift.Types as X import Shift.Types as X
import Shift.Server (runServer)
-- | The main CLI entrypoint. -- | The main CLI entrypoint.
shiftMain :: IO () shiftMain :: IO ()
...@@ -19,6 +20,7 @@ shiftMain = do ...@@ -19,6 +20,7 @@ shiftMain = do
case currentOptions ^. soCommand of case currentOptions ^. soCommand of
GenerateCommand -> tempMain currentOptions GenerateCommand -> tempMain currentOptions
ServeCommand -> runServer currentOptions
where where
opts = info (helper <*> shiftOptions) opts = info (helper <*> shiftOptions)
......
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Shift.CLI where module Shift.CLI where
import Options.Applicative
import Control.Lens (makeLenses) import Control.Lens (makeLenses)
import Options.Applicative
data ShiftOptions = ShiftOptions data ShiftOptions = ShiftOptions
{ _soCommand :: ShiftCommand { _soCommand :: ShiftCommand,
, _soHostingType :: HostingType _soHostingType :: HostingType,
, _soGitHubOwner :: Maybe String _soGitHubOwner :: Maybe String,
, _soGitHubRepository :: Maybe String _soGitHubRepository :: Maybe String,
, _soGitHubToken :: Maybe String _soGitHubToken :: Maybe String
} deriving (Show, Eq) }
deriving (Show, Eq)
data ShiftCommand = GenerateCommand deriving (Show, Eq, Enum) data ShiftCommand = GenerateCommand | ServeCommand deriving (Show, Eq, Enum)
data HostingType = GitHubType | GitType deriving (Show, Eq, Enum) data HostingType = GitHubType | GitType deriving (Show, Eq, Enum)
shiftOptions :: Parser ShiftOptions shiftOptions :: Parser ShiftOptions
shiftOptions = ShiftOptions shiftOptions =
<$> shiftCommand ShiftOptions
<*> option hostingType <$> shiftCommand
( long "hosting-type" <*> option
<> short 't' hostingType
<> metavar "TYPE" ( long "hosting-type"
<> help "Which kind of service the repository is hosted on" <> short 't'
) <> metavar "TYPE"
<*> optional (strOption <> help "Which kind of service the repository is hosted on"
( long "github-owner" )
<> metavar "USERNAME" <*> optional
<> help "Username who owns the repository" ( strOption
)) ( long "github-owner"
<*> optional (strOption <> metavar "USERNAME"
( long "github-repository" <> help "Username who owns the repository"
<> metavar "REPOSITORY" )
<> help "Name of the repository" )
)) <*> optional
<*> optional (strOption ( strOption
( long "github-token" ( long "github-repository"
<> metavar "TOKEN" <> metavar "REPOSITORY"
<> help "GitHub access token" <> help "Name of the repository"
)) )
)
<*> optional
( strOption
( long "github-token"
<> metavar "TOKEN"
<> help "GitHub access token"
)
)
shiftCommand :: Parser ShiftCommand shiftCommand :: Parser ShiftCommand
shiftCommand = subparser $ shiftCommand =
command "generate" subparser $
(info (pure GenerateCommand) command
(progDesc "Generate changelog") "generate"
) ( info
(pure GenerateCommand)
(progDesc "Generate changelog")
)
<> command
"serve"
(info (pure ServeCommand) (progDesc "Start UI server"))
hostingType :: ReadM HostingType hostingType :: ReadM HostingType
hostingType = eitherReader $ \case hostingType = eitherReader $ \case
......
{-# LANGUAGE OverloadedStrings #-}
module Shift.Server (runServer) where
import Web.Scotty (scotty, get, param, html)
import Shift.CLI (ShiftOptions)
import Shift.Git (renderToNode)
import Control.Monad.IO.Class (MonadIO(liftIO))
import CMarkGFM (nodeToHtml, nodeToHtml, commonmarkToHtml)
import Data.Text.Lazy (fromChunks)
runServer :: ShiftOptions -> IO ()
runServer options = scotty 3000 $
get "/" $ do
node <- liftIO $ renderToNode options
html $ fromChunks [nodeToHtml [] [] node]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment