1 | import path from 'path'
|
2 | import fs from 'fs-extra'
|
3 | import { RunnerConfig } from './types'
|
4 | import { ConfigResolver } from './config'
|
5 |
|
6 | const configResolver = new ConfigResolver('.hygen.js', {
|
7 | exists: fs.exists,
|
8 |
|
9 | load: f => Promise.resolve(require(f)),
|
10 | none: _ => ({}),
|
11 | })
|
12 |
|
13 | export 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 | }
|