Switch back to original dir after running elm, and export function.

This commit is contained in:
Dillon Kearns 2019-08-19 10:23:07 -07:00
parent c022531ff2
commit 68b6ceb769

View File

@ -1,12 +1,22 @@
var compile = require("node-elm-compiler").compile;
var compileToString = require("node-elm-compiler").compileToString;
const { compileToString } = require("node-elm-compiler");
process.chdir("./examples/docs/");
compileToString(["./src/Main.elm"], {}).then(function(data) {
eval(data.toString());
const app = Elm.Main.init({ flags: { imageAssets: {} } });
module.exports = runElm;
function runElm(callback) {
const startingDir = process.cwd();
console.log("cwd", process.cwd());
process.chdir("./examples/docs/");
console.log("cwd", process.cwd());
compileToString(["./src/Main.elm"], {}).then(function(data) {
eval(data.toString());
const app = Elm.Main.init({ flags: { imageAssets: {} } });
app.ports.toJsPort.subscribe(payload => {
console.log("payload", payload);
app.ports.toJsPort.subscribe(payload => {
console.log("payload", payload);
callback(payload);
process.chdir(startingDir);
console.log("cwd", process.cwd());
});
});
});
}
runElm(function() {});