UNPKG

growthbook

Version:

The GrowthBook command-line interface (CLI) for working with the GrowthBook A/B testing, feature flagging, and experimentation platform

37 lines (36 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCompiledTypeScriptTemplateForFeatures = void 0; const Handlebars = require("handlebars"); const feature_1 = require("./feature"); const hbsTemplate = `/** * GrowthBook Features TypeScript Typings * * NOTE: This file is auto generated by the GrowthBook CLI (https://docs.growthbook.io/tools/cli). * See https://docs.growthbook.io/tools/cli#generating-types for more information. * * DO NOT EDIT this file manually. */ export type AppFeatures = { {{#each features}} '{{id}}': {{{valueType}}}; {{/each}} } `; /** * Given the provided features list, will compile it into a TypeScript template. * @param features List of key/value pairs * @return {string} TypeScript template */ const getCompiledTypeScriptTemplateForFeatures = (features) => { const compiled = Handlebars.compile(hbsTemplate); const featuresMappedToTypes = features.map(({ valueType, id }) => ({ id, valueType: (0, feature_1.getFeatureValueTypeToTypeScriptMapping)(valueType), })); const data = { features: featuresMappedToTypes, }; return compiled(data); }; exports.getCompiledTypeScriptTemplateForFeatures = getCompiledTypeScriptTemplateForFeatures;