Generate files to avoid having to manually copy and update vendor files.

This commit is contained in:
Dillon Kearns 2019-09-23 16:11:59 -07:00
parent b5cca02356
commit 479ad6267c
3 changed files with 38 additions and 2 deletions

View File

@ -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"
}
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}