mirror of
https://github.com/engineer-man/piston.git
synced 2025-06-07 10:46:27 +02:00
Add CLI written in Node
This commit is contained in:
parent
d666e5c19d
commit
d8b6379b9a
9 changed files with 321 additions and 192 deletions
3
cli/execute
Executable file
3
cli/execute
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
node src $*
|
12
cli/package.json
Normal file
12
cli/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "cli",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
30
cli/src/index.js
Normal file
30
cli/src/index.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const { execute } = require('../../shared/execute');
|
||||
const { readFileSync } = require('fs');
|
||||
const languages = require('../../shared/languages.json');
|
||||
|
||||
const [languageName, sourceFile, ...args] = process.argv.slice(2);
|
||||
|
||||
(async () => {
|
||||
if (!languageName) {
|
||||
console.error('Provide a language name');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sourceFile) {
|
||||
console.error('Provide a source file');
|
||||
return;
|
||||
}
|
||||
|
||||
const source = readFileSync(sourceFile);
|
||||
|
||||
const language = languages.find(language => language.name === languageName);
|
||||
|
||||
if (!language) {
|
||||
console.error(`${languageName} is not supported by Piston`);
|
||||
return;
|
||||
}
|
||||
|
||||
const { output } = await execute(language, source, args);
|
||||
|
||||
console.log(output);
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue