Skip to main content

Prompt configuration

Under Construction
This page is under construction, but we are working hard to improve it.

Prompt configuration object. We use inquirer library for prompting. All inquirer prompt properties are supported when creating prompts. For more information on the available properties in inquirer, you can refer to the documentation here.

Type
interface Prompt {
/**
* Name of prompt
*/
name: string;
/**
* Prompt description
*/
description: string;
/**
* Message you would like to show user
*/
message: string;
/**
* Type of inquirer prompt you would like to use
*
* @link https://github.com/SBoudrias/Inquirer.js/tree/v6.0.0
*/
type: 'confirm' | 'input' | 'checkbox' | 'list' | 'rawlist' | 'password';
/**
* How you want templates to process this prompts answer
*/
tpsType: 'package' | 'data';
/**
* choices for your prompt.
*
* Only needed for prompts of type `list`, `rawlist` or `checkbox`
*/
choices?: string[];
/**
* Make prompt a hidden prompt
* @version templates@>v1.1.1
*/
hidden?: boolean;
/**
* Default answer for the prompt
*/
default?: any;
}

Examples

Using confirm

Say you have this react-component template:

| - tps-example
| - .tps/
| - react-component/
| - settings.json
| - default/
| - index.js
| - css
| - {{=tps.name}}.css

Adding this prompt will allow you to conditionally render the css package.

settings.json
{
"prompts": [
{
"name": "css",
"type": "confirm",
"message": "Would you like to add a css file?"
}
]
}

Now if the user answers true like so:

tps react-component App --css

then this will be the new template:

    | - tps-example
| - .tps/
| - ...
| - App
| - index.js
| - App.css

Now if the user answers false like so:

tps react-component App --no-css

then this will be the new template:

    | - tps-example
| - .tps/
| - ...
| - App
| - index.js

Using checkbox

settings.json
{
"prompts": [
{
"name": "modules",
"type": "checkbox",
"choices": ["react", "express", "fs", "path"],
"tpsType": "data",
"message": "What node modules would you like to import into this js file?"
}
]
}