2022-09-09 20:56:54 +03:00
|
|
|
port module Cli exposing (main)
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
|
|
|
|
import Cli.Option as Option
|
|
|
|
import Cli.OptionsParser as OptionsParser
|
|
|
|
import Cli.Program as Program
|
|
|
|
import Cli.Validate
|
|
|
|
import Elm
|
|
|
|
import Elm.Annotation
|
|
|
|
import Elm.Case
|
|
|
|
import Gen.DataSource
|
|
|
|
import Gen.Effect
|
|
|
|
import Gen.Html
|
|
|
|
import Gen.Platform.Sub
|
|
|
|
import Gen.Server.Request
|
|
|
|
import Gen.Server.Response
|
|
|
|
import Gen.View
|
2022-09-09 21:09:25 +03:00
|
|
|
import Pages.Generate exposing (Type(..))
|
2022-09-09 20:56:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias CliOptions =
|
|
|
|
{ moduleName : String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
program : Program.Config CliOptions
|
|
|
|
program =
|
|
|
|
Program.config
|
|
|
|
|> Program.add
|
|
|
|
(OptionsParser.build CliOptions
|
|
|
|
|> OptionsParser.with
|
|
|
|
(Option.requiredPositionalArg "module"
|
|
|
|
|> Option.validate (Cli.Validate.regex moduleNameRegex)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
moduleNameRegex : String
|
|
|
|
moduleNameRegex =
|
|
|
|
"([A-Z][a-zA-Z_]*)(\\.([A-Z][a-zA-Z_]*))*"
|
|
|
|
|
|
|
|
|
|
|
|
main : Program.StatelessProgram Never {}
|
|
|
|
main =
|
|
|
|
Program.stateless
|
|
|
|
{ printAndExitFailure = printAndExitFailure
|
|
|
|
, printAndExitSuccess = printAndExitSuccess
|
|
|
|
, init = init
|
|
|
|
, config = program
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Flags =
|
|
|
|
Program.FlagsIncludingArgv {}
|
|
|
|
|
|
|
|
|
|
|
|
init : Flags -> CliOptions -> Cmd Never
|
|
|
|
init flags cliOptions =
|
|
|
|
let
|
|
|
|
file : Elm.File
|
|
|
|
file =
|
|
|
|
createFile (cliOptions.moduleName |> String.split ".")
|
|
|
|
in
|
|
|
|
writeFile
|
|
|
|
{ path = file.path
|
|
|
|
, body = file.contents
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
createFile : List String -> Elm.File
|
|
|
|
createFile moduleName =
|
2022-09-10 03:18:23 +03:00
|
|
|
Pages.Generate.serverRender
|
|
|
|
{ moduleName = moduleName
|
|
|
|
, action =
|
|
|
|
( Alias (Elm.Annotation.record [])
|
|
|
|
, \routeParams ->
|
2022-09-09 20:56:54 +03:00
|
|
|
Gen.Server.Request.succeed
|
|
|
|
(Gen.DataSource.succeed
|
|
|
|
(Gen.Server.Response.render
|
|
|
|
(Elm.record [])
|
|
|
|
)
|
|
|
|
)
|
2022-09-10 03:18:23 +03:00
|
|
|
)
|
2022-09-09 20:56:54 +03:00
|
|
|
, data =
|
2022-09-10 03:18:23 +03:00
|
|
|
( Alias (Elm.Annotation.record [])
|
|
|
|
, \routeParams ->
|
2022-09-09 20:56:54 +03:00
|
|
|
Gen.Server.Request.succeed
|
|
|
|
(Gen.DataSource.succeed
|
|
|
|
(Gen.Server.Response.render
|
|
|
|
(Elm.record [])
|
|
|
|
)
|
|
|
|
)
|
2022-09-10 03:18:23 +03:00
|
|
|
)
|
2022-09-09 20:56:54 +03:00
|
|
|
, head = \app -> Elm.list []
|
2022-09-10 03:18:23 +03:00
|
|
|
}
|
|
|
|
|> Pages.Generate.withLocalState
|
|
|
|
{ view =
|
|
|
|
\maybeUrl sharedModel model app ->
|
|
|
|
Gen.View.make_.view
|
|
|
|
{ title = moduleName |> String.join "." |> Elm.string
|
|
|
|
, body = Elm.list [ Gen.Html.text "Here is your generated page!!!" ]
|
|
|
|
}
|
|
|
|
, update =
|
|
|
|
\pageUrl sharedModel app msg model ->
|
|
|
|
Elm.Case.custom msg
|
|
|
|
(Elm.Annotation.named [] "Msg")
|
|
|
|
[ Elm.Case.branch0 "NoOp"
|
|
|
|
(Elm.tuple model Gen.Effect.none)
|
|
|
|
]
|
|
|
|
, init =
|
|
|
|
\pageUrl sharedModel app ->
|
|
|
|
Elm.tuple (Elm.record []) Gen.Effect.none
|
|
|
|
, subscriptions =
|
|
|
|
\maybePageUrl routeParams path sharedModel model ->
|
|
|
|
Gen.Platform.Sub.none
|
2022-09-09 20:56:54 +03:00
|
|
|
, model =
|
2022-09-09 21:09:25 +03:00
|
|
|
Alias (Elm.Annotation.record [])
|
2022-09-09 20:56:54 +03:00
|
|
|
, msg =
|
2022-09-09 21:09:25 +03:00
|
|
|
Custom [ Elm.variant "NoOp" ]
|
2022-09-09 20:56:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
port print : String -> Cmd msg
|
|
|
|
|
|
|
|
|
|
|
|
port printAndExitFailure : String -> Cmd msg
|
|
|
|
|
|
|
|
|
|
|
|
port printAndExitSuccess : String -> Cmd msg
|
|
|
|
|
|
|
|
|
|
|
|
port writeFile : { path : String, body : String } -> Cmd msg
|