Features and Properties
Before we show you conditional questions and choice, we have to understand how “makes” makes use of the answers from questions.
“makes” divides the answers into two groups.
- the answers from text prompts were grouped into a hash object called
properties
. - the answers from select/multi-select prompts are grouped into an array called
features
. properties
andfeatures
were built progressively when end user went through the questions, so we can usefeatures
to conditionally control the appearance of next question and choice of select prompt.
Take makesjs/demo2
questions.js
for example, “makes” will form properties
and features
like this:
var properties = {
name: 'my-app',
description: '',
author: 'CP'
};
var features = [ 'nodejs', 'gitignore', 'license', 'babel' ];
Properties
The properties
from text prompts are only useful for @echo
and @eval
in preprocess file content.
/* @echo name */
var desc = /* @eval JSON.stringify(description) */;
Be careful, @echo
does not automatically escape the string in any situation, we can use @eval
to help escaping. We will explain more in preprocess file content.
Features
The features
array from answers of select/multi-select prompts have much wider usage in “makes”, it serves as the basis of any conditional logic. You can conditionally show questions, choices, files, part of file contents based on end user’s selected features
.
Boolean Prompt or Checkbox
Note “makes” doesn’t provide any boolean/checkbox prompt. To do a “yes/no” question, just use a select prompt.
{
message: 'Do you want to use PostCSS?',
choices: [
{title: 'No'},
{value: 'postcss', title: 'Yes'}
]
}
Please don’t use string like
"yes"
,"no"
,"true"
,"false"
in choice values. Because “makes” select prompt’s answer is not labelled,"yes"
and"no"
are not readable infeatures
array.
- use missing value for ‘No’ branch. When end user selected ‘No’, it adds nothing to
features
array. - use readable string like
'postcss'
in ‘Yes’ branch.