Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added flag to have it prompt for generator and action #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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