UNPKG

@starship-ci/client

Version:
85 lines (84 loc) 3.57 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StarshipInstaller = void 0; const chalk_1 = __importDefault(require("chalk")); const os = __importStar(require("os")); const shell = __importStar(require("shelljs")); class StarshipInstaller { installations = { docker: { mac: 'Please install Docker. Follow: https://docs.docker.com/desktop/install/mac-install/', linux: 'Please install Docker. Follow: https://docs.docker.com/engine/install/ubuntu/' }, kubectl: { mac: 'brew install kubectl', linux: `curl -Lks "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" > ~/.local/bin/kubectl && chmod +x ~/.local/bin/kubectl` }, helm: { mac: 'brew install helm', linux: 'curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash' } }; async checkAndInstallBinary(binaryName) { if (!shell.which(binaryName)) { console.log(`${binaryName} is not installed`); await this.installBinary(binaryName); if (!shell.which(binaryName)) { console.log(chalk_1.default.red(`Installation of ${binaryName} failed. Please install ${binaryName} manually.`)); process.exit(1); } } } async checkAndInstallDependencies() { try { for (const dependency of Object.keys(this.installations)) { console.log(chalk_1.default.yellow(`Checking ${dependency}...`)); await this.checkAndInstallBinary(dependency); } console.log(chalk_1.default.green('All dependencies are installed!! Good to go!!')); } catch (err) { console.error(chalk_1.default.red(`Error installing dependencies: ${err}`)); } } async installBinary(binaryName) { const platform = os.platform(); const installation = this.installations[binaryName]; if (platform === 'darwin') { await this.runInstallation(installation.mac); } else if (platform === 'linux') { await this.runInstallation(installation.linux); } } async runInstallation(command) { shell.exec(command); } } exports.StarshipInstaller = StarshipInstaller;