text: // @flow
  
  import type { ActionResult, RunnerConfig } from './types'
  
  const fs = require('fs-extra')
  const params = require('./params')
  
  const engine = async (
    argv: Array<string>,
    config: RunnerConfig
  ): Promise<Array<ActionResult>> => {
    const { cwd, templates, logger } = config
    const args = Object.assign(await params(config, argv), { cwd })
    const { generator, action, actionfolder } = args
  
    logger.log(args.dry ? '(dry mode)' : '')
    if (!generator) {
      throw new Error('please specify a generator.')
    }
  
    if (!action) {
      throw new Error(`please specify an action for ${generator}.`)
    }
  
    logger.log(`Loaded templates: ${templates.replace(cwd + '/', '')}`)
    if (!(await fs.exists(actionfolder))) {
      throw new Error(`I can't find action '${action}' for generator '${generator}'.
  
        You can try:
        1. 'hygen init self' to initialize your project, and
        2. 'hygen generator new --name ${generator}' to build the generator you wanted.
  
        Check out the quickstart for more: http://www.hygen.io/quick-start
        `)
    }
  
    // lazy loading these dependencies gives a better feel once
    // a user is exploring hygen (not specifying what to execute)
    const execute = require('./execute')
    const render = require('./render')
    return await execute(await render(args, config), args, config)
  }
  
  module.exports = engine
  