From 789cc59d88fbcf25540b0ad888791d49de43f2d1 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 21 Oct 2019 23:02:31 -0700 Subject: [PATCH] Send manifest config through port. --- examples/docs/elm.json | 3 +- generator/src/compile-elm.js | 8 ++++- src/Pages/Internal/Platform/Cli.elm | 54 +++++++++++++++++++++-------- tests/StaticHttpRequestsTests.elm | 9 ++--- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/examples/docs/elm.json b/examples/docs/elm.json index e1596532..f2c9df89 100644 --- a/examples/docs/elm.json +++ b/examples/docs/elm.json @@ -27,6 +27,7 @@ "lukewestby/elm-string-interpolate": "1.0.4", "mdgriffith/elm-markup": "3.0.1", "mdgriffith/elm-ui": "1.1.5", + "miniBill/elm-codec": "1.2.0", "noahzgordon/elm-color-extra": "1.0.2", "rtfeldman/elm-hex": "1.0.0" }, @@ -47,4 +48,4 @@ "elm/random": "1.0.0" } } -} \ No newline at end of file +} diff --git a/generator/src/compile-elm.js b/generator/src/compile-elm.js index c81e75be..82cfd932 100644 --- a/generator/src/compile-elm.js +++ b/generator/src/compile-elm.js @@ -16,7 +16,13 @@ function runElm(callback) { app.ports.toJsPort.subscribe(payload => { process.chdir(startingDir); - callback(payload); + + if (payload.tag === "Success") { + callback(payload.args[0]); + } else { + console.log("ERROR bad payload", payload); + process.exit(1); + } delete Elm; console.warn = warnOriginal; }); diff --git a/src/Pages/Internal/Platform/Cli.elm b/src/Pages/Internal/Platform/Cli.elm index 5610d8df..7bb0c144 100644 --- a/src/Pages/Internal/Platform/Cli.elm +++ b/src/Pages/Internal/Platform/Cli.elm @@ -25,6 +25,7 @@ import Json.Encode import Mark import Pages.ContentCache as ContentCache exposing (ContentCache) import Pages.Document +import Pages.ImagePath as ImagePath import Pages.Manifest as Manifest import Pages.PagePath as PagePath exposing (PagePath) import Pages.StaticHttp as StaticHttp @@ -32,17 +33,18 @@ import Pages.StaticHttpRequest as StaticHttpRequest import Url exposing (Url) -type ToJsPayload +type ToJsPayload pathKey = Errors (Dict String String) - | Success ToJsSuccessPayload + | Success (ToJsSuccessPayload pathKey) -type alias ToJsSuccessPayload = +type alias ToJsSuccessPayload pathKey = { pages : Dict String (Dict String String) + , manifest : Manifest.Config pathKey } -toJsCodec : Codec ToJsPayload +toJsCodec : Codec (ToJsPayload pathKey) toJsCodec = Codec.custom (\errors success value -> @@ -50,8 +52,8 @@ toJsCodec = Errors errorList -> errors errorList - Success { pages } -> - success (ToJsSuccessPayload pages) + Success { pages, manifest } -> + success (ToJsSuccessPayload pages manifest) ) |> Codec.variant1 "Errors" Errors (Codec.dict Codec.string) |> Codec.variant1 "Success" @@ -60,20 +62,39 @@ toJsCodec = |> Codec.buildCustom -successCodec : Codec ToJsSuccessPayload +stubManifest : Manifest.Config pathKey +stubManifest = + { backgroundColor = Nothing + , categories = [] + , displayMode = Manifest.Standalone + , orientation = Manifest.Portrait + , description = "elm-pages - A statically typed site generator." + , iarcRatingId = Nothing + , name = "elm-pages docs" + , themeColor = Nothing + , startUrl = PagePath.external "" + , shortName = Just "elm-pages" + , sourceIcon = ImagePath.external "" + } + + +successCodec : Codec (ToJsSuccessPayload pathKey) successCodec = Codec.object ToJsSuccessPayload |> Codec.field "pages" - (\{ pages } -> pages) + .pages (Codec.dict (Codec.dict Codec.string)) + |> Codec.field "manifest" + .manifest + (Codec.build Manifest.toJson (Decode.succeed stubManifest)) |> Codec.buildObject -type Effect +type Effect pathKey = NoEffect - | SendJsData ToJsPayload + | SendJsData (ToJsPayload pathKey) | FetchHttp StaticHttp.Request - | Batch (List Effect) + | Batch (List (Effect pathKey)) type alias Page metadata view pathKey = @@ -188,7 +209,7 @@ cliApplication cliMsgConstructor narrowMsg toModel fromModel config = } -perform : (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect -> Cmd msg +perform : (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect pathKey -> Cmd msg perform cliMsgConstructor toJsPort effect = case effect of NoEffect -> @@ -326,7 +347,12 @@ update siteMetadata config msg model = in ( model , SendJsData - (Success (encodeStaticResponses staticResponses |> ToJsSuccessPayload)) + (Success + (ToJsSuccessPayload + (encodeStaticResponses staticResponses) + config.manifest + ) + ) -- (Json.Encode.object -- [ ( "manifest", Manifest.toJson config.manifest ) -- , ( "pages", encodeStaticResponses staticResponses ) @@ -335,7 +361,7 @@ update siteMetadata config msg model = ) -performStaticHttpRequests : List ( PagePath pathKey, ( StaticHttp.Request, Decode.Value -> Result error value ) ) -> Effect +performStaticHttpRequests : List ( PagePath pathKey, ( StaticHttp.Request, Decode.Value -> Result error value ) ) -> Effect pathKey performStaticHttpRequests staticRequests = -- @@@@@@@@ TODO -- NoEffect diff --git a/tests/StaticHttpRequestsTests.elm b/tests/StaticHttpRequestsTests.elm index eb60fe53..71111ce6 100644 --- a/tests/StaticHttpRequestsTests.elm +++ b/tests/StaticHttpRequestsTests.elm @@ -43,13 +43,14 @@ all = ] ) ] + , manifest = manifest } ] ) ] -start : ProgramTest Main.Model Main.Msg Main.Effect +start : ProgramTest Main.Model Main.Msg (Main.Effect PathKey) start = let document = @@ -114,7 +115,7 @@ start = |> ProgramTest.start () -simulateEffects : Main.Effect -> ProgramTest.SimulatedEffect Main.Msg +simulateEffects : Main.Effect PathKey -> ProgramTest.SimulatedEffect Main.Msg simulateEffects effect = case effect of NoEffect -> @@ -161,7 +162,7 @@ manifest = , iarcRatingId = Nothing , name = "elm-pages docs" , themeColor = Nothing - , startUrl = PagePath.build PathKey [] + , startUrl = PagePath.external "" , shortName = Just "elm-pages" - , sourceIcon = ImagePath.build PathKey [] + , sourceIcon = ImagePath.external "" }