When building Khaos templates, you have the ability to define the schema for all of the possible inputs. Though not required, providing a schema can yield a more pleasant and consistent user experience.
Note that the schema here is a JavaScript Object that is used when prompting the user for the names to be used in the scaffolding process. This is an example of a schema object:
{
name: 'string',
siblings: 'number',
deceased: 'boolean',
secret: 'password'
}
..which will generate this prompt:
name: andy
siblings: 0
deceased: (y/N) N
secret:
Khaos uses prompt-for
to prompt the user on the command line for inputs. The schema object is passed directly to the prompt-for
module.
You can pass more complex objects such as:
{
name: {
label: 'What\'s your name?',
hint: 'e.g. Steve Brule'
required: true
},
url: {
label: 'What is the URL?',
required: true
}
twitter: {
label: 'If you want to link your Twitter, what\'s your username?'
}
}
More information about schema objects can be found at the prompt-for
repo.
With the JavaScript API, you can just pass the schema object as such:
var template = resolve('../path/to/template');
var schema = require('../path/to/schema.json');
var khaos = new Khaos(template)
.schema(schema);
More information here.