Generate new static route records for Cli file in addition to Ui file.

This commit is contained in:
Dillon Kearns 2019-08-20 09:31:04 -07:00
parent 290e79f2c6
commit beb9268de0
4 changed files with 37 additions and 26 deletions

View File

@ -1,6 +1,27 @@
const exposingList = "(application, PageRoute, all, pages, routeToString)";
const elmPagesUiFile = `port module PagesNew exposing ${exposingList}
function staticRouteStuff(staticRoutes) {
return `
type PageRoute = PageRoute (List String)
${staticRoutes.allRoutes}
${staticRoutes.routeRecord}
${staticRoutes.urlParser}
${staticRoutes.assetsRecord}
routeToString : PageRoute -> String
routeToString (PageRoute route) =
"/"
++ (route |> String.join "/")
`;
}
function elmPagesUiFile(staticRoutes) {
return `port module PagesNew exposing ${exposingList}
import Dict exposing (Dict)
import Head
@ -44,9 +65,12 @@ application config =
, head = config.head
, manifest = config.manifest
}
${staticRouteStuff(staticRoutes)}
`;
}
const elmPagesCliFile = `port module PagesNew exposing ${exposingList}
function elmPagesCliFile(staticRoutes) {
return `port module PagesNew exposing ${exposingList}
import Dict exposing (Dict)
import Head
@ -90,5 +114,9 @@ application config =
, head = config.head
, manifest = config.manifest
}
${staticRouteStuff(staticRoutes)}
`;
}
module.exports = { elmPagesUiFile, elmPagesCliFile };

View File

@ -61,30 +61,11 @@ function run() {
});
app.ports.writeFile.subscribe(contents => {
const uiFile =
elmPagesUiFile +
`
type PageRoute = PageRoute (List String)
${staticRoutes.allRoutes}
${staticRoutes.routeRecord}
${staticRoutes.urlParser}
${staticRoutes.assetsRecord}
routeToString : PageRoute -> String
routeToString (PageRoute route) =
"/"
++ (route |> String.join "/")
`;
fs.writeFileSync("./gen/RawContent.elm", contents.rawContent);
fs.writeFileSync("./gen/PagesNew.elm", uiFile);
fs.writeFileSync("./gen/PagesNew.elm", elmPagesUiFile(staticRoutes));
fs.writeFileSync("./src/js/image-assets.js", contents.imageAssets);
console.log("elm-pages DONE");
doCliStuff(contents.rawContent, function(manifestConfig) {
doCliStuff(staticRoutes, contents.rawContent, function(manifestConfig) {
if (contents.watch) {
startWatchIfNeeded();
develop.start({

View File

@ -3,13 +3,16 @@ const runElm = require("./compile-elm.js");
const copyModifiedElmJson = require("./rewrite-elm-json.js");
const { elmPagesCliFile } = require("./elm-file-constants.js");
module.exports = function run(rawContentFile, callback) {
module.exports = function run(staticRoutes, rawContentFile, callback) {
// mkdir -p elm-stuff/elm-pages/
// requires NodeJS >= 10.12.0
fs.mkdirSync("./elm-stuff/elm-pages", { recursive: true });
// write `PagesNew.elm` with cli interface
fs.writeFileSync("./elm-stuff/elm-pages/PagesNew.elm", elmPagesCliFile);
fs.writeFileSync(
"./elm-stuff/elm-pages/PagesNew.elm",
elmPagesCliFile(staticRoutes)
);
// generate RawContent.elm
fs.writeFileSync("./elm-stuff/elm-pages/RawContent.elm", rawContentFile);

View File

@ -54,7 +54,6 @@ function generate(scanned) {
//remove extesion and split into fragments
pathFragments = pathFragments.replace(/\.[^/.]+$/, "").split(path.sep);
const is404 = pathFragments.length == 1 && pathFragments[0] == "404";
console.log("is404", is404, pathFragments);
const ext = path.extname(scanned[i].path);
if (scanned[i].document) {
// const elmType = pathFragments.map(toPascalCase).join("");