From 5a319d7c6d2f2ea0340767610368c41e928658e2 Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Tue, 23 Jan 2024 01:51:09 -0500 Subject: [PATCH] Check template for codeblocks exists or not before trying to generate --- src/macrofier/engine.mjs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 9cd824ba..badf7756 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -363,9 +363,22 @@ const makeProviderMethod = x => x.name["onRequest".length].toLowerCase() + x.nam //import { default as platform } from '../Platform/defaults' const generateAggregateMacros = (openrpc, modules, templates, library) => Object.values(modules) .reduce((acc, module) => { - acc.exports += insertMacros(getTemplate('/codeblocks/export', templates) + '\n', generateMacros(module, templates)) - acc.mockImports += insertMacros(getTemplate('/codeblocks/mock-import', templates) + '\n', generateMacros(module, templates)) - acc.mockObjects += insertMacros(getTemplate('/codeblocks/mock-parameter', templates) + '\n', generateMacros(module, templates)) + + let template = getTemplate('/codeblocks/export', templates) + if (template) { + acc.exports += insertMacros(template + '\n', generateMacros(module, templates)) + } + + template = getTemplate('/codeblocks/mock-import', templates) + if (template) { + acc.mockImports += insertMacros(template + '\n', generateMacros(module, templates)) + } + + template = getTemplate('/codeblocks/mock-parameter', templates) + if (template) { + acc.mockObjects += insertMacros(template + '\n', generateMacros(module, templates)) + } + return acc }, { exports: '',