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