Remove CLI tooling from Cylon

It now lives in hybridgroup/cylon-cli.
This commit is contained in:
Andrew Stewart 2014-03-27 14:45:36 -07:00
parent da07a5644f
commit 2d11e75434
22 changed files with 0 additions and 738 deletions

View File

@ -1,86 +0,0 @@
#!/usr/bin/env node
require('../lib/cli/cli-commands');
var Program = require('commander'),
Pkg = require('../package.json'),
globule = require('globule');
Program
.version(Pkg.version)
.usage('[command] [options]');
Program
.command("generate <name>")
.description("Generates a new adaptor")
.action(function(name) { require('../lib/generators/adaptor')(name) });
Program
.command("scan <type>")
.description("Scans serial, bluetooth or usb (pass param <serial> | <bluetooth> | <usb>) for connected devices")
.action(function(type) {
var scan = new Cylon.CLI.Scan();
scan.search(type);
});
Program
.command("bluetooth <subcmd> [address] [option]")
.description("Scan, pair, unpair bluetooth devices to/from the PC, establishes serial to bluetooth connection. Try 'cylon bluetooth help'")
.action(function(subcmd, address, option){
var bluetooth = new Cylon.CLI.Bluetooth();
switch(subcmd){
case 'pair':
option = (option === null || option === undefined) ? 'hci0' : option;
bluetooth.pair(option, address);
break;
case 'unpair':
option = (option === null || option === undefined) ? 'hci0' : option;
bluetooth.unpair(option, address);
break;
case 'connect':
option = (option === null || option === undefined) ? '/dev/rfcomm0' : option;
bluetooth.connect(option, address);
break;
case 'scan':
bluetooth.scan();
break;
default:
console.log("cylon bluetooth argument not recognized, try:\n");
console.log("1.- cylon bluetooth scan");
console.log("2.- cylon bluetooth pair <address> [hciX]");
console.log("3.- cylon bluetooth unpair <address> [hciX]");
console.log("4.- cylon bluetooth connect <address> [dev]\n");
}
});
var cylonModules = globule.find('cylon-*', { srcBase: 'node_modules'}),
cylonModule;
cylonModules.forEach(function(moduleName){
cylonModule = require(moduleName);
if (typeof cylonModule.registerCommands === 'function') {
var name,
command,
commands = cylonModule.registerCommands(),
// get subcommand arguments
args = process.argv.slice(3);
for (name in commands) {
command = commands[name];
Program
.command(name)
.description(command.description)
.action(function(){
command.command(args);
});
}
}
});
var argv = Program.parse(process.argv);
// print help if no arguments were provided
if(!Program.args.length) { Program.help(); }

View File

@ -1,49 +0,0 @@
var os = require('os'),
namespace = require('node-namespace');
namespace("Cylon.CLI", function() {
this.Arduino = (function() {
function Arduino() {}
Arduino.prototype.upload = function(serialPort, hexFile) {
var cylonProcess = new Cylon.Process(),
part = '-patmega328p',
programmer = '-carduino',
baudrate = '-b115200',
hexFile = "-Uflash:w:" + hexFile + ":i",
port = serialPort.search(/[\/\:]/) >= 0 ? "-P" + serialPort : "-P/dev/" + serialPort;
switch (os.platform()) {
case 'linux':
cylonProcess.spawn('avrdude', [part, programmer, port, baudrate, '-D', hexFile]);
break;
case 'darwin':
cylonProcess.spawn('avrdude', [part, programmer, port, baudrate, '-D', hexFile]);
break;
default:
console.log('OS not yet supported...\n');
}
return true;
};
Arduino.prototype.install = function() {
var cylonProcess = new Cylon.Process();
switch (os.platform()) {
case 'linux':
console.log("Should be installing...");
cylonProcess.spawn('sudo', ['apt-get', 'install', 'avrdude']);
break;
case 'darwin':
cylonProcess.exec('brew install avrdude');
break;
default:
console.log('OS not yet supported...\n');
}
return true;
};
return Arduino;
})();
});

View File

@ -1,58 +0,0 @@
var os = require('os'),
namespace = require('node-namespace');
namespace("Cylon.CLI", function() {
this.Bluetooth = (function() {
function Bluetooth() {
this.process = new Cylon.Process();
this.platform = os.platform();
}
Bluetooth.prototype.pair = function(hciX, address) {
switch (this.platform) {
case 'linux':
this.process.spawn('bluez-simple-agent', [hciX, address]);
break;
case 'darwin':
console.log("OS X manages Bluetooth pairing itself.");
break;
default:
console.log("OS not yet supported.");
}
};
Bluetooth.prototype.unpair = function(hciX, address) {
switch (this.platform) {
case 'linux':
this.process.spawn('bluez-simple-agent', [hciX, address, 'remove']);
break;
case 'darwin':
console.log("OS X manages Bluetooth unpairing itself.");
break;
default:
console.log("OS not yet supported.");
}
};
Bluetooth.prototype.connect = function(dev, address) {
switch (this.platform) {
case 'linux':
this.process.spawn('sudo', ['rfcomm', 'connect', dev, address, '1']);
break;
case 'darwin':
console.log("OS X manages binding itself.");
break;
default:
console.log("OS not yet supported");
}
};
Bluetooth.prototype.scan = function() {
var scan = new Cylon.CLI.Scan();
scan.bluetooth();
};
return Bluetooth;
})();
});

View File

@ -1,7 +0,0 @@
// Make Cylon.CLI.Arduino available for other modules
// executing commands
require("./process");
require('./arduino');
require('./scan');
require('./bluetooth');

View File

@ -1,46 +0,0 @@
var spawn = require('child_process').spawn,
exec = require('child_process').exec,
namespace = require('node-namespace');
namespace("Cylon", function() {
this.Process = (function() {
function Process() {}
Process.prototype.exec = function(command) {
exec(command, function(err, stdout, stderr) {
if (stdout != null) {
console.log(stdout);
}
if (stderr != null) {
console.log(stderr);
}
if (err != null) {
console.log(err);
}
});
};
Process.prototype.spawn = function(command, args) {
var cmd;
cmd = spawn(command, args, {
stdio: 'inherit'
});
cmd.on('close', function(code) {
if (code !== 0) {
return console.log("ps process exited with code " + code);
}
});
cmd.on('exit', function(code) {
if (code !== 0) {
return console.log("ps process exited with code " + code);
}
});
};
return Process;
})();
});

View File

@ -1,51 +0,0 @@
var os = require('os'),
namespace = require('node-namespace');
namespace('Cylon.CLI', function() {
this.Scan = (function() {
function Scan() {
this.process = new Cylon.Process();
this.platform = os.platform();
}
Scan.prototype.serial = function(){
this.search('serial');
};
Scan.prototype.bluetooth = function(){
this.search('bluetooth');
};
Scan.prototype.usb = function(){
this.search('usb');
};
Scan.prototype.search = function(type) {
switch (this.platform) {
case 'linux':
switch (type) {
case 'serial':
this.process.exec("dmesg | grep tty");
break;
case 'bluetooth':
this.process.exec("hcitool scan");
break;
case 'usb':
this.process.exec("lsusb");
break;
default:
console.log("Device type not yet supported.");
break;
}
break;
case 'darwin':
this.process.exec("ls /dev/{tty,cu}.*");
break;
default:
console.log("OS not yet supported.");
}
};
return Scan;
})();
});

View File

@ -1,65 +0,0 @@
var wrench = require('wrench'),
ejs = require('ejs'),
glob = require('glob'),
fs = require('fs'),
pkg = require('../../package.json'),
adaptorName = "";
// Returns a cylon-namespaced adaptor name
var cylonAdaptorName = function() {
return "cylon-" + adaptorName;
};
// Converts the adaptor name to from camel_case to snake_case
var adaptorClassName = function() {
return String(adaptorName)
.replace(/[\W_]/g, ' ')
.toLowerCase()
.replace(/(?:^|\s|-)\S/g, function(c){ return c.toUpperCase(); })
.replace(/\s/g, '');
};
var compileTemplates = function() {
console.log("Compiling templates.");
glob(cylonAdaptorName() + "/**/*.tpl", function(err, files) {
files.forEach(function(filename) {
var templateData = generateTemplateData();
var newFilename = String(filename)
.replace(/adaptorName/, cylonAdaptorName())
.replace(/\.tpl$/, '');
fs.rename(filename, newFilename, function(err) {
if (err) { return console.log(err); }
fs.readFile(newFilename, 'utf8', function(err, contents) {
if (err) { return console.log(err); }
var result = ejs.render(contents, templateData);
fs.writeFile(newFilename, result, function(err) {
if (err) { return console.log(err); }
});
});
});
});
});
};
var generateTemplateData = function() {
return {
adaptorName: cylonAdaptorName(),
adaptorClassName: adaptorClassName(),
basename: String(adaptorName).toLowerCase(),
cylonVersion: pkg.version
};
};
var generator = function(name) {
adaptorName = name;
console.log("Creating " + cylonAdaptorName() + " adaptor.");
wrench.copyDirSyncRecursive(__dirname + "/adaptor", cylonAdaptorName());
compileTemplates();
};
module.exports = generator;

View File

@ -1,2 +0,0 @@
/node_modules/
npm-debug.log

View File

@ -1,29 +0,0 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"node": true,
"predef": [
"Cylon",
"Logger",
"after",
"bind",
"constantly",
"every",
"hasProp",
"proxyFunctionsToObject",
"proxyTestStubs",
"sleep",
"slice",
"subclass"
]
}

View File

@ -1 +0,0 @@
# TODO - put your license here

View File

@ -1,17 +0,0 @@
BIN := ./node_modules/.bin
TEST_FILES := test/support/globals.js $(shell find test/specs -type f -name "*.js")
# Our 'phony' make targets (don't involve any file changes)
.PHONY: test bdd lint
# Run Mocha, with standard reporter.
test:
@$(BIN)/mocha -r cylon --colors $(TEST_FILES)
# Run Mocha, with more verbose BDD reporter.
bdd:
@$(BIN)/mocha -r cylon --colors -R spec $(TEST_FILES)
# Run JSHint
lint:
@$(BIN)/jshint ./lib

View File

@ -1,68 +0,0 @@
# Cylon.js For <%= adaptorClassName %>
Cylon.js (http://cylonjs.com) is a JavaScript framework for robotics and
physical computing using Node.js
This repository contains the Cylon adaptor for <%= adaptorClassName %>.
Want to use Ruby on robots? Check out our sister project Artoo (http://artoo.io)
Want to use the Go programming language to power your robots? Check out our
sister project Gobot (http://gobot.io).
For more information about Cylon, check out our repo at
https://github.com/hybridgroup/cylon
## Getting Started
Install the module with: `npm install <%= adaptorName %>`
## Examples
## Connecting
### JavaScript
```javascript
var Cylon = require('cylon');
Cylon.robot({
connection: { name: '<%= basename %>', adaptor: '<%= basename %>' },
device: {name: '<%= basename %>', driver: '<%= basename %>'},
work: function(my) {
// provide an example of your module here
}
}).start();
```
### CoffeeScript
```
Cylon = require 'cylon'
Cylon.robot
connection: { name: '<%= basename %>', adaptor: '<%= basename %>' }
device: { name: '<%= basename %>', driver: '<%= basename %>' }
work: (my) ->
# provide an example of your module here
.start()
```
Explain how to connect from the computer to the device here...
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code
using `make test` and `make lint`.
## Release History
None yet...
## License
Copyright (c) 2014 Your Name Here. See `LICENSE` for more details

View File

@ -1,34 +0,0 @@
/*
* <%= adaptorName %> adaptor
* http://cylonjs.com
*
* Copyright (c) 2014 Your Name Here
* Licensed under the Apache 2.0 license.
*/
"use strict";
var namespace = require('node-namespace');
require('./<%= adaptorName %>');
require('./driver');
namespace('Cylon.Adaptors', function() {
this.<%= adaptorClassName %> = (function(klass) {
subclass(<%= adaptorClassName %>, klass);
function <%= adaptorClassName %>(opts) {
if (opts == null) { opts = {}; }
<%= adaptorClassName %>.__super__.constructor.apply(this, arguments);
}
<%= adaptorClassName %>.prototype.connect = function(callback) {
return <%= adaptorClassName %>.__super__.connect.apply(this, arguments);
};
return <%= adaptorClassName %>;
})(Cylon.Adaptor);
});
module.exports = Cylon.Adaptors.<%= adaptorClassName %>;

View File

@ -1,39 +0,0 @@
/*
* <%= adaptorName %>
* http://cylonjs.com
*
* Copyright (c) 2014 Your Name Here
* Your License Here
*/
"use strict";
require('cylon');
require('./adaptor');
require('./driver');
module.exports = {
adaptor: function(opts) {
// Provide a function that's an instance of your adaptor here. For example,
// the Sphero adaptor creates a new instance of the Sphero adaptor class:
//
// new Cylon.Adaptors.Sphero(args...)
return new Cylon.Adaptors.<%= adaptorClassName %>(opts);
},
driver: function(opts) {
// Provide a function that's an instance of your driver here. For example,
// the Sphero adaptor creates a new instance of the Sphero driver class:
//
// new Cylon.Drivers.Sphero(args...)
return new Cylon.Drivers.<%= adaptorClassName %>(opts);
},
register: function(robot) {
// Bootstrap your adaptor here. For example, with a Sphero, you would call
// the registerAdaptor and registerDriver functions as follows:
//
// robot.registerAdaptor('cylon-sphero', 'sphero');
// robot.registerDriver('cylon-sphero', 'sphero');
}
};

View File

@ -1,33 +0,0 @@
/*
* <%= adaptorName %> driver
* http://cylonjs.com
*
* Copyright (c) 2014 Your Name Here
* Licensed under the Apache 2.0 license.
*/
"use strict";
require('./<%= adaptorName %>');
require('./adaptor');
var namespace = require('node-namespace');
namespace("Cylon.Drivers", function() {
this.<%= adaptorClassName %> = (function(klass) {
subclass(<%= adaptorClassName %>, klass);
function <%= adaptorClassName %>() {
<%= adaptorClassName %>.__super__.constructor.apply(this, arguments);
}
<%= adaptorClassName %>.prototype.start = function(callback) {
return <%= adaptorClassName %>.__super__.start.apply(this, arguments);
};
return <%= adaptorClassName %>;
})(Cylon.Driver);
});
module.exports = Cylon.Drivers.<%= adaptorClassName %>;

View File

@ -1,33 +0,0 @@
{
"name": "<%= adaptorName %>",
"version": "0.1.0",
"main": "lib/<%= adaptorName %>.js",
"description": "Cylon module for <%= adaptorClassName %>",
"homepage": "http://cylonjs.com",
"bugs": "Your bug report URL here",
"author": {
"name": "Your Name Here",
"email": "Your Email Here",
"url": "Your URL here"
},
"repository": {
"type": "git",
"url": "your git URL here"
},
"licenses": [
{
"type": "your license type here"
}
],
"devDependencies": {
"sinon-chai": "~2.5.0",
"chai": "~1.9.0",
"mocha": "~1.17.1",
"sinon": "~1.8.2",
"jshint": "~2.4.4"
},
"dependencies": {
"node-namespace": "~1.0.0",
"cylon": "~<%= cylonVersion %>"
}
}

View File

@ -1,9 +0,0 @@
"use strict";
var <%= adaptorClassName %> = source("adaptor");
describe("Cylon.Adaptors.<%= adaptorClassName %>", function() {
var adaptor = new <%= adaptorClassName %>();
it("needs tests");
});

View File

@ -1,17 +0,0 @@
"use strict";
var module = source("<%= adaptorName %>");
describe("Cylon.<%= adaptorClassName %>", function() {
it("should be able to register", function() {
expect(module.register).to.be.a('function');
});
it("should be able to create adaptor", function() {
expect(module.adaptor()).to.be.a('object');
});
it("should be able to create driver", function() {
expect(module.adaptor({ device: {} })).to.be.a('object');
});
});

View File

@ -1,11 +0,0 @@
"use strict";
var <%= adaptorClassName %> = source("driver");
describe("Cylon.Drivers.<%= adaptorClassName %>", function() {
var driver = new <%= adaptorClassName %>({
device: { connection: 'connect' }
});
it("needs tests");
});

View File

@ -1,47 +0,0 @@
'use strict';
// allow production modules to expose internal
// functions and properties for testing
process.env.NODE_ENV = 'test';
var path = require('path');
var chai = require('chai');
var sinonChai = require('sinon-chai');
require('cylon');
Logger.setup(false); // turn off Cylon's logger by default
global.chai = chai;
global.should = chai.should();
global.expect = chai.expect;
global.assert = chai.assert;
global.AssertionError = chai.AssertionError;
global.sinon = require('sinon');
global.spy = sinon.spy;
global.stub = sinon.stub;
// can be used by test modules to require production modules,
// relative to the base path (where the Gruntfile.js also lives)
global.source = function (src) {
var resource = path.normalize('../../lib/' + src);
return require(resource);
};
// can be used when you expect a function to throw an error
global.err = function (fn, msg) {
try {
fn();
throw new chai.AssertionError({ message: 'Expected an error' });
} catch (err) {
if ('string' === typeof msg) {
chai.expect(err.message).to.equal(msg);
} else {
chai.expect(err.message).to.match(msg);
}
}
};
chai.use(sinonChai);
// if you want a detailed error stack output
chai.Assertion.includeStack = true;

View File

@ -1,25 +0,0 @@
'use strict';
require('./globals');
var grunt = require('grunt');
var Mocha = require('mocha');
var mocha = new Mocha({ reporter: 'spec', ui: 'bdd'});
function run(cb) {
var files = grunt.file.expand(__dirname + '/../specs/**/*.spec.js');
console.log(files);
files.forEach(function (file) {
mocha.addFile(file);
});
cb();
}
run(function (err) {
if (err) { throw err; }
mocha.run(function (failures) {
process.exit(failures);
});
});

View File

@ -25,10 +25,6 @@
"async": true,
"node-namespace": true,
"./lib": true,
"./lib/cli": false
},
"bin": {
"cylon": "./bin/cylon"
},
"devDependencies": {
"sinon-chai": "~2.5.0",
@ -41,13 +37,6 @@
"async": "~0.2.9",
"node-namespace": "~1.0.0",
"express.io": "~1.1.13",
"wrench": "~1.5.4",
"glob": "~3.2.7",
"ejs": "~0.8.5",
"commander": "~2.1.0",
"globule": "~0.2.0",
"robeaux": ">= 0.0.4"
}
}