You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some template files under a folder doc/new.
One template (file.ejs.t) looks like:
---
to: doc/<%= name %>.md
---
And one (random.ejs.t) looks like:
---
to: doc/<%= h.customRandomGen() %>.md
---
The second one used a custom util function to generate a random file name.
But a filename name is required to be input for the first one.
I created a prompt.js under doc/new:
module.exports = [
{
type: "input",
name: "name",
message: "File name:",
validate: function (value) {
if (value.trim().length === 0) {
return "File name can't be empty!";
}
return true;
},
}
];
And I can generate files by doc new:file or doc new:random.
For doc new:file, it's ok to ask for a name input, but for doc new:random, no input is needed, but the prompt shows and since the validation I defined, I can't input empty.
Is there any way to filter the prompts array, based on the variables appeared in template file?
So for template A, which uses a required name and optional desc, template B which uses only a required name, template C which uses optional desc, and template D which uses no input,
I can define a single array of prompts:
I have some template files under a folder
doc/new
.One template (file.ejs.t) looks like:
And one (random.ejs.t) looks like:
The second one used a custom util function to generate a random file name.
But a filename
name
is required to be input for the first one.I created a
prompt.js
underdoc/new
:And I can generate files by
doc new:file
ordoc new:random
.For
doc new:file
, it's ok to ask for aname
input, but fordoc new:random
, no input is needed, but the prompt shows and since the validation I defined, I can't input empty.Is there any way to filter the prompts array, based on the variables appeared in template file?
So for template A, which uses a required
name
and optionaldesc
, template B which uses only a requiredname
, template C which uses optionaldesc
, and template D which uses no input,I can define a single array of prompts:
And the prompts are filtered:
template A:
name
,desc
template B:
name
template C:
desc
template D: nothing
Is there any way to do this?
The text was updated successfully, but these errors were encountered: