mirror of
https://github.com/kanaka/mal.git
synced 2024-10-27 14:52:16 +03:00
e984ed8801
Various trivial changes reducing the diff to #450. Dockerfile: npm already depends on nodejs Core.elm: change profile of deepEquals instead of uncurrying before each call.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
var readline = require('./node_readline');
|
|
var fs = require('fs');
|
|
|
|
// The first two arguments are: 'node' and 'bootstrap.js'
|
|
// The third argument is the name of the Elm module to load.
|
|
var args = process.argv.slice(2);
|
|
var mod = require('./' + args[0]);
|
|
|
|
var app = mod.Elm['S' + args[0].slice(1)].init({
|
|
flags: {
|
|
args: args.slice(1)
|
|
}
|
|
});
|
|
|
|
// Hook up the writeLine and readLine ports of the app.
|
|
app.ports.writeLine.subscribe(function(line) {
|
|
console.log(line);
|
|
app.ports.input.send({"tag": "lineWritten"});
|
|
});
|
|
|
|
app.ports.readLine.subscribe(function(prompt) {
|
|
var line = readline.readline(prompt);
|
|
app.ports.input.send({"tag": "lineRead", "line": line});
|
|
});
|
|
|
|
// Read the contents of a file.
|
|
if ('readFile' in app.ports) {
|
|
app.ports.readFile.subscribe(function(filename) {
|
|
try {
|
|
var contents = fs.readFileSync(filename, 'utf8');
|
|
app.ports.input.send({"tag": "fileRead", "contents": contents});
|
|
} catch (e) {
|
|
app.ports.input.send({"tag": "exception", "message": e.message});
|
|
}
|
|
});
|
|
}
|