UNPKG

resumed

Version:

Lightweight JSON Resume builder, no-frills alternative to resume-cli

104 lines (103 loc) 3.27 kB
import { readFile as d, writeFile as u } from "node:fs/promises"; import { basename as g, extname as $ } from "node:path"; import O from "sade"; import k from "strip-json-comments"; import { yellow as r, red as E } from "yoctocolors"; import { createRequire as N } from "node:module"; import v from "@jsonresume/schema"; import { promisify as x } from "node:util"; const C = "../package.json", p = JSON.parse( await d(new URL(C, import.meta.url), "utf-8") ), m = "resume.json", l = (e, t) => [g(e, $(e)), t].join("."), w = async (e) => JSON.parse(k(await d(e, "utf-8"))), h = async (e, t) => { const o = t ?? e?.meta?.theme; if (!o) throw new Error( `No theme to use. Please specify one via the ${r("--theme")} option or the ${r(".meta.theme")} field of your resume.` ); try { return await import(o); } catch { throw new Error( `Could not load theme ${r(o)}. Is it installed?` ); } }, c = O(p.name).version(p.version); c.command("render [filename]", "Render resume", { default: !0 }).option("-o, --output", "Output filename").option("-t, --theme", "Theme to use").action( async (e = m, { output: t = l( e, "html" /* Html */ ), theme: o }) => { const a = await w(e), n = await h(a, o), s = await f(a, n); await u(t, s), console.log( `You can find your rendered resume at ${r(t)}. Nice work! 🚀` ); } ); c.command("export [filename]", "Export resume to PDF").option("-o, --output", "Output filename").option("-t, --theme", "Theme to use").action( async (e = m, { output: t = l( e, "pdf" /* Pdf */ ), theme: o }) => { const a = await w(e), n = await h(a, o), s = await f(a, n), i = await j(s, a, n); await u(t, i), console.log( `You can find your exported resume at ${r(t)}. Nice work! 🚀` ); } ); c.command("init [filename]", "Create sample resume", { alias: "create" }).action(async (e = m) => { await R(e), console.log( `Done! Start editing ${r(e)} now, and run the ${r("render")} command when you are ready. 👍` ); }); c.command("validate [filename]", "Validate resume").action(async (e = m) => { try { await S(e), console.log(`Your ${r(e)} looks amazing! ✨`); } catch (t) { if (!Array.isArray(t)) throw t; console.error( `Uh-oh! The following errors were found in ${r(e)}: ` ), t.forEach( (o) => console.error(` ${E(`❌ ${o.message}`)} at ${r(o.path)}.`) ), process.exitCode = 1; } }); const F = N(import.meta.url), R = (e) => { const t = F("@jsonresume/schema/sample.resume.json"); return u(e, JSON.stringify(t, void 0, 2)); }, j = async (e, t, o, a = "puppeteer") => { let n; try { n = await import(a); } catch { throw new Error( `Could not import ${r(a)} package. Is it installed?` ); } const s = await n.launch(), i = await s.newPage(); await i.setContent(e, { waitUntil: "networkidle0" }); const y = await i.pdf({ ...o.pdfRenderOptions, ...t.meta?.pdfRenderOptions }); return await s.close(), y; }, f = (e, t) => t.render(e), J = x(v.validate), S = async (e) => { const t = await d(e, "utf-8"); return J(JSON.parse(t)); }; export { c as cli, R as init, j as pdf, f as render, S as validate };