mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
cli: merge with api-client
This commit is contained in:
parent
e5000917e8
commit
a1536ffe56
8 changed files with 28 additions and 102 deletions
|
@ -1,4 +1,4 @@
|
|||
const {PistonEngine} = require('piston-api-client');
|
||||
const fetch = require('node-fetch');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
|
@ -34,8 +34,6 @@ exports.builder = {
|
|||
|
||||
exports.handler = async function(argv){
|
||||
|
||||
const api = new PistonEngine(argv['piston-url']);
|
||||
|
||||
const files = [...(argv.files || []),argv.file]
|
||||
.map(file_path => ({
|
||||
name: path.basename(file_path),
|
||||
|
@ -50,7 +48,7 @@ exports.handler = async function(argv){
|
|||
})) || "";
|
||||
|
||||
|
||||
const response = await api.run_job({
|
||||
const request = {
|
||||
language: argv.language,
|
||||
version: argv['language-version'],
|
||||
files: files,
|
||||
|
@ -59,7 +57,16 @@ exports.handler = async function(argv){
|
|||
stdin,
|
||||
compile_timeout: argv.ct,
|
||||
run_timeout: argv.rt
|
||||
})
|
||||
};
|
||||
|
||||
const response = await fetch(argv['piston-url'] + '/jobs', {
|
||||
method: 'post',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(request)
|
||||
})
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)})
|
||||
.catch(x=>x);
|
||||
|
||||
function step(name, ctx){
|
||||
console.log(chalk.bold(`== ${name} ==`))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {PistonEngine} = require('piston-api-client');
|
||||
const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['install <language> <language-version>']
|
||||
|
@ -14,14 +14,14 @@ const msg_format = {
|
|||
}
|
||||
|
||||
exports.handler = async function(argv){
|
||||
const api = new PistonEngine(argv['piston-url']);
|
||||
const install = await fetch(
|
||||
`${argv['piston-url']}/packages/${argv['language']}/${argv['language-version']}`,
|
||||
{method: 'post'}
|
||||
)
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)})
|
||||
.catch(x=>x);
|
||||
|
||||
const opts = {
|
||||
language: argv['language'],
|
||||
version: argv['language-version']
|
||||
};
|
||||
|
||||
const install = await api.install_package(opts).catch(x=>x);
|
||||
|
||||
console.log(msg_format.color(install));
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
const {PistonEngine} = require('piston-api-client');
|
||||
const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['list']
|
||||
|
@ -18,6 +18,12 @@ exports.handler = async function(argv){
|
|||
|
||||
const packages = await api.list_packages();
|
||||
|
||||
const packages = await fetch(argv['piston-url'] + '/packages')
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)});
|
||||
.then(res=>res.packages)
|
||||
.catch(x=>x)
|
||||
|
||||
|
||||
const pkg_msg = packages
|
||||
.map(msg_format.color)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0",
|
||||
"piston-api-client": "file:../api-client",
|
||||
"node-fetch": "^2.6.1",
|
||||
"yargs": "^16.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,11 +73,6 @@ node-fetch@^2.6.1:
|
|||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
|
||||
"piston-api-client@file:../api-client":
|
||||
version "1.0.0"
|
||||
dependencies:
|
||||
node-fetch "^2.6.1"
|
||||
|
||||
require-directory@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue