Skip to content

Commit

Permalink
feat: added flag to have it prompt for generator and action
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtisHumphrey committed Mar 25, 2019
1 parent 47b7fd0 commit f1315cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Loaded templates: _templates
added: app/hello.js
```

Or you can have it prompt for generator and action:

```
$ hygen --prompt
```

You've generated content into the current working directory in `app/`. To see how the generator is built, look at `_templates` (which you should check-in to your project from now on, by the way).

You can build a generator that uses an interactive prompt to fill in a variable:
Expand Down
29 changes: 27 additions & 2 deletions src/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,39 @@ const L = require('lodash')
const path = require('path')
const yargs = require('yargs-parser')
const prompt = require('./prompt')
const { availableActions } = require('./help')

const params = async (
{ templates, createPrompter }: RunnerConfig,
{ templates, logger, createPrompter }: RunnerConfig,
externalArgv: Array<string>
): any => {
const argv = yargs(externalArgv)
let [generator, action] = argv._
const name = argv._[2]

if (argv.prompt) {
logger.log('Asking for generator and action')

const availableOptions = availableActions(templates)

const prompter = createPrompter()
let response = await prompter.prompt({
type: 'select',
name: 'generator',
message: 'Generator?',
choices: Object.keys(availableOptions)
})
generator = response.generator // eslint-disable-line prefer-destructuring

response = await prompter.prompt({
type: 'select',
name: 'action',
message: 'Action?',
choices: availableOptions[generator]
})
action = response.action // eslint-disable-line prefer-destructuring
}

const [generator, action, name] = argv._
if (!generator || !action) {
return { generator, action, templates }
}
Expand Down

0 comments on commit f1315cb

Please sign in to comment.