2018-05-28 21:50:44 -04:00
|
|
|
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
|
|
|
// All rights reserved. MIT License.
|
2018-05-27 01:33:21 -04:00
|
|
|
// This allows us to have async/await in our code. It must be loaded first.
|
|
|
|
import "babel-polyfill";
|
|
|
|
|
2018-05-21 22:07:40 -04:00
|
|
|
import * as dispatch from "./dispatch";
|
2018-05-14 03:06:09 -04:00
|
|
|
import { main as pb } from "./msg.pb";
|
2018-05-21 22:07:40 -04:00
|
|
|
|
2018-05-17 09:47:09 -04:00
|
|
|
import * as runtime from "./runtime";
|
2018-05-19 05:38:51 -04:00
|
|
|
import * as util from "./util";
|
2018-05-14 01:30:56 -04:00
|
|
|
|
2018-05-21 22:07:40 -04:00
|
|
|
import { initTimers } from "./timers";
|
2018-05-27 03:46:18 -04:00
|
|
|
import { initFetch } from "./fetch";
|
2018-05-21 22:07:40 -04:00
|
|
|
|
2018-05-19 05:38:51 -04:00
|
|
|
// To control internal logging output
|
|
|
|
// Set with the -debug command-line flag.
|
|
|
|
export let debug = false;
|
2018-05-21 22:07:40 -04:00
|
|
|
let startCalled = false;
|
|
|
|
|
|
|
|
dispatch.sub("start", (payload: Uint8Array) => {
|
|
|
|
if (startCalled) {
|
|
|
|
throw Error("start message received more than once!");
|
|
|
|
}
|
|
|
|
startCalled = true;
|
|
|
|
|
|
|
|
const msg = pb.Msg.decode(payload);
|
2018-05-25 15:24:24 -04:00
|
|
|
const cwd = msg.startCwd;
|
|
|
|
const argv = msg.startArgv;
|
|
|
|
const debugFlag = msg.startDebugFlag;
|
|
|
|
const mainJs = msg.startMainJs;
|
|
|
|
const mainMap = msg.startMainMap;
|
2018-05-19 05:38:51 -04:00
|
|
|
|
|
|
|
debug = debugFlag;
|
|
|
|
util.log("start", { cwd, argv, debugFlag });
|
2018-05-19 07:06:23 -04:00
|
|
|
|
2018-05-21 22:07:40 -04:00
|
|
|
initTimers();
|
2018-05-27 03:46:18 -04:00
|
|
|
initFetch();
|
2018-05-21 17:33:33 -04:00
|
|
|
runtime.setup(mainJs, mainMap);
|
|
|
|
|
2018-05-19 05:38:51 -04:00
|
|
|
const inputFn = argv[0];
|
2018-05-28 09:42:10 -04:00
|
|
|
const mod = runtime.resolveModule(inputFn, `${cwd}/`);
|
2018-05-19 04:47:40 -04:00
|
|
|
mod.compileAndRun();
|
2018-05-14 00:31:48 -04:00
|
|
|
});
|