/** * @copyright nhcarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { writeFile, copyFile, stat, mkdir } from "node:fs/promises"; import { join } from "node:path"; // eslint-disable-next-line import/no-extraneous-dependencies -- Since this is a dev script, there are no production dependencies. import { parse } from "yaml"; import type { Resume } from "./interfaces/resume.js"; const htmlBeginning = ` Naomi Carrigan
`; const htmlEnd = `
`; const request = await fetch( "https://data.nhcarrigan.com/resume.yml", ); if (!request.ok) { // eslint-disable-next-line no-console -- error logging. console.error( `Failed to fetch resume.yaml: ${request.status.toString()} ${request.statusText}`, ); process.exit(1); } const result = await request.text(); // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- parse does not accept a generic. const yaml = (await parse( result, )) as Resume; const currentEmployment = yaml.employment. filter((item) => { return item.end_date === "Present"; }). sort((a, b) => { return ( new Date(`5${b.start_date}`).getTime() - new Date(`5${a.start_date}`).getTime() ); }); const currentVolunteer = yaml.volunteer. filter((item) => { return item.end_date === "Present"; }). sort((a, b) => { return ( new Date(`5${b.start_date}`).getTime() - new Date(`5${a.start_date}`).getTime() ); }); const pastEmployment = yaml.employment. filter((item) => { return item.end_date !== "Present"; }). sort((a, b) => { return ( new Date(`5${b.end_date}`).getTime() - new Date(`5${a.end_date}`).getTime() ); }); const pastVolunteer = yaml.volunteer. filter((item) => { return item.end_date !== "Present"; }). sort((a, b) => { return ( new Date(`5${b.end_date}`).getTime() - new Date(`5${a.end_date}`).getTime() ); }); yaml.employment = [ ...currentEmployment, ...pastEmployment ]; yaml.volunteer = [ ...currentVolunteer, ...pastVolunteer ]; yaml.certifications.sort((a, b) => { return new Date(`5${b.date}`).getTime() - new Date(`5${a.date}`).getTime(); }); yaml.education.sort((a, b) => { return ( new Date(`5${b.end_date}`).getTime() - new Date(`5${a.end_date}`).getTime() ); }); yaml.projects.sort((a, b) => { return new Date(`5${b.date}`).getTime() - new Date(`5${a.date}`).getTime(); }); yaml.publications.sort((a, b) => { return new Date(b.date).getTime() - new Date(a.date).getTime(); }); const heading = `

${yaml.name}

${yaml.contact}

${yaml.summary}

Interested in hiring me? See what past clients have to say, or submit your own request!`; const employment = `

Employment

${yaml.employment. map((item) => { return `

${item.title}

${item.company} ${item.type}
${item.start_date} - ${item.end_date} ${ item.prior_positions ? `
${item.prior_positions. map((position, index) => { return `

${position.title}

${position.start_date} - ${ position.end_date }

`; }). join("
")}` : "" }

${item.description}

`; }). join("\n")}
`; const volunteer = `

Volunteer Work

${yaml.volunteer. map((item) => { return `

${item.title}

${item.company}
${item.start_date} - ${item.end_date}

${item.description}

`; }). join("\n")}
`; const education = `

Education

${yaml.education. map((item) => { return `

${item.title}

${item.institution} ${item.type}
${item.start_date} - ${item.end_date}

${item.description}

`; }). join("\n")}
`; const certifications = `

Certifications

${yaml.certifications. map((item) => { return `

${item.title}

${item.issuer}
${item.date}
`; }). join("\n")}
`; const projects = `

Projects

${yaml.projects. map((item) => { return `

${item.title}

${item.company}
${item.date}

${item.description}

`; }). join("\n")}
`; const publications = `

Publications

${yaml.publications. map((item) => { return `

${item.title}

${item.company}
${item.date}

${item.description}

`; }). join("\n")}
`; const directoryStatus = await stat(join(process.cwd(), "site")). then((status) => { return status.isDirectory(); }). catch(() => { return false; }); if (!directoryStatus) { await mkdir(join(process.cwd(), "site")); } await writeFile( join(process.cwd(), "site", "index.html"), htmlBeginning + heading + employment + volunteer + education + certifications + projects + publications + htmlEnd, "utf8", ); await copyFile( join(process.cwd(), "src", "static", "style.css"), join(process.cwd(), "site", "style.css"), ); await copyFile( join(process.cwd(), "src", "static", "dates.js"), join(process.cwd(), "site", "dates.js"), );