2019-08-20 01:20:20 +03:00
|
|
|
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");
|
2019-09-24 02:11:59 +03:00
|
|
|
const path = require("path");
|
2019-08-20 01:20:20 +03:00
|
|
|
|
2019-09-06 06:33:11 +03:00
|
|
|
module.exports = function run(
|
|
|
|
staticRoutes,
|
|
|
|
markdownContent,
|
|
|
|
markupContent,
|
|
|
|
callback
|
|
|
|
) {
|
2019-09-25 01:07:21 +03:00
|
|
|
ensureDirSync("./elm-stuff");
|
|
|
|
ensureDirSync("./elm-stuff/elm-pages");
|
2019-08-20 01:20:20 +03:00
|
|
|
|
2019-09-16 07:51:16 +03:00
|
|
|
// write `Pages.elm` with cli interface
|
2019-08-20 19:31:04 +03:00
|
|
|
fs.writeFileSync(
|
2019-09-16 07:51:16 +03:00
|
|
|
"./elm-stuff/elm-pages/Pages.elm",
|
2019-09-06 06:33:11 +03:00
|
|
|
elmPagesCliFile(staticRoutes, markdownContent, markupContent)
|
2019-08-20 19:31:04 +03:00
|
|
|
);
|
2019-08-20 01:20:20 +03:00
|
|
|
|
|
|
|
// write modified elm.json to elm-stuff/elm-pages/
|
|
|
|
copyModifiedElmJson();
|
|
|
|
|
|
|
|
// run Main.elm from elm-stuff/elm-pages with `runElm`
|
2019-08-20 01:58:55 +03:00
|
|
|
runElm(callback);
|
2019-08-20 01:20:20 +03:00
|
|
|
};
|
2019-09-24 02:11:59 +03:00
|
|
|
|
|
|
|
function ensureDirSync(dirpath) {
|
|
|
|
try {
|
|
|
|
fs.mkdirSync(dirpath, { recursive: true });
|
|
|
|
} catch (err) {
|
|
|
|
if (err.code !== "EEXIST") throw err;
|
|
|
|
}
|
|
|
|
}
|