UNPKG

658 BPlain TextView Raw
1import path from 'path'
2import fs from 'fs-extra'
3import { RunnerConfig } from './types'
4import { ConfigResolver } from './config'
5
6const configResolver = new ConfigResolver('.hygen.js', {
7 exists: fs.exists,
8 // $FlowFixMe
9 load: f => Promise.resolve(require(f)),
10 none: _ => ({}),
11})
12
13export default async (config: RunnerConfig): Promise<RunnerConfig> => {
14 const { cwd, templates } = config
15
16 const resolvedTemplates =
17 [process.env.HYGEN_TMPLS, path.join(cwd, '_templates')].find(
18 _ => _ && fs.existsSync(_),
19 ) || templates
20
21 return {
22 ...config,
23 templates: resolvedTemplates,
24 ...(await configResolver.resolve(cwd)),
25 }
26}