mirror of
https://github.com/ivabus/gui
synced 2025-04-24 14:37:11 +03:00
29 lines
771 B
TypeScript
29 lines
771 B
TypeScript
import { spawn } from 'child_process';
|
|
import { clean } from 'semver';
|
|
|
|
export async function installPackage(full_name: string) {
|
|
return await new Promise((resolve, reject) => {
|
|
let version = '';
|
|
let lastError = '';
|
|
const teaInstallation = spawn('tea', [`+${full_name}`, 'true']);
|
|
|
|
teaInstallation.stdout.on('data', (data) => {
|
|
console.log('stdout:', data);
|
|
});
|
|
|
|
teaInstallation.stderr.on('data', (err) => {
|
|
lastError = err.toString();
|
|
if (lastError && lastError.includes('installed') && lastError.includes(full_name)) {
|
|
version = lastError.split('/').pop() || '';
|
|
}
|
|
});
|
|
|
|
teaInstallation.on('exit', (code) => {
|
|
if (code === 0) {
|
|
resolve({ version: clean(version) });
|
|
} else {
|
|
reject(new Error(lastError));
|
|
}
|
|
});
|
|
});
|
|
}
|