UNPKG

tsjobs

Version:

CLI typescript job board

57 lines (55 loc) 1.8 kB
#!/usr/bin/env node // src/index.ts import { defineCommand, runMain } from "citty"; import axios from "axios"; import Enquirer from "enquirer"; var main = defineCommand({ meta: { name: "tsjobs", version: "1.0.0", description: "Curated typescript jobs in your terminal" }, run: async () => { try { const res = await axios.get("https://typescript.jobs/api/job"); const data = res.data; const locations = data.locations; if (locations.length === 0) { console.log("No job locations found."); return; } const answer = await Enquirer.prompt([ { type: "select", name: "location", message: "Choose a location", choices: locations } ]); const selectedLocation = answer.location; const locationRes = await axios.get(`https://typescript.jobs/api/job?location=${encodeURIComponent(selectedLocation)}`); const locationJobs = locationRes.data.jobs; if (locationJobs.length === 0) { console.log(`No jobs found for ${selectedLocation}.`); return; } console.log(` \u{1F3AF} Jobs in ${selectedLocation}: `); locationJobs.forEach((job, index) => { console.log(`${index + 1}. \u{1F4CC} ${job.title} @ ${job.company_name}`); console.log(` \u{1F30D} Location: ${selectedLocation} ${job.remote}`); console.log(` \u{1F517} Apply: ${job.company_job_listing_url}`); console.log(` \u{1F50E} See more: ${job.full_details} `); }); } catch (error) { let errorMessage = "\u274C Failed to fetch job data"; if (error instanceof Error) { errorMessage = error.message; } console.error("\u274C Failed to fetch job data:", errorMessage); } } }); runMain(main);