UNPKG

hygen

Version:

The scalable code generator that saves you time.

42 lines (31 loc) 1.3 kB
// @flow import type { RunnerConfig } from './types' const fs = require('fs-extra') const params = require('./params') const engine = async (argv: Array<string>, config: RunnerConfig) => { const { cwd, templates, logger } = config const args = Object.assign(await params(templates, 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') await execute(await render(args, config), args, config) } module.exports = engine