UNPKG

1.44 kBSource Map (JSON)View Raw
1{"version":3,"file":"templateFile.js","sourceRoot":"","sources":["../src/templateFile.ts"],"names":[],"mappings":";;;;;AAAA,oDAAuB;AACvB,wDAA0B;AAE1B,KAAK,UAAU,YAAY,CACzB,gBAAwB,EACxB,IAA2C,EAC3C,cAAuB,EACvB,EAAE,QAAQ,GAAG,IAAI,KAA6B,EAAE;IAEhD,MAAM,cAAc,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACnE,MAAM,gBAAgB,GAAG,gBAAC,CAAC,QAAQ,CACjC,cAAc,EACd,QAAQ;QACN,CAAC,CAAC;YACE,WAAW;YACX,WAAW,EAAE,iBAAiB;SAC/B;QACH,CAAC,CAAC,SAAS,CACd,CAAC;IACF,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAElD,IAAI,cAAc,EAAE;QAClB,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;KACxD;SAAM;QACL,OAAO,kBAAkB,CAAC;KAC3B;AACH,CAAC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import _ from 'lodash';\nimport fs from 'fs-extra';\n\nasync function templateFile(\n templateFilePath: string,\n envs: Record<string, string | number | any>,\n outputFilePath?: string,\n { mustache = true }: { mustache?: boolean } = {}\n): Promise<string | void> {\n const templateString = await fs.readFile(templateFilePath, 'utf8');\n const compiledTemplate = _.template(\n templateString,\n mustache\n ? {\n // mustache\n interpolate: /{{([\\s\\S]+?)}}/g,\n }\n : undefined\n );\n const outputFileContents = compiledTemplate(envs);\n\n if (outputFilePath) {\n await fs.writeFile(outputFilePath, outputFileContents);\n } else {\n return outputFileContents;\n }\n}\n\nexport default templateFile;\n"]}
\No newline at end of file