mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
Piston lint
This commit is contained in:
parent
d61fb8ec5b
commit
f2c91acbe6
57 changed files with 1121 additions and 893 deletions
|
@ -3,8 +3,44 @@ const path = require('path');
|
|||
const chalk = require('chalk');
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const SIGNALS = ["SIGABRT","SIGALRM","SIGBUS","SIGCHLD","SIGCLD","SIGCONT","SIGEMT","SIGFPE","SIGHUP","SIGILL","SIGINFO","SIGINT","SIGIO","SIGIOT","SIGLOST","SIGPIPE","SIGPOLL","SIGPROF","SIGPWR","SIGQUIT","SIGSEGV","SIGSTKFLT","SIGTSTP","SIGSYS","SIGTERM","SIGTRAP","SIGTTIN","SIGTTOU","SIGUNUSED","SIGURG","SIGUSR1","SIGUSR2","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGWINCH"]
|
||||
|
||||
const SIGNALS = [
|
||||
'SIGABRT',
|
||||
'SIGALRM',
|
||||
'SIGBUS',
|
||||
'SIGCHLD',
|
||||
'SIGCLD',
|
||||
'SIGCONT',
|
||||
'SIGEMT',
|
||||
'SIGFPE',
|
||||
'SIGHUP',
|
||||
'SIGILL',
|
||||
'SIGINFO',
|
||||
'SIGINT',
|
||||
'SIGIO',
|
||||
'SIGIOT',
|
||||
'SIGLOST',
|
||||
'SIGPIPE',
|
||||
'SIGPOLL',
|
||||
'SIGPROF',
|
||||
'SIGPWR',
|
||||
'SIGQUIT',
|
||||
'SIGSEGV',
|
||||
'SIGSTKFLT',
|
||||
'SIGTSTP',
|
||||
'SIGSYS',
|
||||
'SIGTERM',
|
||||
'SIGTRAP',
|
||||
'SIGTTIN',
|
||||
'SIGTTOU',
|
||||
'SIGUNUSED',
|
||||
'SIGURG',
|
||||
'SIGUSR1',
|
||||
'SIGUSR2',
|
||||
'SIGVTALRM',
|
||||
'SIGXCPU',
|
||||
'SIGXFSZ',
|
||||
'SIGWINCH',
|
||||
];
|
||||
|
||||
exports.command = ['execute <language> <file> [args..]'];
|
||||
exports.aliases = ['run'];
|
||||
|
@ -15,18 +51,18 @@ exports.builder = {
|
|||
string: true,
|
||||
desc: 'Set the version of the language to use',
|
||||
alias: ['l'],
|
||||
default: '*'
|
||||
default: '*',
|
||||
},
|
||||
stdin: {
|
||||
boolean: true,
|
||||
desc: 'Read input from stdin and pass to executor',
|
||||
alias: ['i']
|
||||
alias: ['i'],
|
||||
},
|
||||
run_timeout: {
|
||||
alias: ['rt', 'r'],
|
||||
number: true,
|
||||
desc: 'Milliseconds before killing run process',
|
||||
default: 3000
|
||||
default: 3000,
|
||||
},
|
||||
compile_timeout: {
|
||||
alias: ['ct', 'c'],
|
||||
|
@ -42,117 +78,126 @@ exports.builder = {
|
|||
interactive: {
|
||||
boolean: true,
|
||||
alias: ['t'],
|
||||
desc: 'Run interactively using WebSocket transport'
|
||||
desc: 'Run interactively using WebSocket transport',
|
||||
},
|
||||
status: {
|
||||
boolean: true,
|
||||
alias: ['s'],
|
||||
desc: 'Output additional status to stderr'
|
||||
}
|
||||
desc: 'Output additional status to stderr',
|
||||
},
|
||||
};
|
||||
|
||||
async function handle_interactive(files, argv){
|
||||
const ws = new WebSocket(argv.pistonUrl.replace("http", "ws") + "/api/v2/connect")
|
||||
async function handle_interactive(files, argv) {
|
||||
const ws = new WebSocket(
|
||||
argv.pistonUrl.replace('http', 'ws') + '/api/v2/connect'
|
||||
);
|
||||
|
||||
const log_message = (process.stderr.isTTY && argv.status) ? console.error : ()=>{};
|
||||
const log_message =
|
||||
process.stderr.isTTY && argv.status ? console.error : () => {};
|
||||
|
||||
process.on("exit", ()=>{
|
||||
process.on('exit', () => {
|
||||
ws.close();
|
||||
process.stdin.end();
|
||||
process.stdin.destroy();
|
||||
process.exit();
|
||||
})
|
||||
process.exit();
|
||||
});
|
||||
|
||||
for(const signal of SIGNALS){
|
||||
process.on(signal, ()=>{
|
||||
ws.send(JSON.stringify({type: 'signal', signal}))
|
||||
})
|
||||
for (const signal of SIGNALS) {
|
||||
process.on(signal, () => {
|
||||
ws.send(JSON.stringify({ type: 'signal', signal }));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
ws.on('open', ()=>{
|
||||
ws.on('open', () => {
|
||||
const request = {
|
||||
type: "init",
|
||||
type: 'init',
|
||||
language: argv.language,
|
||||
version: argv['language_version'],
|
||||
files: files,
|
||||
args: argv.args,
|
||||
compile_timeout: argv.ct,
|
||||
run_timeout: argv.rt
|
||||
}
|
||||
run_timeout: argv.rt,
|
||||
};
|
||||
|
||||
ws.send(JSON.stringify(request))
|
||||
log_message(chalk.white.bold("Connected"))
|
||||
ws.send(JSON.stringify(request));
|
||||
log_message(chalk.white.bold('Connected'));
|
||||
|
||||
process.stdin.resume();
|
||||
|
||||
process.stdin.on("data", (data) => {
|
||||
ws.send(JSON.stringify({
|
||||
type: "data",
|
||||
stream: "stdin",
|
||||
data: data.toString()
|
||||
}))
|
||||
})
|
||||
})
|
||||
process.stdin.on('data', data => {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: 'data',
|
||||
stream: 'stdin',
|
||||
data: data.toString(),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
ws.on("close", (code, reason)=>{
|
||||
ws.on('close', (code, reason) => {
|
||||
log_message(
|
||||
chalk.white.bold("Disconnected: "),
|
||||
chalk.white.bold("Reason: "),
|
||||
chalk.white.bold('Disconnected: '),
|
||||
chalk.white.bold('Reason: '),
|
||||
chalk.yellow(`"${reason}"`),
|
||||
chalk.white.bold("Code: "),
|
||||
chalk.yellow(`"${code}"`),
|
||||
)
|
||||
process.stdin.pause()
|
||||
})
|
||||
chalk.white.bold('Code: '),
|
||||
chalk.yellow(`"${code}"`)
|
||||
);
|
||||
process.stdin.pause();
|
||||
});
|
||||
|
||||
ws.on('message', function(data){
|
||||
ws.on('message', function (data) {
|
||||
const msg = JSON.parse(data);
|
||||
|
||||
switch(msg.type){
|
||||
case "runtime":
|
||||
log_message(chalk.bold.white("Runtime:"), chalk.yellow(`${msg.language} ${msg.version}`))
|
||||
|
||||
switch (msg.type) {
|
||||
case 'runtime':
|
||||
log_message(
|
||||
chalk.bold.white('Runtime:'),
|
||||
chalk.yellow(`${msg.language} ${msg.version}`)
|
||||
);
|
||||
break;
|
||||
case "stage":
|
||||
log_message(chalk.bold.white("Stage:"), chalk.yellow(msg.stage))
|
||||
case 'stage':
|
||||
log_message(
|
||||
chalk.bold.white('Stage:'),
|
||||
chalk.yellow(msg.stage)
|
||||
);
|
||||
break;
|
||||
case "data":
|
||||
if(msg.stream == "stdout") process.stdout.write(msg.data)
|
||||
else if(msg.stream == "stderr") process.stderr.write(msg.data)
|
||||
else log_message(chalk.bold.red(`(${msg.stream}) `), msg.data)
|
||||
case 'data':
|
||||
if (msg.stream == 'stdout') process.stdout.write(msg.data);
|
||||
else if (msg.stream == 'stderr') process.stderr.write(msg.data);
|
||||
else log_message(chalk.bold.red(`(${msg.stream}) `), msg.data);
|
||||
break;
|
||||
case "exit":
|
||||
if(msg.signal === null)
|
||||
case 'exit':
|
||||
if (msg.signal === null)
|
||||
log_message(
|
||||
chalk.white.bold("Stage"),
|
||||
chalk.white.bold('Stage'),
|
||||
chalk.yellow(msg.stage),
|
||||
chalk.white.bold("exited with code"),
|
||||
chalk.white.bold('exited with code'),
|
||||
chalk.yellow(msg.code)
|
||||
)
|
||||
);
|
||||
else
|
||||
log_message(
|
||||
chalk.white.bold("Stage"),
|
||||
chalk.white.bold('Stage'),
|
||||
chalk.yellow(msg.stage),
|
||||
chalk.white.bold("exited with signal"),
|
||||
chalk.white.bold('exited with signal'),
|
||||
chalk.yellow(msg.signal)
|
||||
)
|
||||
break;
|
||||
);
|
||||
break;
|
||||
default:
|
||||
log_message(chalk.red.bold("Unknown message:"), msg)
|
||||
log_message(chalk.red.bold('Unknown message:'), msg);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
async function run_non_interactively(files, argv) {
|
||||
|
||||
|
||||
const stdin = (argv.stdin && await new Promise((resolve, _) => {
|
||||
let data = '';
|
||||
process.stdin.on('data', d => data += d);
|
||||
process.stdin.on('end', _ => resolve(data));
|
||||
})) || '';
|
||||
const stdin =
|
||||
(argv.stdin &&
|
||||
(await new Promise((resolve, _) => {
|
||||
let data = '';
|
||||
process.stdin.on('data', d => (data += d));
|
||||
process.stdin.on('end', _ => resolve(data));
|
||||
}))) ||
|
||||
'';
|
||||
|
||||
const request = {
|
||||
language: argv.language,
|
||||
|
@ -161,7 +206,7 @@ async function run_non_interactively(files, argv) {
|
|||
args: argv.args,
|
||||
stdin,
|
||||
compile_timeout: argv.ct,
|
||||
run_timeout: argv.rt
|
||||
run_timeout: argv.rt,
|
||||
};
|
||||
|
||||
let { data: response } = await argv.axios.post('/api/v2/execute', request);
|
||||
|
@ -170,13 +215,13 @@ async function run_non_interactively(files, argv) {
|
|||
console.log(chalk.bold(`== ${name} ==`));
|
||||
|
||||
if (ctx.stdout) {
|
||||
console.log(chalk.bold(`STDOUT`))
|
||||
console.log(ctx.stdout.replace(/\n/g,'\n '))
|
||||
console.log(chalk.bold(`STDOUT`));
|
||||
console.log(ctx.stdout.replace(/\n/g, '\n '));
|
||||
}
|
||||
|
||||
if (ctx.stderr) {
|
||||
console.log(chalk.bold(`STDERR`))
|
||||
console.log(ctx.stderr.replace(/\n/g,'\n '))
|
||||
console.log(chalk.bold(`STDERR`));
|
||||
console.log(ctx.stderr.replace(/\n/g, '\n '));
|
||||
}
|
||||
|
||||
if (ctx.code) {
|
||||
|
@ -187,12 +232,9 @@ async function run_non_interactively(files, argv) {
|
|||
}
|
||||
|
||||
if (ctx.signal) {
|
||||
console.log(
|
||||
chalk.bold(`Signal:`),
|
||||
chalk.bold.yellow(ctx.signal)
|
||||
);
|
||||
console.log(chalk.bold(`Signal:`), chalk.bold.yellow(ctx.signal));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (response.compile) {
|
||||
step('Compile', response.compile);
|
||||
|
@ -201,17 +243,14 @@ async function run_non_interactively(files, argv) {
|
|||
step('Run', response.run);
|
||||
}
|
||||
|
||||
exports.handler = async (argv) => {
|
||||
const files = [...(argv.files || []),argv.file]
|
||||
.map(file_path => {
|
||||
return {
|
||||
name: path.basename(file_path),
|
||||
content: fs.readFileSync(file_path).toString()
|
||||
};
|
||||
});
|
||||
exports.handler = async argv => {
|
||||
const files = [...(argv.files || []), argv.file].map(file_path => {
|
||||
return {
|
||||
name: path.basename(file_path),
|
||||
content: fs.readFileSync(file_path).toString(),
|
||||
};
|
||||
});
|
||||
|
||||
if(argv.interactive) await handle_interactive(files, argv);
|
||||
if (argv.interactive) await handle_interactive(files, argv);
|
||||
else await run_non_interactively(files, argv);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -2,6 +2,4 @@ exports.command = 'ppman';
|
|||
exports.aliases = ['pkg'];
|
||||
exports.describe = 'Package Manager';
|
||||
|
||||
exports.builder = yargs => yargs
|
||||
.commandDir('ppman_commands')
|
||||
.demandCommand();
|
||||
exports.builder = yargs => yargs.commandDir('ppman_commands').demandCommand();
|
||||
|
|
|
@ -4,30 +4,31 @@ exports.command = ['install <packages...>'];
|
|||
exports.aliases = ['i'];
|
||||
exports.describe = 'Installs the named package';
|
||||
|
||||
|
||||
|
||||
//Splits the package into it's language and version
|
||||
function split_package(package) {
|
||||
[language, language_version] = package.split("=")
|
||||
[language, language_version] = package.split('=');
|
||||
|
||||
res = {
|
||||
language: language,
|
||||
version: language_version || "*"
|
||||
version: language_version || '*',
|
||||
};
|
||||
return res
|
||||
return res;
|
||||
}
|
||||
|
||||
const msg_format = {
|
||||
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p => `Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify
|
||||
color: p =>
|
||||
`${
|
||||
p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')
|
||||
} Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p =>
|
||||
`Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify,
|
||||
};
|
||||
|
||||
exports.handler = async ({ axios, packages }) => {
|
||||
const requests = packages.map(package => split_package(package));
|
||||
for (request of requests) {
|
||||
try {
|
||||
|
||||
const install = await axios.post(`/api/v2/packages`, request);
|
||||
|
||||
console.log(msg_format.color(install.data));
|
||||
|
@ -35,5 +36,4 @@ exports.handler = async ({ axios, packages }) => {
|
|||
console.error(response.data.message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,17 +5,21 @@ exports.aliases = ['l'];
|
|||
exports.describe = 'Lists all available packages';
|
||||
|
||||
const msg_format = {
|
||||
color: p => `${chalk[p.installed ? 'green':'red']('•')} ${p.language} ${p.language_version}`,
|
||||
monochrome: p => `${p.language} ${p.language_version} ${p.installed ? '(INSTALLED)': ''}`,
|
||||
json: JSON.stringify
|
||||
color: p =>
|
||||
`${chalk[p.installed ? 'green' : 'red']('•')} ${p.language} ${
|
||||
p.language_version
|
||||
}`,
|
||||
monochrome: p =>
|
||||
`${p.language} ${p.language_version} ${
|
||||
p.installed ? '(INSTALLED)' : ''
|
||||
}`,
|
||||
json: JSON.stringify,
|
||||
};
|
||||
|
||||
exports.handler = async ({ axios }) => {
|
||||
const packages = await axios.get('/api/v2/packages');
|
||||
|
||||
const pkg_msg = packages.data
|
||||
.map(msg_format.color)
|
||||
.join('\n');
|
||||
const pkg_msg = packages.data.map(msg_format.color).join('\n');
|
||||
|
||||
console.log(pkg_msg);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,49 +1,53 @@
|
|||
const chalk = require('chalk');
|
||||
const fs = require('fs/promises');
|
||||
const minimatch = require("minimatch");
|
||||
const minimatch = require('minimatch');
|
||||
const semver = require('semver');
|
||||
|
||||
exports.command = ['spec <specfile>'];
|
||||
exports.aliases = ['s'];
|
||||
exports.describe = 'Install the packages described in the spec file, uninstalling packages which aren\'t in the list'
|
||||
exports.describe =
|
||||
"Install the packages described in the spec file, uninstalling packages which aren't in the list";
|
||||
|
||||
function does_match(package, rule){
|
||||
function does_match(package, rule) {
|
||||
const nameMatch = minimatch(package.language, rule.package_selector);
|
||||
const versionMatch = semver.satisfies(package.language_version, rule.version_selector)
|
||||
const versionMatch = semver.satisfies(
|
||||
package.language_version,
|
||||
rule.version_selector
|
||||
);
|
||||
|
||||
return nameMatch && versionMatch;
|
||||
}
|
||||
|
||||
exports.handler = async ({axios, specfile}) => {
|
||||
exports.handler = async ({ axios, specfile }) => {
|
||||
const spec_contents = await fs.readFile(specfile);
|
||||
const spec_lines = spec_contents.toString().split("\n");
|
||||
const spec_lines = spec_contents.toString().split('\n');
|
||||
|
||||
const rules = [];
|
||||
|
||||
for(const line of spec_lines){
|
||||
for (const line of spec_lines) {
|
||||
const rule = {
|
||||
_raw: line.trim(),
|
||||
comment: false,
|
||||
package_selector: null,
|
||||
version_selector: null,
|
||||
negate: false
|
||||
negate: false,
|
||||
};
|
||||
|
||||
if(line.starts_with("#")){
|
||||
if (line.starts_with('#')) {
|
||||
rule.comment = true;
|
||||
}else {
|
||||
} else {
|
||||
let l = line.trim();
|
||||
if(line.starts_with("!")){
|
||||
if (line.starts_with('!')) {
|
||||
rule.negate = true;
|
||||
l = line.slice(1).trim();
|
||||
}
|
||||
|
||||
const [pkg, ver] = l.split(" ", 2);
|
||||
const [pkg, ver] = l.split(' ', 2);
|
||||
rule.package_selector = pkg;
|
||||
rule.version_selector = ver;
|
||||
}
|
||||
|
||||
if(rule._raw.length != 0) rules.push(rule);
|
||||
if (rule._raw.length != 0) rules.push(rule);
|
||||
}
|
||||
|
||||
const packages_req = await axios.get('/api/v2/packages');
|
||||
|
@ -53,108 +57,127 @@ exports.handler = async ({axios, specfile}) => {
|
|||
|
||||
let ensure_packages = [];
|
||||
|
||||
for(const rule of rules){
|
||||
if(rule.comment) continue;
|
||||
for (const rule of rules) {
|
||||
if (rule.comment) continue;
|
||||
|
||||
const matches = [];
|
||||
|
||||
if(!rule.negate){
|
||||
for(const package of packages){
|
||||
if(does_match(package, rule))
|
||||
matches.push(package)
|
||||
if (!rule.negate) {
|
||||
for (const package of packages) {
|
||||
if (does_match(package, rule)) matches.push(package);
|
||||
}
|
||||
|
||||
const latest_matches = matches.filter(
|
||||
pkg => {
|
||||
const versions = matches
|
||||
.filter(x=>x.language == pkg.language)
|
||||
.map(x=>x.language_version).sort(semver.rcompare);
|
||||
return versions[0] == pkg.language_version
|
||||
}
|
||||
);
|
||||
const latest_matches = matches.filter(pkg => {
|
||||
const versions = matches
|
||||
.filter(x => x.language == pkg.language)
|
||||
.map(x => x.language_version)
|
||||
.sort(semver.rcompare);
|
||||
return versions[0] == pkg.language_version;
|
||||
});
|
||||
|
||||
for(const match of latest_matches){
|
||||
if(!ensure_packages.find(pkg => pkg.language == match.language && pkg.language_version == match.language_version))
|
||||
ensure_packages.push(match)
|
||||
for (const match of latest_matches) {
|
||||
if (
|
||||
!ensure_packages.find(
|
||||
pkg =>
|
||||
pkg.language == match.language &&
|
||||
pkg.language_version == match.language_version
|
||||
)
|
||||
)
|
||||
ensure_packages.push(match);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
ensure_packages = ensure_packages.filter(
|
||||
pkg => !does_match(pkg, rule)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const operations = [];
|
||||
|
||||
for(const package of ensure_packages){
|
||||
if(!package.installed)
|
||||
for (const package of ensure_packages) {
|
||||
if (!package.installed)
|
||||
operations.push({
|
||||
type: "install",
|
||||
type: 'install',
|
||||
package: package.language,
|
||||
version: package.language_version
|
||||
version: package.language_version,
|
||||
});
|
||||
}
|
||||
|
||||
for(const installed_package of installed){
|
||||
if(!ensure_packages.find(
|
||||
pkg => pkg.language == installed_package.language &&
|
||||
pkg.language_version == installed_package.language_version
|
||||
))
|
||||
for (const installed_package of installed) {
|
||||
if (
|
||||
!ensure_packages.find(
|
||||
pkg =>
|
||||
pkg.language == installed_package.language &&
|
||||
pkg.language_version == installed_package.language_version
|
||||
)
|
||||
)
|
||||
operations.push({
|
||||
type: "uninstall",
|
||||
type: 'uninstall',
|
||||
package: installed_package.language,
|
||||
version: installed_package.language_version
|
||||
})
|
||||
version: installed_package.language_version,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(chalk.bold.yellow("Actions"))
|
||||
for(const op of operations){
|
||||
console.log((op.type == "install" ? chalk.green("Install") : chalk.red("Uninstall")) + ` ${op.package} ${op.version}`)
|
||||
console.log(chalk.bold.yellow('Actions'));
|
||||
for (const op of operations) {
|
||||
console.log(
|
||||
(op.type == 'install'
|
||||
? chalk.green('Install')
|
||||
: chalk.red('Uninstall')) + ` ${op.package} ${op.version}`
|
||||
);
|
||||
}
|
||||
|
||||
if(operations.length == 0){
|
||||
console.log(chalk.gray("None"))
|
||||
if (operations.length == 0) {
|
||||
console.log(chalk.gray('None'));
|
||||
}
|
||||
|
||||
for(const op of operations){
|
||||
if(op.type == "install"){
|
||||
try{
|
||||
for (const op of operations) {
|
||||
if (op.type == 'install') {
|
||||
try {
|
||||
const install = await axios.post(`/api/v2/packages`, {
|
||||
language: op.package,
|
||||
version: op.version
|
||||
version: op.version,
|
||||
});
|
||||
|
||||
if(!install.data.language)
|
||||
if (!install.data.language)
|
||||
throw new Error(install.data.message); // Go to exception handler
|
||||
|
||||
console.log(chalk.bold.green("Installed"), op.package, op.version)
|
||||
|
||||
}catch(e){
|
||||
console.log(chalk.bold.red("Failed to install") + ` ${op.package} ${op.version}:`, e.message)
|
||||
console.log(
|
||||
chalk.bold.green('Installed'),
|
||||
op.package,
|
||||
op.version
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
chalk.bold.red('Failed to install') +
|
||||
` ${op.package} ${op.version}:`,
|
||||
e.message
|
||||
);
|
||||
}
|
||||
}
|
||||
else if(op.type == "uninstall"){
|
||||
try{
|
||||
} else if (op.type == 'uninstall') {
|
||||
try {
|
||||
const install = await axios.delete(`/api/v2/packages`, {
|
||||
data: {
|
||||
language: op.package,
|
||||
version: op.version
|
||||
}
|
||||
version: op.version,
|
||||
},
|
||||
});
|
||||
|
||||
if(!install.data.language)
|
||||
if (!install.data.language)
|
||||
throw new Error(install.data.message); // Go to exception handler
|
||||
|
||||
console.log(chalk.bold.green("Uninstalled"), op.package, op.version)
|
||||
|
||||
}catch(e){
|
||||
console.log(chalk.bold.red("Failed to uninstall") + ` ${op.package} ${op.version}:`, e.message)
|
||||
console.log(
|
||||
chalk.bold.green('Uninstalled'),
|
||||
op.package,
|
||||
op.version
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
chalk.bold.red('Failed to uninstall') +
|
||||
` ${op.package} ${op.version}:`,
|
||||
e.message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,31 +6,36 @@ exports.describe = 'Uninstalls the named package';
|
|||
|
||||
//Splits the package into it's language and version
|
||||
function split_package(package) {
|
||||
[language, language_version] = package.split("=")
|
||||
[language, language_version] = package.split('=');
|
||||
|
||||
res = {
|
||||
language: language,
|
||||
version: language_version || "*"
|
||||
version: language_version || '*',
|
||||
};
|
||||
return res
|
||||
return res;
|
||||
}
|
||||
|
||||
const msg_format = {
|
||||
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p => `Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify
|
||||
color: p =>
|
||||
`${
|
||||
p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')
|
||||
} Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p =>
|
||||
`Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify,
|
||||
};
|
||||
|
||||
exports.handler = async ({ axios, packages }) => {
|
||||
const requests = packages.map(package => split_package(package));
|
||||
for (request of requests) {
|
||||
try {
|
||||
|
||||
const uninstall = await axios.delete(`/api/v2/packages`, { data: request });
|
||||
const uninstall = await axios.delete(`/api/v2/packages`, {
|
||||
data: request,
|
||||
});
|
||||
|
||||
console.log(msg_format.color(uninstall.data));
|
||||
} catch ({ response }) {
|
||||
console.error(response.data.message)
|
||||
console.error(response.data.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue