Skip to content

Commit

Permalink
Merge pull request #25 from mintuz/setup_for_exports
Browse files Browse the repository at this point in the history
Adding ability to use functions in consuming projects
  • Loading branch information
mintuz committed Aug 26, 2016
2 parents ee50278 + b70c234 commit c459662
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 129 deletions.
27 changes: 13 additions & 14 deletions README.md
Expand Up @@ -6,32 +6,31 @@ A Node CLI Tool for Sphero BB8 Robot using the [Sphero Javascript SDK](http://sd
# Install
Not yet on npm so you'll have to do it the good'ol fasioned way with a cheeky git clone

* `git clone git@github.com:mintuz/bb8-commander.git`
* `npm install`
* `node index.js setup`
* `npm install -g bb8-commander`
* `bb8 setup`
* Use commands below

# Commands

### Utility Commands
* `node index.js setup` - Command to save your BB8 Unit UUID to config for future reference
* `node index.js disconnect` - Command to disconnect from your BB8 Unit
* `bb8 setup` - Command to save your BB8 Unit UUID to config for future reference
* `bb8 disconnect` - Command to disconnect from your BB8 Unit

### Action Commands
* `node index.js disco` - Command to turn your BB8 Unit into a shining disco ball in the night
* `node index.js roll` - A simple command to make your BB8 Randomly roll in any direction.
* `node index.js desk-buddy` - A command to keep you company whilst working at your desk. Place in it's charging station to watch its head move round randomly.
* `node index.js weather --city="manchester" --country="uk" --api-key="ABCD"` - Command to turn your BB8 Unit into your very own weather reporter, uses OpenWeather so be sure to get your own API key
* `node index.js tweet --hash-tag="bb8" --delay=5000` - Command to search twitter and run the first hashtag it finds as a command. Eg a tweet "#disco #bb8" would run the `disco` command --consumer-key xxx --consumer-secret xxx --access-token-key xxx --access-token-secret xxx
* `node index.js power` - A command to get details of the battery state.
* `node index.js drive` - A command to enable you to take input from the keyboard and 'drive' your BB-8 with the arrow keys.
* `node index.js express --port=4000` - Command to run an express server which has a single POST endpoint which you can send a JSON object to. See below for more details.
* `bb8 disco` - Command to turn your BB8 Unit into a shining disco ball in the night
* `bb8 roll` - A simple command to make your BB8 Randomly roll in any direction.
* `bb8 desk-buddy` - A command to keep you company whilst working at your desk. Place in it's charging station to watch its head move round randomly.
* `bb8 weather --city="manchester" --country="uk" --api-key="ABCD"` - Command to turn your BB8 Unit into your very own weather reporter, uses OpenWeather so be sure to get your own API key
* `bb8 tweet --hash-tag="bb8" --delay=5000` - Command to search twitter and run the first hashtag it finds as a command. Eg a tweet "#disco #bb8" would run the `disco` command --consumer-key xxx --consumer-secret xxx --access-token-key xxx --access-token-secret xxx
* `bb8 power` - A command to get details of the battery state.
* `bb8 drive` - A command to enable you to take input from the keyboard and 'drive' your BB-8 with the arrow keys.
* `bb8 express --port=4000` - Command to run an express server which has a single POST endpoint which you can send a JSON object to. See below for more details.

### Express Server

Having the ability to run an Express server to issue commands to the BB8 unit opens up a bunch of possibilities. One of the main benefits of having an Express server is that you can integrate into [IFTTT](https://ifttt.com/) and at that point, you have entered the Internet of things.

To get started is really easy, all you need to do is run `node index.js express --port=4000` adn once your BB8 is connected, an Express server will be started.
To get started is really easy, all you need to do is run `bb8 express --port=4000` adn once your BB8 is connected, an Express server will be started.

You can then send commands directly to it via a POST request. It supports any SpheroSDK command as well as custom commands we have created. See below for some examples.

Expand Down
114 changes: 114 additions & 0 deletions bin/index.js
@@ -0,0 +1,114 @@
var program = require('commander'),
packageFile = require('../package.json'),
executeCommand = require('../libs/execute-command');

program.version(packageFile.version);

// Utility Actions

program
.command('setup')
.description('Command to setup BB8 With your Mac')
.action(require('../commands/setup'));

program
.command('disconnect')
.description('Command to disconnect from your BB8 Unit')
.action(function () {
executeCommand('disconnect');
});

// Real Actions

program
.command("dance")
.description("dance dance BB-8")
.action(function () {
executeCommand("dance");
});

program
.command('disco')
.description('Command to make your BB8 Unit A disco ball')
.action(function () {
executeCommand('disco');
});

program
.command('weather')
.description('Command to get the weather colour from your BB8 Unit')
.option('-c, --city <city>', 'City name such as manchester')
.option('-cc, --country <country>', 'Country name such as uk')
.option('-t, --access-token <accessToken>', 'API Key')
.action(function(options) {
executeCommand('weather', options);
});

program
.command('github')
.description('Command to get notifications of new issues and PRs')
.option('-t, --access-token <accessToken>', 'API Key')
.action(require('github'));

program
.command('roll')
.description('BB8 will roll!')
.action(function () {
executeCommand('roll');
});


program
.command('tweet')
.description('BB8 will respond to tweets!')
.option('-#, --hash-tag <hashTag>', 'Hashtag to search for. Defaults to "#bb8bbc"')
.option('-d, --delay <delay>', 'Interval delay for retrieving new tweets. Defaults to 10000')
.option('--consumer-key <consumerKey>', 'Twitter api consumer key')
.option('--consumer-secret <consumerSecret>', 'Twitter api consumer secret')
.option('--access-token-key <accessTokenKey>', 'Twitter api access token key')
.option('--access-token-secret <accessTokenSecret>', 'Twitter api access token secret')
.action(function (options) {
executeCommand('tweet', options);
});

program
.command('express')
.description('Command to setup express server')
.option('-p, --port <port>', 'Port to run express on. Defaults to 3000')
.action(function (options) {
executeCommand('express', options);
});

program
.command('desk-buddy')
.description('Command to keep you company whilst working at your desk. Place your BB8 in the charging station.')
.action(function (options) {
executeCommand('desk-buddy');
});

program
.command('power')
.description('Command to get the power state of the BB-8')
.action(function (options) {
executeCommand('power');
});

program
.command('gestures')
.description('Some gestures for your BB-8')
.action(function (options) {
executeCommand('gestures');
});

program
.command('drive')
.description('Command to accept keyboard input--use arrow keys')
.action(function (options) {
executeCommand('drive');
});

try {
program.parse(process.argv);
} catch (e) {
console.error(e);
}
116 changes: 2 additions & 114 deletions index.js
@@ -1,114 +1,2 @@
var program = require('commander'),
packageFile = require('./package.json'),
executeCommand = require('./libs/execute-command');

program.version(packageFile.version);

// Utility Actions

program
.command('setup')
.description('Command to setup BB8 With your Mac')
.action(require('./commands/setup'));

program
.command('disconnect')
.description('Command to disconnect from your BB8 Unit')
.action(function () {
executeCommand('disconnect');
});

// Real Actions

program
.command("dance")
.description("dance dance BB-8")
.action(function () {
executeCommand("dance");
});

program
.command('disco')
.description('Command to make your BB8 Unit A disco ball')
.action(function () {
executeCommand('disco');
});

program
.command('weather')
.description('Command to get the weather colour from your BB8 Unit')
.option('-c, --city <city>', 'City name such as manchester')
.option('-cc, --country <country>', 'Country name such as uk')
.option('-t, --access-token <accessToken>', 'API Key')
.action(function(options) {
executeCommand('weather', options);
});

program
.command('github')
.description('Command to get notifications of new issues and PRs')
.option('-t, --access-token <accessToken>', 'API Key')
.action(require('github'));

program
.command('roll')
.description('BB8 will roll!')
.action(function () {
executeCommand('roll');
});


program
.command('tweet')
.description('BB8 will respond to tweets!')
.option('-#, --hash-tag <hashTag>', 'Hashtag to search for. Defaults to "#bb8bbc"')
.option('-d, --delay <delay>', 'Interval delay for retrieving new tweets. Defaults to 10000')
.option('--consumer-key <consumerKey>', 'Twitter api consumer key')
.option('--consumer-secret <consumerSecret>', 'Twitter api consumer secret')
.option('--access-token-key <accessTokenKey>', 'Twitter api access token key')
.option('--access-token-secret <accessTokenSecret>', 'Twitter api access token secret')
.action(function (options) {
executeCommand('tweet', options);
});

program
.command('express')
.description('Command to setup express server')
.option('-p, --port <port>', 'Port to run express on. Defaults to 3000')
.action(function (options) {
executeCommand('express', options);
});

program
.command('desk-buddy')
.description('Command to keep you company whilst working at your desk. Place your BB8 in the charging station.')
.action(function (options) {
executeCommand('desk-buddy');
});

program
.command('power')
.description('Command to get the power state of the BB-8')
.action(function (options) {
executeCommand('power');
});

program
.command('gestures')
.description('Some gestures for your BB-8')
.action(function (options) {
executeCommand('gestures');
});

program
.command('drive')
.description('Command to accept keyboard input--use arrow keys')
.action(function (options) {
executeCommand('drive');
});

try {
program.parse(process.argv);
} catch (e) {
console.error(e);
}
module.exports.setup = require('./commands/setup');
module.exports.executeCommand = require('./libs/execute-command');
9 changes: 8 additions & 1 deletion package.json
@@ -1,15 +1,22 @@
{
"name": "bb8-commander",
"version": "1.3.0",
"version": "2.0.0",
"description": "A Node CLI Tool for Sphero BB8 Robot.",
"main": "index.js",
"bin": {
"bb8": "bin/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mintuz/bb8-commander.git"
},
"keywords": [
"BB8",
"Sphero",
"BB8 Commander",
"BB8 Javascript",
"BB8 Robot",
"Sphero Robot",
"Robot"
],
"author": "",
Expand Down

0 comments on commit c459662

Please sign in to comment.