-
Notifications
You must be signed in to change notification settings - Fork 3
/
silly-tour.js
executable file
·65 lines (53 loc) · 1.44 KB
/
silly-tour.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
'use strict';
const vorpal = require('vorpal')();
const vorpalTour = require('../dist/tour.js');
vorpal.command('foo')
.action(function (args, cb) {
this.log('bar');
cb();
});
vorpal.use(vorpalTour, {
command: 'tour',
tour: defineTour
});
vorpal
.delimiter('myamazingapp~$')
.show()
.parse(process.argv);
function defineTour(tour) {
tour.color('cyan');
tour.prepare(function (callback) {
// do anything you need to
// just before the tour starts.
callback();
});
tour.cleanup(function (callback) {
// Runs after the tour ends.
vorpal.log('(cleaned up tour)');
callback();
});
tour.step(1)
.begin('\nWelcome to my amazing app!\n\nTo start, run "foo".\n')
.expect('command', function (data, cb) {
cb(data.command === 'foo');
})
.reject('Uh.. Let\'s type "foo" instead..')
.wait(500)
.end('\nNice! Wasn\'t that command just amazing?\n');
tour.wait(1000);
tour.step(2)
.begin('\nNow press the left arrow key, and then the right one!\n')
.expect('keypress', function (keypress, cb) {
this._cache = this._cache || 0;
if (keypress.key === 'left' && this._cache === 0) {
this._cache = 1;
} else if (keypress.key === 'right' && this._cache === 1) {
this._cache = 2;
} else {
this._cache = 0;
}
cb(this._cache === 2);
});
tour.end('\nVery well done! You\'re such a master at my app!\n');
return tour;
}