UNPKG

@sprucelabs/spruce-templates

Version:

Templates used for code generation in skills!

24 lines (23 loc) 1.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const handlebars_1 = __importDefault(require("handlebars")); const lodash_1 = require("lodash"); handlebars_1.default.registerHelper('valueTypeGenerator', function (fieldDefinition, renderAs, func, options) { const { data: { root: { fieldTemplateItems }, }, } = options; const match = fieldTemplateItems.filter((item) => item.camelType === fieldDefinition.type)[0]; if (!match) { throw new Error(`valueTypeGenerator.addon could not find a fieldTemplateItem with type ${fieldDefinition.type}`); } const type = handlebars_1.default.helpers.fieldTypeEnum(fieldDefinition, options); const fieldDefinitionCopy = { ...fieldDefinition }; // @ts-ignore fieldDefinitionCopy === null || fieldDefinitionCopy === void 0 ? true : delete fieldDefinitionCopy.keyName; const def = JSON.stringify({ ...fieldDefinitionCopy, type: '{{TYPE_ENUM}}', }).replace('"{{TYPE_ENUM}}"', type); return `${func}(${def}, TemplateRenderAs.${(0, lodash_1.upperFirst)(renderAs)}, "${match.importAs}")`; });