-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic-wizard.js
68 lines (57 loc) · 1.45 KB
/
basic-wizard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
const inquirer = require('inquirer')
const Joi = require('joi')
const Bootme = require('./../packages/bootme')
const task = new Bootme.Task('foo')
task.validateConfig = function(value) {
return Joi.object()
.keys({
size: Joi.string().required(),
theme: Joi.string().required()
})
.validate(value)
}
task.setConfig(async () => {
const result = await inquirer.prompt([
{
type: 'list',
name: 'theme',
message: 'What do you want to do?',
choices: [
'Order a pizza',
'Make a reservation',
new inquirer.Separator(),
'Ask for opening hours',
{
name: 'Contact support',
disabled: 'Unavailable at this time'
},
'Talk to the receptionist'
]
},
{
type: 'list',
name: 'size',
message: 'What size do you need?',
choices: ['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'],
filter: function(val) {
return val.toLowerCase()
}
}
])
return result
})
task.setAction(async function(state) {
console.log('Do something!')
console.log('Config', this.config)
})
const registry = new Bootme.Registry()
const pipeline = new Bootme.Pipeline(registry)
registry.addTask(task)
registry.addHook('foo', 'onBefore', async function() {
console.log(`Before ${this.name}`)
})
registry.addHook('foo', 'onAfter', async function() {
console.log(`After ${this.name}`)
})
pipeline.execute()