2021-02-27 07:30:11 +01:00
|
|
|
const chalk = require('chalk');
|
|
|
|
|
2021-06-05 09:34:43 +02:00
|
|
|
exports.command = ['install <packages...>'];
|
2021-05-07 21:22:25 +02:00
|
|
|
exports.aliases = ['i'];
|
|
|
|
exports.describe = 'Installs the named package';
|
2021-02-27 07:30:11 +01:00
|
|
|
|
2021-06-05 09:20:06 +02:00
|
|
|
//Splits the package into it's language and version
|
|
|
|
function split_package(package) {
|
2021-10-08 15:16:57 +02:00
|
|
|
[language, language_version] = package.split('=');
|
2021-06-05 09:20:06 +02:00
|
|
|
|
|
|
|
res = {
|
|
|
|
language: language,
|
2021-10-08 15:16:57 +02:00
|
|
|
version: language_version || '*',
|
2021-06-05 09:20:06 +02:00
|
|
|
};
|
2021-10-08 15:16:57 +02:00
|
|
|
return res;
|
2021-06-05 09:20:06 +02:00
|
|
|
}
|
|
|
|
|
2021-02-27 07:30:11 +01:00
|
|
|
const msg_format = {
|
2021-10-08 15:16:57 +02:00
|
|
|
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-05-07 21:22:25 +02:00
|
|
|
};
|
2021-02-27 07:30:11 +01:00
|
|
|
|
2021-06-05 09:20:06 +02:00
|
|
|
exports.handler = async ({ axios, packages }) => {
|
|
|
|
const requests = packages.map(package => split_package(package));
|
2023-03-09 02:59:43 +01:00
|
|
|
for (const request of requests) {
|
2021-06-05 09:20:06 +02:00
|
|
|
try {
|
|
|
|
const install = await axios.post(`/api/v2/packages`, request);
|
2021-04-23 01:43:21 +02:00
|
|
|
|
2021-06-05 09:20:06 +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-10-08 15:16:57 +02:00
|
|
|
};
|