piston/cli/commands/ppman_commands/install.js

40 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-02-27 07:30:11 +01:00
const chalk = require('chalk');
exports.command = ['install <packages...>'];
exports.aliases = ['i'];
exports.describe = 'Installs the named package';
2021-02-27 07:30:11 +01:00
//Splits the package into it's language and version
function split_package(package) {
[language, language_version] = package.split("=")
res = {
language: language,
version: language_version || "*"
};
return res
}
2021-02-27 07:30:11 +01:00
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
};
2021-02-27 07:30:11 +01:00
exports.handler = async ({ axios, packages }) => {
const requests = packages.map(package => split_package(package));
for (request of requests) {
try {
2021-05-08 02:57:37 +02:00
const install = await axios.post(`/api/v2/packages`, request);
2021-04-23 01:43:21 +02:00
console.log(msg_format.color(install.data));
} catch ({ response }) {
console.error(response.data.message);
}
2021-03-13 04:44:33 +01:00
}
2021-04-23 01:43:21 +02:00
}