UNPKG

ikea-availability-checker

Version:

ikea product in-store availability checker and product search

108 lines (100 loc) 3.66 kB
#!/usr/bin/env node "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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const program_1 = require("./lib/program"); const stores_1 = require("./../lib/stores"); const arguments_1 = require("./lib/arguments"); const options = __importStar(require("./lib/options")); const storesTable_1 = require("./reporter/storesTable"); program_1.program .addArgument(arguments_1.countryCode) .addOption(options.plain) .addOption(options.pretty) .addOption(options.json) .description("List the IKEA stores found in the given country.") .addHelpText("after", ` Examples: get all stores in a country ikea-availability-checker stores de get all stores from multiple countries ikea-availability-checker stores de at us print results as JSON ikea-availability-checker stores --json de get only the ids, the second column ikea-availability-checker stores --plain de | awk '{print $2}' get all stores ikea-availability-checker stores count all stores ikea-availability-checker stores --plain | wc -l get all store country codes, sorted asc ikea-availability-checker stores --plain | awk '{print $1} | uniq | sort `) .action((countryCodes) => { const opts = program_1.program.opts(); let foundStores = stores_1.stores; if (countryCodes && countryCodes.length) { foundStores = (0, stores_1.findByCountryCode)(countryCodes); } let format = "table"; if (opts.json) format = "json"; if (opts.plain) format = "tsv"; if (opts.pretty) format = "table"; let report; switch (format) { case "json": report = JSON.stringify(foundStores); break; case "tsv": report = foundStores .map((store) => [store.countryCode, store.country, store.buCode, store.name].join("\t")) .join("\n"); break; default: case "table": report = (0, storesTable_1.createStoresReportTable)(foundStores).toString(); break; } process.stdout.write(report); }); program_1.program.parseAsync() .catch((err) => { const message = err instanceof Error ? err.message : String(err); process.stderr.write(message + "\n"); process.exit(1); });