@ahurein/travel-explorer
Version:
CLI utility to easily browse attractions in every country/city
32 lines (31 loc) • 1.51 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Command } from "commander";
import { getAttractionsStats } from "../attractionsApi.js";
import ora from 'ora';
import { customTable } from "../helpers/helper.js";
const spinner = ora('Loading unicorns');
const log = console.log;
export const statisticsCommand = new Command("stats");
statisticsCommand
.description("List statistics of all attractions")
.action(() => __awaiter(void 0, void 0, void 0, function* () {
spinner.start();
const stats = yield getAttractionsStats();
spinner.stop();
const statsTable = customTable(["No", "Continent", "Number of attractions"], [4, 20, 30]);
let count = 1;
stats.forEach((stat) => {
const { continent, total } = stat;
statsTable.push([count, continent, total]);
count += 1;
});
log(statsTable.toString());
}));