mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
deno2: compile in TS, build protobuf
This commit is contained in:
parent
356fd18c73
commit
b3003535be
7 changed files with 495 additions and 2979 deletions
102
deno2/BUILD.gn
102
deno2/BUILD.gn
|
@ -68,29 +68,91 @@ proto_library("msg_proto") {
|
|||
]
|
||||
}
|
||||
|
||||
action("run_parcel") {
|
||||
template("run_node") {
|
||||
action(target_name) {
|
||||
forward_variables_from(invoker, "*")
|
||||
script = "js/run_node.py"
|
||||
}
|
||||
}
|
||||
|
||||
run_node("bundle") {
|
||||
main_source = "$target_gen_dir/tsc_dist/main.js"
|
||||
main_output = "$target_gen_dir/bundle/main.js"
|
||||
sources = [
|
||||
"js/main.ts",
|
||||
main_source,
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/main.js",
|
||||
"$target_gen_dir/main.map",
|
||||
main_output,
|
||||
]
|
||||
deps = [
|
||||
":run_tsc",
|
||||
]
|
||||
|
||||
# Our script imports this Python file so we want to rebuild if it changes.
|
||||
# inputs = [ "helper_library.py" ]
|
||||
|
||||
# Note that we have to manually pass the sources to our script if the
|
||||
# script needs them as inputs.
|
||||
script = "js/run_node.py"
|
||||
root = root_build_dir + "/../../js"
|
||||
args = [
|
||||
"./node_modules/.bin/parcel",
|
||||
"build",
|
||||
"--log-level=1",
|
||||
"--no-minify",
|
||||
"--out-dir=" + rebase_path(target_gen_dir, root),
|
||||
] + rebase_path(sources, root)
|
||||
"./node_modules/.bin/browserify",
|
||||
rebase_path(main_source, root_build_dir),
|
||||
"-o",
|
||||
rebase_path(main_output, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
run_node("run_tsc") {
|
||||
main_source = "js/main.ts"
|
||||
sources = [
|
||||
"$target_gen_dir/node_modules/deno_pb/msg.pb.d.ts",
|
||||
"$target_gen_dir/node_modules/deno_pb/msg.pb.js",
|
||||
"js/tsconfig.json",
|
||||
main_source,
|
||||
]
|
||||
out_dir = "$target_gen_dir/tsc_dist"
|
||||
outputs = [
|
||||
out_dir + "/main.js",
|
||||
out_dir + "/main.map",
|
||||
]
|
||||
deps = [
|
||||
":run_pbjs",
|
||||
":run_pbts",
|
||||
]
|
||||
args = [
|
||||
"./node_modules/.bin/tsc",
|
||||
"--baseUrl",
|
||||
rebase_path(target_gen_dir + "/node_modules", root_build_dir),
|
||||
"--outDir",
|
||||
rebase_path(out_dir, root_build_dir),
|
||||
rebase_path(main_source, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
run_node("run_pbjs") {
|
||||
sources = [
|
||||
"msg.proto",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/node_modules/deno_pb/msg.pb.js",
|
||||
]
|
||||
args = [
|
||||
"./node_modules/.bin/pbjs",
|
||||
"--target=static-module",
|
||||
"--wraper=commonjs",
|
||||
"--out=" + rebase_path(outputs[0], root_build_dir),
|
||||
rebase_path(sources[0], root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
run_node("run_pbts") {
|
||||
sources = [
|
||||
"$target_gen_dir/node_modules/deno_pb/msg.pb.js",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/node_modules/deno_pb/msg.pb.d.ts",
|
||||
]
|
||||
args = [
|
||||
"./node_modules/.bin/pbts",
|
||||
"--out=" + rebase_path(outputs[0], root_build_dir),
|
||||
rebase_path(sources[0], root_build_dir),
|
||||
]
|
||||
deps = [
|
||||
":run_pbjs",
|
||||
]
|
||||
}
|
||||
|
||||
# Template to generate different V8 snapshots based on different runtime flags.
|
||||
|
@ -145,9 +207,9 @@ template("create_snapshot") {
|
|||
|
||||
# Generates $target_gen_dir/snapshot_deno.cc
|
||||
create_snapshot("deno") {
|
||||
js = "$target_gen_dir/main.js"
|
||||
js = "$target_gen_dir/bundle/main.js"
|
||||
deps = [
|
||||
":run_parcel",
|
||||
":bundle",
|
||||
]
|
||||
}
|
||||
|
||||
|
|
6
deno2/js/deno.d.ts
vendored
Normal file
6
deno2/js/deno.d.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
||||
// All rights reserved. MIT License.
|
||||
type MessageCallback = (msg: ArrayBuffer) => void;
|
||||
declare function denoSub(channel: string, cb: MessageCallback): void;
|
||||
declare function denoPub(channel: string, msg: ArrayBuffer): null | ArrayBuffer;
|
||||
declare function denoPrint(x: string): void;
|
|
@ -1,6 +1,13 @@
|
|||
/// <reference path="deno.d.ts" />
|
||||
//import { main as pb } from "deno_pb/msg.pb"
|
||||
import * as ts from "typescript";
|
||||
|
||||
const globalEval = eval;
|
||||
const window = globalEval("this");
|
||||
window["denoMain"] = () => {
|
||||
//const msg = pb.Msg.fromObject({});
|
||||
//denoPrint(`msg.command: ${msg.command}`);
|
||||
denoPrint(`ts.version: ${ts.version}`);
|
||||
denoPrint("Hello world from foo");
|
||||
return "foo";
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"parcel-bundler": "^1.8.1",
|
||||
"browserify": "^16.2.2",
|
||||
"protobufjs": "^6.8.6",
|
||||
"typescript": "^2.9.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
gn can only run python scripts.
|
||||
Also Node programs except to be run with cwd = $root_dir/js so it can resolve
|
||||
node_modules.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
js_path = os.path.dirname(os.path.realpath(__file__))
|
||||
os.chdir(js_path)
|
||||
node_modules_path = os.path.join(js_path, "node_modules")
|
||||
|
||||
# root_out_dir
|
||||
if not os.path.exists("node_modules"):
|
||||
os.symlink(node_modules_path, "node_modules")
|
||||
|
||||
args = ["node"] + sys.argv[1:]
|
||||
sys.exit(subprocess.call(args))
|
||||
|
|
19
deno2/js/tsconfig.json
Normal file
19
deno2/js/tsconfig.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
"removeComments": true,
|
||||
"preserveConstEnums": true,
|
||||
"declaration": true,
|
||||
"target": "es2017",
|
||||
"noImplicitReturns": true,
|
||||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"allowUnreachableCode": false,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"include": ["*.ts", "*.js"],
|
||||
"exclude": ["tests.ts"]
|
||||
}
|
3327
deno2/js/yarn.lock
3327
deno2/js/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue