diff --git a/examples/docs/functions/render/index.js b/examples/docs/functions/render/index.js index 38c081ad..4294af8d 100644 --- a/examples/docs/functions/render/index.js +++ b/examples/docs/functions/render/index.js @@ -1,13 +1,16 @@ -// const path = require("path"); +const path = require("path"); exports.handler = async function (event, context) { console.log(JSON.stringify(event)); // process.chdir(path.join(__dirname, "../../")); // process.chdir("../"); + + // const compiledElmPath = path.join(process.cwd(), "elm-pages-cli.js"); + const compiledElmPath = path.join(__dirname, "elm-pages-cli.js"); const renderer = require("../../../../generator/src/render"); console.log("pwd", process.cwd()); return { - body: (await renderer()).htmlString, + body: (await renderer(compiledElmPath)).htmlString, statusCode: 200, }; }; diff --git a/generator/src/render.js b/generator/src/render.js index 6025e4f7..cb00c306 100755 --- a/generator/src/render.js +++ b/generator/src/render.js @@ -15,14 +15,17 @@ process.on("unhandledRejection", (error) => { process.exit(1); }); -module.exports = async function run() { +module.exports = async function run(/** @type {string} */ compiledElmPath) { XMLHttpRequest = require("xhr2"); console.log("RENDER NEW"); - const result = await runElmApp(); + const result = await runElmApp(compiledElmPath); return result; }; -function runElmApp() { +/** + * @param {string} compiledElmPath + */ +function runElmApp(compiledElmPath) { process.on("beforeExit", (code) => { if (foundErrors) { process.exit(1); @@ -32,10 +35,9 @@ function runElmApp() { }); return new Promise((resolve, _) => { - const ELM_FILE_PATH = path.join(process.cwd(), "elm-pages-cli.js"); const mode /** @type { "dev" | "prod" } */ = "elm-to-html-beta"; const staticHttpCache = {}; - const app = require(ELM_FILE_PATH).Elm.Main.init({ + const app = require(compiledElmPath).Elm.Main.init({ flags: { secrets: process.env, mode, staticHttpCache }, });