Last active
July 24, 2018 20:47
-
-
Save boxdot/ac3243b67fff83f53493 to your computer and use it in GitHub Desktop.
Minimal console app in Elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Cli where | |
port output : String | |
port output = | |
"Sub-orbital table 8-bit realism boat soul-delay face forwards industrial | |
grade drone. Cartel towards footage tube assault table woman stimulate bridge | |
claymore mine semiotics human. Post-construct j-pop military-grade stimulate | |
narrative realism. Shoes convenience store sunglasses realism numinous tanto | |
long-chain hydrocarbons. Franchise tower render-farm girl wonton soup sprawl | |
fetishism Kowloon advert semiotics shoes dolphin drugs otaku marketing. | |
Refrigerator 8-bit nodality rebar-space sprawl marketing jeans dissident | |
human artisanal soul-delay. Dome crypto-range-rover realism katana engine | |
nano-military-grade Kowloon otaku pre-advert into." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Execute elm code in node and print output | |
// | |
// The module specified in `ELM_MODULE` should define a port `output`. The code | |
// should be compiled in file specified by `ELM_CODE`. | |
const ELM_MODULE = 'Cli'; | |
const ELM_CODE = 'cli.js'; | |
var vm = require('vm'); | |
var fs = require('fs'); | |
var jsdom = require("jsdom").jsdom; | |
var elm = execute(); | |
console.log(elm.ports['output']); | |
function execute() { | |
var context = getDefaultContext(); | |
var code = fs.readFileSync(ELM_CODE); | |
var script = new vm.Script(code); | |
script.runInContext(context); | |
return context.Elm.worker(context.Elm[ELM_MODULE]); | |
} | |
function getDefaultContext() { | |
var document = jsdom(); | |
return new vm.createContext({ | |
document: document, | |
window: document.parentWindow | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to https://github.com/sonnym/node-elm-loader