add language: TypeScript

This commit is contained in:
MeiK2333 2020-11-05 20:51:10 +08:00
parent a162ed4e43
commit a2f016a66c
14 changed files with 74 additions and 31 deletions

2
.gitignore vendored
View File

@ -12,3 +12,5 @@ Cargo.lock
.idea
.vscode
.devcontainer
nohup.out

View File

@ -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/*

3
example/.gitignore vendored
View File

@ -3,3 +3,6 @@ venv/
__pycache__/
*.out
*.class
package.json
package-lock.json
node_modules

View File

@ -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__":

1
example/ts/1000/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
main.js

0
example/ts/1000/in.txt Normal file
View File

1
example/ts/1000/main.ts Normal file
View File

@ -0,0 +1 @@
console.log("Hello World!");

1
example/ts/1000/out.txt Normal file
View File

@ -0,0 +1 @@
Hello World!

1
example/ts/1001/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
main.js

1
example/ts/1001/in.txt Normal file
View File

@ -0,0 +1 @@
2 3

15
example/ts/1001/main.ts Normal file
View File

@ -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);
});

1
example/ts/1001/out.txt Normal file
View File

@ -0,0 +1 @@
5

View File

@ -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

View File

@ -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)),