UNPKG

gitarsenal-cli

Version:

CLI tool for creating Modal sandboxes with GitHub repositories

130 lines (114 loc) 3.09 kB
const { promisify } = require('util'); const { exec } = require('child_process'); const which = require('which'); const chalk = require('chalk'); const execAsync = promisify(exec); /** * Check if a command is available in the system * @param {string} command - Command to check * @returns {Promise<boolean>} - True if command exists */ async function commandExists(command) { try { await which(command); return true; } catch (error) { return false; } } /** * Check Python version * @returns {Promise<{exists: boolean, version: string|null}>} */ async function checkPython() { try { const { stdout } = await execAsync('python --version'); const version = stdout.trim().split(' ')[1]; return { exists: true, version }; } catch (error) { try { const { stdout } = await execAsync('python3 --version'); const version = stdout.trim().split(' ')[1]; return { exists: true, version }; } catch (error) { return { exists: false, version: null }; } } } /** * Check if Modal is installed * @returns {Promise<boolean>} */ async function checkModal() { try { await execAsync('modal --version'); return true; } catch (error) { return false; } } /** * Check if Git is installed * @returns {Promise<boolean>} */ async function checkGit() { try { await execAsync('git --version'); return true; } catch (error) { return false; } } async function checkGitingest() { try { await execAsync('gitingest --help'); return true; } catch (error) { return false; } } /** * Check all required dependencies * @returns {Promise<boolean>} - True if all dependencies are met */ async function checkDependencies() { const pythonCheck = await checkPython(); const modalExists = await checkModal(); const gitExists = await checkGit(); const gitingestExists = await checkGitingest(); let allDependenciesMet = true; console.log('\n--- Dependency Check ---'); if (pythonCheck.exists) { console.log(`${chalk.green('✓')} Python ${pythonCheck.version} found`); } else { console.log(`${chalk.red('✗')} Python not found. Please install Python 3.8 or newer.`); allDependenciesMet = false; } if (modalExists) { console.log(`${chalk.green('✓')} Modal CLI found`); } else { console.log(`${chalk.red('✗')} Modal CLI not found. Please install it with: pip install modal`); allDependenciesMet = false; } if (gitingestExists) { console.log(`${chalk.green('✓')} Gitingest CLI found`); } else { console.log(`${chalk.red('✗')} Gitingest CLI not found. Please install it with: pip install gitingest`); allDependenciesMet = false; } if (gitExists) { console.log(`${chalk.green('✓')} Git found`); } else { console.log(`${chalk.red('✗')} Git not found. Please install Git.`); allDependenciesMet = false; } console.log('------------------------\n'); return allDependenciesMet; } module.exports = { checkDependencies, commandExists, checkPython, checkModal, checkGit };