elm-pages-v3-beta/generator/src/generate-elm-stuff.js

35 lines
1000 B
JavaScript
Raw Normal View History

const fs = require("fs");
const runElm = require("./compile-elm.js");
const copyModifiedElmJson = require("./rewrite-elm-json.js");
2019-08-20 02:25:30 +03:00
const { elmPagesCliFile } = require("./elm-file-constants.js");
const path = require("path");
const { ensureDirSync, deleteIfExists } = require('./file-helpers.js')
module.exports = function run(
mode,
staticRoutes,
markdownContent,
callback
) {
ensureDirSync("./elm-stuff");
ensureDirSync("./elm-stuff/elm-pages");
// prevent compilation errors if migrating from previous elm-pages version
deleteIfExists("./elm-stuff/elm-pages/Pages/ContentCache.elm");
deleteIfExists("./elm-stuff/elm-pages/Pages/Platform.elm");
2020-04-20 04:32:16 +03:00
// write `Pages.elm` with cli interface
fs.writeFileSync(
"./elm-stuff/elm-pages/Pages.elm",
2020-04-20 04:32:16 +03:00
elmPagesCliFile(staticRoutes, markdownContent)
);
// write modified elm.json to elm-stuff/elm-pages/
copyModifiedElmJson();
// run Main.elm from elm-stuff/elm-pages with `runElm`
2020-04-21 03:12:16 +03:00
return runElm(mode, callback);
};