# yeoman-option-or-prompt

> Provides a helper for yeoman generators that wraps the prompt method with code that will exclude any prompts for data that has been supplied via options.

Latest version **2.0.1** (published 2018-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install yeoman-option-or-prompt
pnpm add yeoman-option-or-prompt
yarn add yeoman-option-or-prompt
bun add yeoman-option-or-prompt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-08-27 |
| First published | 2015-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sam Baker |
| Maintainers | artefact, funwhilelost |

## Links

- npm: https://www.npmjs.com/package/yeoman-option-or-prompt
- Repository: https://github.com/artefact-group/yeoman-option-or-prompt
- Homepage: https://github.com/artefact-group/yeoman-option-or-prompt#readme
- Issues: https://github.com/artefact-group/yeoman-option-or-prompt/issues
- npm.io page: https://npm.io/package/yeoman-option-or-prompt

## Dependencies (1)

- [pinkie-promise](https://npm.io/package/pinkie-promise.md) 2.0.1

## Recent versions

- 2.0.1 (latest) — 2018-08-27
- 2.0.0 — 2017-04-24
- 1.0.2 — 2015-06-01
- 1.0.1 — 2015-05-31
- 1.0.0 — 2015-05-31

## README

# yeoman-option-or-prompt
Provides a helper for yeoman generators that wraps the prompt method with code that will exclude any prompts for data that has been supplied via options.

To install use

``` bash
npm install yeoman-option-or-prompt --save
```

To use it, just add optionOrPrompt as an internal function on your generator and call it in place of the yeoman-generator `prompt` method:

``` javascript
var yeoman = require('yeoman-generator');
var optionOrPrompt = require('yeoman-option-or-prompt');

module.exports = yeoman.generators.Base.extend({

  _optionOrPrompt: optionOrPrompt,

  prompting: function () {
    var done = this.async();
    // Instead of calling prompt, call _optionOrPrompt to allow parameters to be passed as command line or composeWith options.
    this._optionOrPrompt([{
      type    : 'input',
      name    : 'name',
      message : 'Your project name',
      default : this.appname // Default to current folder name
    }], function (answers) {
      this.log(answers.name);
      done();
    }.bind(this));
  }
})
```

You can also pass options to subgenerators, with:

``` javascript
  compose: function () {
    this.composeWith('node-webkit:download', { options: this.options });
    if(this.examples){
      this.composeWith('node-webkit:examples', { options: this.options });
    }
  }
```

Now if another app calls your generator, they can supply values for each of your prompts with the options parameter. Alternatively, a user can supply values for your prompts on the command line:

``` bash
yo single-page-app --name="App that saves the world."
```

---
_Source: https://npm.io/package/yeoman-option-or-prompt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
