1 Star 5 Fork 1

汪磊 / caz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
render.ts 757 Bytes
一键复制 编辑 原始数据 按行查看 历史
汪磊 提交于 2020-08-09 12:29 . fix: skip binary file (#5)
import _ from 'lodash'
import { file } from '../core'
import { Context } from './types'
/**
* Render file if template.
*/
export default async (ctx: Context): Promise<void> => {
// interpolate
// https://github.com/lodash/lodash/blob/master/.internal/reEvaluate.js
const regexp = /<%([\s\S]+?)%>/
const imports = {
...ctx.config.metadata,
...ctx.config.helpers
}
ctx.files.forEach(item => {
// ignore binary files
if (file.isBinary(item.contents)) return
const text = item.contents.toString()
// ignore files without interpolate
if (!regexp.test(text)) return
const compiled = _.template(text, { imports })
const newContents = compiled(ctx.answers)
item.contents = Buffer.from(newContents)
})
}
TypeScript
1
https://gitee.com/zce/caz.git
git@gitee.com:zce/caz.git
zce
caz
caz
master

搜索帮助