honour profilePath

This commit is contained in:
DaKheera47 2026-01-21 15:30:45 +00:00
parent 7c524f5d63
commit 77f7927e77
2 changed files with 24 additions and 12 deletions

View File

@ -113,7 +113,7 @@ export async function runPipeline(config: Partial<PipelineConfig> = {}): Promise
try { try {
// Step 1: Load profile // Step 1: Load profile
console.log('\n📋 Loading profile...'); console.log('\n📋 Loading profile...');
const profile = await getProfile(); const profile = await getProfile(mergedConfig.profilePath);
// Step 2: Run crawler // Step 2: Run crawler
console.log('\n🕷 Running crawler...'); console.log('\n🕷 Running crawler...');
@ -347,7 +347,7 @@ export async function runPipeline(config: Partial<PipelineConfig> = {}): Promise
// Process job (Generate Summary + PDF) // Process job (Generate Summary + PDF)
// We catch errors here to ensure one failure doesn't stop the whole batch // We catch errors here to ensure one failure doesn't stop the whole batch
const result = await processJob(job.id); const result = await processJob(job.id, { profilePath: mergedConfig.profilePath });
if (result.success) { if (result.success) {
processedCount++; processedCount++;
@ -414,12 +414,17 @@ export async function runPipeline(config: Partial<PipelineConfig> = {}): Promise
} }
} }
export type ProcessJobOptions = {
force?: boolean;
profilePath?: string;
};
/** /**
* Step 1: Generate AI summary and suggest projects. * Step 1: Generate AI summary and suggest projects.
*/ */
export async function summarizeJob( export async function summarizeJob(
jobId: string, jobId: string,
options?: { force?: boolean } options?: ProcessJobOptions
): Promise<{ ): Promise<{
success: boolean; success: boolean;
error?: string; error?: string;
@ -430,7 +435,7 @@ export async function summarizeJob(
const job = await jobsRepo.getJobById(jobId); const job = await jobsRepo.getJobById(jobId);
if (!job) return { success: false, error: 'Job not found' }; if (!job) return { success: false, error: 'Job not found' };
const profile = await getProfile(); const profile = await getProfile(options?.profilePath);
// 1. Generate Summary & Tailoring // 1. Generate Summary & Tailoring
let tailoredSummary = job.tailoredSummary; let tailoredSummary = job.tailoredSummary;
@ -491,7 +496,8 @@ export async function summarizeJob(
* Step 2: Generate PDF using current summary and project selection. * Step 2: Generate PDF using current summary and project selection.
*/ */
export async function generateFinalPdf( export async function generateFinalPdf(
jobId: string jobId: string,
options?: ProcessJobOptions
): Promise<{ ): Promise<{
success: boolean; success: boolean;
error?: string; error?: string;
@ -513,7 +519,7 @@ export async function generateFinalPdf(
skills: job.tailoredSkills ? JSON.parse(job.tailoredSkills) : [] skills: job.tailoredSkills ? JSON.parse(job.tailoredSkills) : []
}, },
job.jobDescription || '', job.jobDescription || '',
DEFAULT_PROFILE_PATH, options?.profilePath || DEFAULT_PROFILE_PATH,
job.selectedProjectIds job.selectedProjectIds
); );
@ -540,7 +546,7 @@ export async function generateFinalPdf(
*/ */
export async function processJob( export async function processJob(
jobId: string, jobId: string,
options?: { force?: boolean } options?: ProcessJobOptions
): Promise<{ ): Promise<{
success: boolean; success: boolean;
error?: string; error?: string;
@ -551,7 +557,7 @@ export async function processJob(
if (!sumResult.success) return sumResult; if (!sumResult.success) return sumResult;
// Step 2: Generate PDF // Step 2: Generate PDF
const pdfResult = await generateFinalPdf(jobId); const pdfResult = await generateFinalPdf(jobId, options);
return pdfResult; return pdfResult;
} catch (error) { } catch (error) {

View File

@ -6,22 +6,28 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const DEFAULT_PROFILE_PATH = join(__dirname, '../../../../resume-generator/base.json'); const DEFAULT_PROFILE_PATH = join(__dirname, '../../../../resume-generator/base.json');
let cachedProfile: any = null; let cachedProfile: any = null;
let cachedProfilePath: string | null = null;
/** /**
* Get the base resume profile from base.json. * Get the base resume profile from base.json.
* Caches the result since it doesn't change often. * Caches the result since it doesn't change often.
* @param profilePath Optional absolute path to profile JSON. Defaults to base.json.
* @param forceRefresh Force reload from disk.
*/ */
export async function getProfile(forceRefresh = false): Promise<any> { export async function getProfile(profilePath?: string, forceRefresh = false): Promise<any> {
if (cachedProfile && !forceRefresh) { const targetPath = profilePath || DEFAULT_PROFILE_PATH;
if (cachedProfile && cachedProfilePath === targetPath && !forceRefresh) {
return cachedProfile; return cachedProfile;
} }
try { try {
const content = await readFile(DEFAULT_PROFILE_PATH, 'utf-8'); const content = await readFile(targetPath, 'utf-8');
cachedProfile = JSON.parse(content); cachedProfile = JSON.parse(content);
cachedProfilePath = targetPath;
return cachedProfile; return cachedProfile;
} catch (error) { } catch (error) {
console.error('❌ Failed to load profile from base.json:', error); console.error(`❌ Failed to load profile from ${targetPath}:`, error);
return {}; return {};
} }
} }