From a2f016a66c31b427dcbd16a2f81b2ce86b352d70 Mon Sep 17 00:00:00 2001 From: MeiK2333 Date: Thu, 5 Nov 2020 20:51:10 +0800 Subject: [PATCH] add language: TypeScript --- .gitignore | 2 ++ Dockerfile | 6 ++++ example/.gitignore | 3 ++ example/main.py | 67 +++++++++++++++++++++----------------- example/ts/1000/.gitignore | 1 + example/ts/1000/in.txt | 0 example/ts/1000/main.ts | 1 + example/ts/1000/out.txt | 1 + example/ts/1001/.gitignore | 1 + example/ts/1001/in.txt | 1 + example/ts/1001/main.ts | 15 +++++++++ example/ts/1001/out.txt | 1 + plugins/build.sh | 4 +++ src/judger.rs | 2 +- 14 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 example/ts/1000/.gitignore create mode 100644 example/ts/1000/in.txt create mode 100644 example/ts/1000/main.ts create mode 100644 example/ts/1000/out.txt create mode 100644 example/ts/1001/.gitignore create mode 100644 example/ts/1001/in.txt create mode 100644 example/ts/1001/main.ts create mode 100644 example/ts/1001/out.txt diff --git a/.gitignore b/.gitignore index c206870..4c05e3b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ Cargo.lock .idea .vscode .devcontainer + +nohup.out diff --git a/Dockerfile b/Dockerfile index 3209c87..efb0113 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,12 @@ RUN add-apt-repository -y ppa:longsleep/golang-backports && \ RUN apt install -y default-jdk # TODO: install other languages +# TODO: C# +# TODO: Ruby +# TODO: PHP +# TODO: Lisp +# TODO: Kotlin +# TODO: Haskell RUN rm -rf /var/lib/apt/lists/* diff --git a/example/.gitignore b/example/.gitignore index 482683f..0c88bd5 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -3,3 +3,6 @@ venv/ __pycache__/ *.out *.class +package.json +package-lock.json +node_modules diff --git a/example/main.py b/example/main.py index 5593ecd..853002b 100644 --- a/example/main.py +++ b/example/main.py @@ -21,6 +21,8 @@ def judge(path, language): filename = "main.go" elif language == river_pb2.Node: filename = "main.js" + elif language == river_pb2.TypeScript: + filename = "main.ts" with open(path.joinpath(filename), "rb") as fr: code = fr.read() with open(path.joinpath("in.txt"), "rb") as fr: @@ -46,41 +48,46 @@ def judge(path, language): def run(): with grpc.insecure_channel("localhost:4003") as channel: stub = river_pb2_grpc.RiverStub(channel) - # for path in Path("java").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.Java)): - # print(item) - # print(f"{path} 评测完成") - # for path in Path("c").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.C)): - # print(item) - # print(f"{path} 评测完成") - # for path in Path("cpp").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.Cpp)): - # print(item) - # print(f"{path} 评测完成") - # for path in Path("py").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.Python)): - # print(item) - # print(f"{path} 评测完成") - # for path in Path("rust").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.Rust)): - # print(item) - # print(f"{path} 评测完成") - # for path in Path("go").iterdir(): - # print(f"开始评测 {path}") - # for item in stub.Judge(judge(path, river_pb2.Go)): - # print(item) - # print(f"{path} 评测完成") + for path in Path("java").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Java)): + print(item) + print(f"{path} 评测完成") + for path in Path("c").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.C)): + print(item) + print(f"{path} 评测完成") + for path in Path("cpp").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Cpp)): + print(item) + print(f"{path} 评测完成") + for path in Path("py").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Python)): + print(item) + print(f"{path} 评测完成") + for path in Path("rust").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Rust)): + print(item) + print(f"{path} 评测完成") + for path in Path("go").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Go)): + print(item) + print(f"{path} 评测完成") for path in Path("node").iterdir(): print(f"开始评测 {path}") for item in stub.Judge(judge(path, river_pb2.Node)): print(item) print(f"{path} 评测完成") + for path in Path("ts").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.TypeScript)): + print(item) + print(f"{path} 评测完成") if __name__ == "__main__": diff --git a/example/ts/1000/.gitignore b/example/ts/1000/.gitignore new file mode 100644 index 0000000..a9b203a --- /dev/null +++ b/example/ts/1000/.gitignore @@ -0,0 +1 @@ +main.js diff --git a/example/ts/1000/in.txt b/example/ts/1000/in.txt new file mode 100644 index 0000000..e69de29 diff --git a/example/ts/1000/main.ts b/example/ts/1000/main.ts new file mode 100644 index 0000000..019c0f4 --- /dev/null +++ b/example/ts/1000/main.ts @@ -0,0 +1 @@ +console.log("Hello World!"); diff --git a/example/ts/1000/out.txt b/example/ts/1000/out.txt new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/example/ts/1000/out.txt @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/example/ts/1001/.gitignore b/example/ts/1001/.gitignore new file mode 100644 index 0000000..a9b203a --- /dev/null +++ b/example/ts/1001/.gitignore @@ -0,0 +1 @@ +main.js diff --git a/example/ts/1001/in.txt b/example/ts/1001/in.txt new file mode 100644 index 0000000..1ed0fb7 --- /dev/null +++ b/example/ts/1001/in.txt @@ -0,0 +1 @@ +2 3 \ No newline at end of file diff --git a/example/ts/1001/main.ts b/example/ts/1001/main.ts new file mode 100644 index 0000000..339521b --- /dev/null +++ b/example/ts/1001/main.ts @@ -0,0 +1,15 @@ +import * as readline from 'readline'; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.on('line', (line: string) => { + var nums = line.split(' '); + var a = parseInt(nums[0]); + var b = parseInt(nums[1]); + var res = a + b; + console.log(res); + process.exit(0); +}); diff --git a/example/ts/1001/out.txt b/example/ts/1001/out.txt new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/example/ts/1001/out.txt @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/plugins/build.sh b/plugins/build.sh index 5532af5..33f64ed 100755 --- a/plugins/build.sh +++ b/plugins/build.sh @@ -3,6 +3,10 @@ echo "Hello World!" # create judge dir mkdir -p /river/runner +# 运行的上层目录创建 node_modules,以便 Node 与 TypeScript 使用 +cd /river/runner +npm init -y +npm i @types/node cd /plugins/js npm install diff --git a/src/judger.rs b/src/judger.rs index 4e29d1f..24fc77f 100644 --- a/src/judger.rs +++ b/src/judger.rs @@ -42,7 +42,7 @@ pub async fn judger( Some(Language::Python) => "/usr/bin/python3.8 main.py", Some(Language::Rust) => "./a.out", Some(Language::Node) => "/usr/bin/node main.js", - Some(Language::TypeScript) => "node main.js", + Some(Language::TypeScript) => "/usr/bin/node main.js", Some(Language::Go) => "./a.out", Some(Language::Java) => "/usr/bin/java -cp . Main", None => return Err(Error::LanguageNotFound(request.language)),