Wire up baseUrl for Route module generation.

This commit is contained in:
Dillon Kearns 2022-09-13 10:49:51 -07:00
parent 92365d95b1
commit 08015f49b9
2 changed files with 14 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import Pretty
type alias Flags =
{ templates : List (List String)
, basePath : String
}
@ -30,9 +31,9 @@ main : Program Flags () ()
main =
Platform.worker
{ init =
\{ templates } ->
\{ templates, basePath } ->
( ()
, onSuccessSend [ file templates ]
, onSuccessSend [ file templates basePath ]
)
, update =
\_ model ->
@ -167,8 +168,8 @@ routeToPath routes =
)
file : List (List String) -> Elm.File
file templates =
file : List (List String) -> String -> Elm.File
file templates basePath =
let
routes : List RoutePattern.RoutePattern
routes =
@ -201,7 +202,7 @@ file templates =
)
)
|> expose
, Elm.declaration "baseUrl" (Elm.string "/")
, Elm.declaration "baseUrl" (Elm.string basePath)
|> expose
, maybeToList.declaration
, routeToPath routes |> .declaration |> expose

View File

@ -38,7 +38,10 @@ async function generateTemplateModuleConnector(basePath, phase) {
],
};
}
const routesModuleNew = await runElmCodegenCli(sortTemplates(templates));
const routesModuleNew = await runElmCodegenCli(
sortTemplates(templates),
basePath
);
return {
mainModule: `port module Main exposing (..)
@ -1146,7 +1149,7 @@ redirectTo route =
};
}
async function runElmCodegenCli(templates) {
async function runElmCodegenCli(templates, basePath) {
// await runElmCodegenInstall();
await compileCliApp(
// { debug: true },
@ -1166,7 +1169,9 @@ async function runElmCodegenCli(templates) {
"./elm-stuff/elm-pages-codegen.js"
)).Elm.Generate;
const app = elmPagesCodegen.init({ flags: { templates: templates } });
const app = elmPagesCodegen.init({
flags: { templates: templates, basePath },
});
if (app.ports.onSuccessSend) {
app.ports.onSuccessSend.subscribe(resolve);
}