Skip to content

Instantly share code, notes, and snippets.

@boxdot
Last active July 24, 2018 20:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxdot/ac3243b67fff83f53493 to your computer and use it in GitHub Desktop.
Save boxdot/ac3243b67fff83f53493 to your computer and use it in GitHub Desktop.
Minimal console app in Elm
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."
// 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
});
}
@boxdot
Copy link
Author

boxdot commented Sep 25, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment