import { searchReports } from '../../../helpers/profileGeneratorHelper'; import fs from 'fs'; export async function includeReport( componentPath: string, entityName: string, ): Promise<{ filePaths: string[]; associations: { taskId: string; pullerId: string; tableId: string; resultKey: string; } | null; } | null> { const reports = (await searchReports(entityName, componentPath)) as any[]; if (!reports.length) { console.error( `Could not find report named ${entityName} in ${componentPath}`, ); return null; } const filePaths: string[] = []; for (const reportYml of reports) { const tableFilePath = reportYml.__file_path.replace( /\_Report\.yaml$/g, '_Report_Table.yaml', ); if (!fs.existsSync(tableFilePath)) { console.error( `Could not find related table at ${tableFilePath} in ${componentPath}`, ); continue; } filePaths.push(tableFilePath, reportYml.__file_path); } const distinctFilePaths = filePaths.filter((v, i, a) => a.indexOf(v) === i); if (!distinctFilePaths.length) { console.error( `No valid report/table files found for ${entityName} in ${componentPath}`, ); return null; } return { filePaths: distinctFilePaths, associations: null, }; }