mirror of
https://github.com/MeiK2333/river.git
synced 2025-11-04 14:49:40 +08:00
add js compiler
This commit is contained in:
parent
09890bd293
commit
6d7438a7d8
1
plugins/js/.gitignore
vendored
Normal file
1
plugins/js/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
5
plugins/js/README.md
Normal file
5
plugins/js/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
```bash
|
||||||
|
cd plugins/js
|
||||||
|
./validate.js success.js
|
||||||
|
./validate.js failure.js
|
||||||
|
```
|
||||||
6
plugins/js/failure.js
Normal file
6
plugins/js/failure.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
return 42; // should be inside a function
|
||||||
|
function f() {
|
||||||
|
'use strict';
|
||||||
|
var x = 042;
|
||||||
|
with (z) { }
|
||||||
|
}
|
||||||
11
plugins/js/package-lock.json
generated
Normal file
11
plugins/js/package-lock.json
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"requires": true,
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"dependencies": {
|
||||||
|
"esprima": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
plugins/js/success.js
Normal file
1
plugins/js/success.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log("Hello World!");
|
||||||
23
plugins/js/validate.js
Executable file
23
plugins/js/validate.js
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/local/bin/node
|
||||||
|
const fs = require('fs');
|
||||||
|
const esprima = require('esprima');
|
||||||
|
|
||||||
|
const file = process.argv[2];
|
||||||
|
const code = fs.readFileSync(file).toString();
|
||||||
|
|
||||||
|
const res = esprima.parseScript(code, { tolerant: true });
|
||||||
|
if (res.errors.length != 0) {
|
||||||
|
const split = code.split('\n');
|
||||||
|
for (const error of res.errors) {
|
||||||
|
console.error(split[error.lineNumber - 1]);
|
||||||
|
for (let i = 1; i < error.column; i++) {
|
||||||
|
process.stderr.write(' ');
|
||||||
|
}
|
||||||
|
console.error('^');
|
||||||
|
console.error(`${error.toString()}
|
||||||
|
at (${file}:${error.lineNumber}:${error.column})`);
|
||||||
|
console.error('--------------------------------------------------------------------------');
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
process.exit(0);
|
||||||
@ -35,6 +35,7 @@ pub async fn judger(
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Result<JudgeResponse> {
|
) -> Result<JudgeResponse> {
|
||||||
let mut resp = JudgeResponse::new();
|
let mut resp = JudgeResponse::new();
|
||||||
|
// TODO: 使用配置文件
|
||||||
let cmd = match Language::from_i32(request.language) {
|
let cmd = match Language::from_i32(request.language) {
|
||||||
Some(Language::C) => "./a.out",
|
Some(Language::C) => "./a.out",
|
||||||
Some(Language::Cpp) => "./a.out",
|
Some(Language::Cpp) => "./a.out",
|
||||||
@ -120,9 +121,8 @@ pub async fn compile(
|
|||||||
Some(Language::Cpp) => "/usr/bin/g++ main.cpp -O2 -Wall --static -o a.out --std=gnu++17",
|
Some(Language::Cpp) => "/usr/bin/g++ main.cpp -O2 -Wall --static -o a.out --std=gnu++17",
|
||||||
Some(Language::Python) => "/usr/bin/python3 -m compileall main.py",
|
Some(Language::Python) => "/usr/bin/python3 -m compileall main.py",
|
||||||
Some(Language::Rust) => "/usr/bin/rustc main.rs -o a.out -C opt-level=2",
|
Some(Language::Rust) => "/usr/bin/rustc main.rs -o a.out -C opt-level=2",
|
||||||
// TODO: eslint......
|
Some(Language::Node) => "validate.js main.js",
|
||||||
Some(Language::Node) => "/bin/echo hello",
|
Some(Language::TypeScript) => "/usr/bin/tsc main.ts",
|
||||||
Some(Language::TypeScript) => "/usr/bin/tsc",
|
|
||||||
Some(Language::Go) => "/usr/bin/go build -ldflags \"-s -w\" main.go",
|
Some(Language::Go) => "/usr/bin/go build -ldflags \"-s -w\" main.go",
|
||||||
None => return Err(Error::LanguageNotFound(request.language)),
|
None => return Err(Error::LanguageNotFound(request.language)),
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user