git.iko.soy/horeca-productions/landing
on master help sign in
89 lines 2.6 kB history raw
1module AddStaticRoute exposing (run)
3import BackendTask
4import Cli.Option as Option
5import Cli.OptionsParser as OptionsParser
6import Cli.Program as Program
7import Elm
8import Elm.Annotation as Type
9import Elm.Arg
10import Elm.Case
11import Gen.BackendTask
12import Gen.Effect as Effect
13import Gen.Html as Html
14import Gen.Platform.Sub
15import Gen.View
16import Pages.Script as Script exposing (Script)
17import Scaffold.Route exposing (Type(..))
20type alias CliOptions =
21 { moduleName : List String
22 }
25run : Script
26run =
27 Script.withCliOptions program
28 (\cliOptions ->
29 cliOptions
30 |> createFile
31 |> Script.writeFile
32 |> BackendTask.allowFatal
33 )
36program : Program.Config CliOptions
37program =
38 Program.config
39 |> Program.add
40 (OptionsParser.build CliOptions
41 |> OptionsParser.with (Option.requiredPositionalArg "module" |> Scaffold.Route.moduleNameCliArg)
42 )
45createFile : CliOptions -> { path : String, body : String }
46createFile { moduleName } =
47 Scaffold.Route.preRender
48 { moduleName = moduleName
49 , pages =
50 Gen.BackendTask.succeed
51 (Elm.list [])
52 , data =
53 ( Alias (Type.record [])
54 , \routeParams ->
55 Gen.BackendTask.succeed (Elm.record [])
56 )
57 , head = \app -> Elm.list []
58 }
59 |> Scaffold.Route.buildWithLocalState
60 { view =
61 \{ shared, model, app } ->
62 Gen.View.make_.view
63 { title = moduleName |> String.join "." |> Elm.string
64 , body =
65 Elm.list
66 [ Html.h2 [] [ Html.text "New Page" ]
67 ]
68 }
69 , update =
70 \{ shared, app, msg, model } ->
71 Elm.Case.custom msg
72 (Type.named [] "Msg")
73 [ Elm.Case.branch (Elm.Arg.customType "NoOp" ())
74 (\() ->
75 Elm.tuple model
76 Effect.none
77 )
78 ]
79 , init =
80 \{ shared, app } ->
81 Elm.tuple (Elm.record []) Effect.none
82 , subscriptions =
83 \{ routeParams, path, shared, model } ->
84 Gen.Platform.Sub.none
85 , model =
86 Alias (Type.record [])
87 , msg =
88 Custom [ Elm.variant "NoOp" ]
89 }