npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vorpal-tour

v0.0.5

Published

Tour users through your Vorpal app.

Downloads

99

Readme

Vorpal - Tour

Build Status XO: Linted

A Vorpal.js extension for building a mature tour that walks users through your interactive CLI with ease.

Installation

npm install vorpal-tour
npm install vorpal

Getting Started

Simply use vorpal.use(tour, options) to add the tour as a Vorpal extension.

const vorpal = require('vorpal')();
const vorpalTour = require('vorpal-tour');

vorpal.use(vorpalTour, {
  command: 'tour',
  tour: function(tour) {
    // add tour steps, etc.
    return tour;
  }
});
Options
  • command: The name of the Vorpal command that will invoke the tour. Defaults to tour. By running use more than once, you can invoke multiple, separate tours.

  • tour: Expects a function that passes in a tour object. You then add steps and details to the tour, and return the tour object.

Building the tour

The tour object has a few basic commands to help you easily build a tour.

vorpal.use(vorpalTour, {
  command: 'tour',
  tour: function(tour) {
    // Colors the "tour guide" text. 
    tour.color('cyan');

    // Adds a step to the tour:
    // .begin spits user instructions when the step starts
    // .expect listens for an event. The function it calls 
    //   expects a `true` to be called in order for the step 
    //   to finish.
    // .reject spits text to the user when `false` is returned 
    //   on an `.expect` callback.
    // .wait waits `x` millis before completing the step
    // .end spits text to the user when the step completes.
    tour.step(1)
      .begin('Welcome to the tour! Run "foo".')
      .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');

    // A delay in millis between steps.
    tour.wait(1000);

    // Ends the tour, spits text to the user.
    tour.end('Very well done!');

    return tour;
  }
});
$ node ./myapp.js
myapp~$ tour

  ┌────────────────────────────────────────────────────────────┐
  |  Welcome to the tour! Run "foo".                           |
  └────────────────────────────────────────────────────────────┘

myapp$ bar

  ┌────────────────────────────────────────────────────────────┐
  |  Uh.. Let's type "foo" instead.                            |
  └────────────────────────────────────────────────────────────┘

myapp$ foo
bar
(... 500 millis ...)

  ┌────────────────────────────────────────────────────────────┐
  |  Nice! Wasn't that command just amazing?                   |
  └────────────────────────────────────────────────────────────┘

(... 1000 millis ...)

  ┌────────────────────────────────────────────────────────────┐
  |  Very well done!                                           |
  └────────────────────────────────────────────────────────────┘

myapp~$

Examples

API

tour

tour.color(chalkColor)

Sets the color of the text that guides the tour. Based on Chalk colors.

tour.color('magenta');
tour.step(1).begin('This is now magenta. Almost like unicorns.');
  ┌────────────────────────────────────────────────────────────┐
  |  This is now magenta. Almost like unicorns.                |
  └────────────────────────────────────────────────────────────┘
tour.prepare(function)

Runs a method just before the tour beings, in preparation for the tour. Expects a callback.

tour.prepare(function (callback) {
  vorpal.log('preparing...');
  callback();
});
tour.step(number)

Creates a new step in the tour, returning a chainable Step instance. See the step section below.

The step number does nothing for now, outside of giving you sanity. This may change.

var step = tour.step(1);
// ... now do things with the step
tour.wait(millis)

Delays a number of millis between multiple steps. The delay begins at the completion of the step.

tour.step(1); // ...

tour.wait(1000);

tour.step(2); // ...
tour.end([message])

Ends the tour, optionally printing a message for the user.

tour.step(895); // ...
tour.end('You really made it through all that? Wow. Well done.');
tour.cleanup(function)

Runs a method directly after the tour ends, in case you need to run cleanup code. Expects a callback.

tour.cleanup(function (callback) {
  mess.cleanup();
  callback();
});

step

step.begin(message)

Prints a message for the user at the start of the step.

tour.step(1).begin('To get started, touch your toes.');
  ┌────────────────────────────────────────────────────────────┐
  |  To get started, touch your toes.                          |
  └────────────────────────────────────────────────────────────┘
step.expect(event, function)

This is the listener that determines when the step has been completed.

Expects an event emitted from Vorpal. On each instance of the event, the function parameter is called, and expects you to return a callback passing true or false. On true, the step is considered to be fullfilled and will proceed to end.

tour.step(1)
  .begin('run "foo"')
  .expect("command", function (data, cb) {
    cb(data.command === 'foo');
  });

While standard events are supported, you can emit your own custom events from Vorpal, if needed.

Standard events:

command: returns {command: 'foo'}

keypress: returns { key, value, event }

submit: returns {}

step.reject(message)

If a step.expect is triggered and false is returned (meaning the event was not fulfilled), you can optionally print a reject message that instructs the user that they did the command incorrectly. This will print with a yellow border.

tour.step(1)
  .begin('run "foo"')
  .expect("command", function (data, cb) {
    cb(data.command === 'foo');
  })
  .reject('Okay, let\'s type "foo".');
step.wait(millis)

Once a step has been fulfilled, you can optionally wait a given amount of millis before completion.

tour.step(1)
  .begin('run "foo"')
  .expect("command", function (data, cb) {
    cb(data.command === 'foo');
  })
  .wait(1000);
step.end(message)

Once a step has been fulfilled and the any step.wait() time has passed, you can optionally add a final remark to the user before moving on to the next step, such as a comment on the last one.

tour.step(1)
  .begin('run "foo"')
  .expect("command", function (data, cb) {
    cb(data.command === 'foo');
  })
  .wait(1000)
  .end('Nice! Isn\'t that just foobar?');

Related

License

MIT © David Caccavella