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