-
-
Notifications
You must be signed in to change notification settings - Fork 794
/
prepare.ts
33 lines (26 loc) · 1.03 KB
/
prepare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}