Silent mode
The -s
option
“makes” can run in silent mode (aka unattended mode).
- Runs demo2 with all default answers, note you need to supply project name in command line, otherwise the project name will be default “my-app”.
npx makes makesjs/demo2 app1 -s
- Runs demo2 with non-default choices.
npx makes makesjs/demo2 app2 -s ruby
For the second example, you can also reorder the arguments to npx makes makesjs/demo2 -s ruby app2
or npx makes -s ruby makesjs/demo2 app2
.
You cannot reorder the arguments for first example where -s
has no extra value, you can only use empty -s
at the end of a command. Or you can do npx makes -s= makesjs/demo2 app1
where -s=
is same as -s=""
, providing empty string as the value of -s
option.
Supply properties in silent mode
You can supply properties (for answers of text prompts) directly in command line.
npx makes makesjs/demo2 app1 --description "Awesome project" -s typescript
If you follow convention, always use camel case for text prompt name, for example:
{
name: 'projectOwner',
message: 'Name of the project owner?'
}
You can supply property as npx makes <skeleton> --project-owner "My Name" -s
.
Properly support silent mode
There is some complication for your questions.js
to support silent mode properly.
Let’s say you have a select default to positive option (the first choice):
{
message: 'Do you want to use PostCSS',
choices: [
{value: 'postcss', title: 'Yes'},
{title: 'No'}
]
}
There is nothing wrong, the silent mode will get default “postcss” in features
array. But now you have no way for silent mode to turn off “postcss”. The easiest fix is to use a valid value for negative choice:
{
message: 'Do you want to use PostCSS',
choices: [
{value: 'postcss', title: 'Yes'},
{value: 'no-postcss', title: 'No'}
]
}
You don’t need to use “no-postcss” anywhere in your skeleton, but it enables silent mode to turn off “postcss”:
npx makes <skeleton> my-project-name -s no-postcss
.
The simple rule is:
- use empty value on first choice, as much as possible. This is the easiest for silent mode to work.
- if you have to use empty value below first choice, and you want to support silent mode, use a negative term (like no-postcss) to give silent mode a chance to turn the feature off.
For multi-select, the situation is more troublesome.
- if there is no default
selected
choice, silent mode will work easily. - if there are some default
selected
choices, there is no way for silent mode to turn off all of them. However, for examplea
,b
andc
are default selected in a big multi-select, you can use silent mode-s a
to force choosinga
only, but silent mode has no way to de-select all of the three default. - if proper silent mode support is needed for multi-select with default
selected
choices, please avoid multi-select, break the mutli-select into multiple single-select (with choice of negative term).