1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/js/main.ts
2019-02-18 23:04:59 -05:00

64 lines
1.6 KiB
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// tslint:disable-next-line:no-reference
/// <reference path="./plugins.d.ts" />
import "./globals";
import { assert, log } from "./util";
import * as os from "./os";
import { libdeno } from "./libdeno";
import { args } from "./deno";
import { replLoop } from "./repl";
import { setVersions } from "./version";
import { setLocation } from "./location";
// builtin modules
import * as deno from "./deno";
// TODO(kitsonk) remove with `--types` below
import libDts from "gen/lib/lib.deno_runtime.d.ts!string";
/* tslint:disable-next-line:no-default-export */
export default function denoMain() {
const startResMsg = os.start();
// TODO(kitsonk) remove when import "deno" no longer supported
libdeno.builtinModules["deno"] = deno;
Object.freeze(libdeno.builtinModules);
setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
// handle `--version`
if (startResMsg.versionFlag()) {
console.log("deno:", deno.version.deno);
console.log("v8:", deno.version.v8);
console.log("typescript:", deno.version.typescript);
os.exit(0);
}
// handle `--types`
// TODO(kitsonk) move to Rust fetching from compiler
if (startResMsg.typesFlag()) {
console.log(libDts);
os.exit(0);
}
const mainModule = startResMsg.mainModule();
if (mainModule) {
assert(mainModule.length > 0);
setLocation(mainModule);
}
const cwd = startResMsg.cwd();
log("cwd", cwd);
for (let i = 1; i < startResMsg.argvLength(); i++) {
args.push(startResMsg.argv(i));
}
log("args", args);
Object.freeze(args);
if (!mainModule) {
replLoop();
}
}