import { SpecifyError, specifyErrors } from '../../../errors/index.js'; import { DeriveBuiltInParserHandlerFromDefinition } from '../../internals/createBuiltInParserDefinition.js'; import { GenerateBarrelFileParserDefinition } from './definition.js'; import { renderBarrelFile } from './internals/renderBarrelFile.js'; export const generateBarrelFileHandler: DeriveBuiltInParserHandlerFromDefinition< GenerateBarrelFileParserDefinition > = async (_, toolbox, options, outputConfiguration) => { let barrelContent: string | null = null; toolbox.updateOutput(output => { switch (output.type) { case 'files': { barrelContent = renderBarrelFile(output.files, options ?? {}); output.files.push({ path: outputConfiguration.filePath, content: { type: 'text', text: barrelContent, }, }); break; } default: { throw new SpecifyError({ errorKey: specifyErrors.PARSERS_ENGINE_INVALID_OUTPUT_TYPE.errorKey, publicMessage: `The output type ${output.type} is not supported by the generate-barrel-file parser.`, }); } } return output; }); return { type: 'JSON', json: { path: outputConfiguration.filePath, text: barrelContent, }, }; };