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