1 Star 5 Fork 1

汪磊 / caz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
prepare.ts 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
汪磊 提交于 2020-07-31 16:05 . feat: prepare & emit hooks
import path from 'path'
import glob from 'fast-glob'
import { file } from '../core'
import { Context } from './types'
/**
* Prepare all template files.
*/
export default async (ctx: Context): Promise<void> => {
const cwd = path.join(ctx.src, ctx.config.source ?? 'template')
const filters = ctx.config.filters
const ignore = filters != null ? Object.keys(filters).filter(i => !filters[i](ctx.answers)) : undefined
const entries = await glob('**', { cwd, ignore, dot: true })
await Promise.all(entries.map(async entry => {
const contents = await file.read(path.join(cwd, entry))
ctx.files.push({ path: entry, contents })
}))
// with stats
// const entries = await glob('**', { cwd, ignore, dot: true, stats: true })
// await Promise.all(entries.map(async entry => {
// const contents = await file.read(path.join(cwd, entry.path))
// ctx.files.push({ path: entry.path, stats: entry.stats, contents })
// }))
// Apply template prepare hook.
if (ctx.config.prepare == null) return
await ctx.config.prepare(ctx)
}
TypeScript
1
https://gitee.com/zce/caz.git
git@gitee.com:zce/caz.git
zce
caz
caz
master

搜索帮助