#!/usr/bin/env node /** * Cover Letter Generator Template * * This script provides a template for generating professional cover letters * using the docx library with proper formatting and structure. * * Usage: Customize the content sections below with job-specific information */ const { Document, Packer, Paragraph, TextRun, AlignmentType } = require('docx'); const fs = require('fs'); // Configuration const OUTPUT_FILE = 'Collins_Robin_Cover_Letter.docx'; const APPLICANT_NAME = 'Robin Collins'; const APPLICANT_EMAIL = 'robin.f.collins@outlook.com'; const APPLICANT_PHONE = '0475 795 732'; // Job-specific configuration - CUSTOMIZE THESE const POSITION_TITLE = '[Position Title]'; const COMPANY_NAME = '[Company Name]'; const HIRING_MANAGER = '[Hiring Manager Name or "Hiring Manager"]'; const DATE = new Date().toLocaleDateString('en-AU', { year: 'numeric', month: 'long', day: 'numeric' }); /** * Content sections - CUSTOMIZE WITH JOB-SPECIFIC CONTENT */ const OPENING_PARAGRAPH = `Dear ${HIRING_MANAGER}, I am writing to express my strong interest in the ${POSITION_TITLE} position at ${COMPANY_NAME}. [Add 1-2 sentences about your unique value proposition and why you're an excellent fit for this specific role.]`; const BODY_PARAGRAPH_1 = `[Address first key selection criterion or requirement. Lead with the criterion, provide specific evidence from your experience with quantifiable results, and connect to the organizational need.]`; const BODY_PARAGRAPH_2 = `[Address second key selection criterion. Include specific achievements, metrics, and demonstrate how your experience directly applies to role requirements.]`; const BODY_PARAGRAPH_3 = `[Optional: Address additional selection criteria or provide compelling examples that differentiate you as a candidate.]`; const CLOSING_PARAGRAPH = `I am excited about the opportunity to bring my [key skills/experience] to ${COMPANY_NAME} and contribute to [specific organizational goal or initiative]. I would welcome the opportunity to discuss how my background aligns with your needs in greater detail. Thank you for considering my application. Sincerely, ${APPLICANT_NAME} ${APPLICANT_EMAIL} ${APPLICANT_PHONE}`; /** * Style definitions */ const styles = { default: { document: { run: { font: 'Calibri', size: 22 } // 11pt } }, paragraphStyles: [ { id: 'Header', name: 'Header', basedOn: 'Normal', run: { font: 'Calibri', size: 22, bold: true }, paragraph: { spacing: { after: 120 }, alignment: AlignmentType.LEFT } }, { id: 'Body', name: 'Body', basedOn: 'Normal', run: { font: 'Calibri', size: 22 }, paragraph: { spacing: { after: 240, line: 360 }, alignment: AlignmentType.LEFT } }, { id: 'Closing', name: 'Closing', basedOn: 'Normal', run: { font: 'Calibri', size: 22 }, paragraph: { spacing: { before: 240, after: 120 }, alignment: AlignmentType.LEFT } } ] }; /** * Generate cover letter document */ function generateCoverLetter() { const doc = new Document({ styles: styles, sections: [{ properties: { page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1 inch margins } }, children: [ // Header with contact info new Paragraph({ style: 'Header', children: [new TextRun(APPLICANT_NAME)] }), new Paragraph({ children: [ new TextRun(`${APPLICANT_EMAIL} | ${APPLICANT_PHONE}`) ], spacing: { after: 240 } }), // Date new Paragraph({ children: [new TextRun(DATE)], spacing: { after: 240 } }), // Opening new Paragraph({ style: 'Body', children: [new TextRun(OPENING_PARAGRAPH)] }), // Body paragraphs new Paragraph({ style: 'Body', children: [new TextRun(BODY_PARAGRAPH_1)] }), new Paragraph({ style: 'Body', children: [new TextRun(BODY_PARAGRAPH_2)] }), // Optional third body paragraph (comment out if not needed) new Paragraph({ style: 'Body', children: [new TextRun(BODY_PARAGRAPH_3)] }), // Closing new Paragraph({ style: 'Closing', children: [new TextRun(CLOSING_PARAGRAPH)] }) ] }] }); return doc; } /** * Save document to file */ async function main() { try { const doc = generateCoverLetter(); const buffer = await Packer.toBuffer(doc); fs.writeFileSync(OUTPUT_FILE, buffer); console.log(`✅ Cover letter created successfully: ${OUTPUT_FILE}`); } catch (error) { console.error('❌ Error generating cover letter:', error); process.exit(1); } } // Run if called directly if (require.main === module) { main(); } module.exports = { generateCoverLetter };