2021-04-10 06:10:18 +02:00
|
|
|
const chalk = require('chalk');
|
|
|
|
|
2021-06-05 09:20:06 +02:00
|
|
|
exports.command = ['uninstall <packages...>'];
|
2021-05-07 21:22:25 +02:00
|
|
|
exports.aliases = ['u'];
|
|
|
|
exports.describe = 'Uninstalls the named package';
|
2021-04-10 06:10:18 +02:00
|
|
|
|
2021-06-05 09:20:06 +02: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-04-10 06:10:18 +02:00
|
|
|
const msg_format = {
|
2021-05-07 21:22:25 +02:00
|
|
|
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
|
|
|
|
};
|
2021-04-10 06:10:18 +02:00
|
|
|
|
2021-06-05 09:20:06 +02:00
|
|
|
exports.handler = async ({ axios, packages }) => {
|
|
|
|
const requests = packages.map(package => split_package(package));
|
|
|
|
for (request of requests) {
|
|
|
|
try {
|
2021-04-23 01:43:21 +02:00
|
|
|
|
2021-06-05 09:20:06 +02:00
|
|
|
const uninstall = await axios.delete(`/api/v2/packages`, { data: request });
|
|
|
|
|
|
|
|
console.log(msg_format.color(uninstall.data));
|
|
|
|
} catch ({ response }) {
|
|
|
|
console.error(response.data.message)
|
|
|
|
}
|
2021-04-10 06:10:18 +02:00
|
|
|
}
|
2021-06-05 09:20:06 +02:00
|
|
|
}
|