diff --git a/examples/docs/elm.json b/examples/docs/elm.json index 8a50b585..ca3eb309 100644 --- a/examples/docs/elm.json +++ b/examples/docs/elm.json @@ -2,7 +2,6 @@ "type": "application", "source-directories": [ "src", - "../../elm-package/src", "../../src", "gen", "elm-markdown-parser" @@ -48,4 +47,4 @@ "elm/random": "1.0.0" } } -} \ No newline at end of file +} diff --git a/generator/src/elm-pages.js b/generator/src/elm-pages.js index 23ff48b0..57413f86 100755 --- a/generator/src/elm-pages.js +++ b/generator/src/elm-pages.js @@ -10,6 +10,7 @@ const doCliStuff = require("./generate-elm-stuff.js"); const { elmPagesUiFile } = require("./elm-file-constants.js"); const generateRecords = require("./generate-records.js"); const parseFrontmatter = require("./frontmatter.js"); +const path = require("path"); const contentGlobPath = "content/**/*.emu"; @@ -82,6 +83,15 @@ function run() { "./gen/Pages.elm", elmPagesUiFile(staticRoutes, markdownContent, content) ); + ensureDirSync("./gen/Pages"); + fs.copyFileSync( + path.resolve(__dirname, "../../elm-package/src/Pages/ContentCache.elm"), + "./gen/Pages/ContentCache.elm" + ); + fs.copyFileSync( + path.resolve(__dirname, "../../elm-package/src/Pages/Platform.elm"), + "./gen/Pages/Platform.elm" + ); console.log("elm-pages DONE"); doCliStuff(staticRoutes, markdownContent, content, function(payload) { if (contents.watch) { @@ -151,3 +161,11 @@ function toRoute(entry) { fullPath.splice(0, 1); return `/${fullPath.join("/")}`; } + +function ensureDirSync(dirpath) { + try { + fs.mkdirSync(dirpath, { recursive: true }); + } catch (err) { + if (err.code !== "EEXIST") throw err; + } +} diff --git a/generator/src/generate-elm-stuff.js b/generator/src/generate-elm-stuff.js index f4503f71..f7abe74e 100644 --- a/generator/src/generate-elm-stuff.js +++ b/generator/src/generate-elm-stuff.js @@ -2,6 +2,7 @@ const fs = require("fs"); const runElm = require("./compile-elm.js"); const copyModifiedElmJson = require("./rewrite-elm-json.js"); const { elmPagesCliFile } = require("./elm-file-constants.js"); +const path = require("path"); module.exports = function run( staticRoutes, @@ -19,9 +20,27 @@ module.exports = function run( elmPagesCliFile(staticRoutes, markdownContent, markupContent) ); + ensureDirSync("./elm-stuff/elm-pages/Pages"); + fs.copyFileSync( + path.resolve(__dirname, "../../elm-package/src/Pages/ContentCache.elm"), + "./elm-stuff/elm-pages/Pages/ContentCache.elm" + ); + fs.copyFileSync( + path.resolve(__dirname, "../../elm-package/src/Pages/Platform.elm"), + "./elm-stuff/elm-pages/Pages/Platform.elm" + ); + // write modified elm.json to elm-stuff/elm-pages/ copyModifiedElmJson(); // run Main.elm from elm-stuff/elm-pages with `runElm` runElm(callback); }; + +function ensureDirSync(dirpath) { + try { + fs.mkdirSync(dirpath, { recursive: true }); + } catch (err) { + if (err.code !== "EEXIST") throw err; + } +}