UNPKG

soccer-go

Version:

Soccer CLI for stats and results.

107 lines (106 loc) • 4.59 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 () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __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.printTeam = void 0; const cfonts_1 = __importDefault(require("cfonts")); const picocolors_1 = __importDefault(require("picocolors")); const api = __importStar(require("../api")); const models_1 = require("../models"); const tableBuilders_1 = require("../tableBuilders"); const printTeam = async (teamName, options, leagueCode) => { const team = await fetchTeam(teamName, leagueCode); cfonts_1.default.say(team.shortName || team.name); printTeamDetails(team); if (options.fixtures) { const fixturesData = await api.getTeamFixtures(team); if (options.details) { const table = new tableBuilders_1.FixtureDetailsTableBuilder().buildTable(fixturesData, models_1.FixtureDetails); console.log(table.toString()); } else { const table = new tableBuilders_1.FixturesTableBuilder().buildTable(fixturesData, models_1.Fixture); console.log(table.toString()); } } if (options.players) { const table = new tableBuilders_1.PlayersTableBuilder().buildTable(team.squad, models_1.Player); console.log(table.toString()); } }; exports.printTeam = printTeam; function printTeamDetails(team) { // Header with full name console.log(picocolors_1.default.cyan(picocolors_1.default.bold(`\nšŸ“‹ ${team.name}`))); console.log(picocolors_1.default.dim('─'.repeat(60))); const infoItems = []; if (team.founded) { infoItems.push(`${picocolors_1.default.yellow('⚔')} Founded ${picocolors_1.default.bold(team.founded.toString())}`); } if (team.venue) { infoItems.push(`${picocolors_1.default.green('šŸŸļø ')} ${team.venue}`); } if (team.clubColors) { infoItems.push(`${picocolors_1.default.magenta('šŸŽØ')} ${team.clubColors}`); } if (infoItems.length > 0) { console.log(infoItems.join(picocolors_1.default.dim(' • '))); } const secondLine = []; if (team.website) { const cleanWebsite = team.website.replace(/^https?:\/\//, '').replace(/\/$/, ''); secondLine.push(`${picocolors_1.default.blue('🌐')} ${cleanWebsite}`); } if (team.coach) { const contractEnd = team.coach.contract.until; secondLine.push(`${picocolors_1.default.cyan('šŸ‘¤')} ${team.coach.name} ${picocolors_1.default.dim(`(until ${contractEnd})`)}`); } if (secondLine.length > 0) { console.log(secondLine.join(picocolors_1.default.dim(' • '))); } if (team.runningCompetitions?.length > 0) { const competitions = team.runningCompetitions.map((c) => picocolors_1.default.bold(c.name)).join(picocolors_1.default.dim(', ')); console.log(`${picocolors_1.default.yellow('šŸ†')} ${competitions}`); } console.log(picocolors_1.default.dim('─'.repeat(60))); console.log(); } async function fetchTeam(team, league) { const teamId = await api.getTeamId(team, league); const teamData = await api.getTeam(teamId); return new models_1.Team(teamData); }