diff --git a/bin/cylon b/bin/cylon deleted file mode 100755 index 85f5383..0000000 --- a/bin/cylon +++ /dev/null @@ -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 ") - .description("Generates a new adaptor") - .action(function(name) { require('../lib/generators/adaptor')(name) }); - -Program - .command("scan ") - .description("Scans serial, bluetooth or usb (pass param | | ) for connected devices") - .action(function(type) { - var scan = new Cylon.CLI.Scan(); - scan.search(type); - }); - -Program - .command("bluetooth [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
[hciX]"); - console.log("3.- cylon bluetooth unpair
[hciX]"); - console.log("4.- cylon bluetooth connect
[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(); } diff --git a/lib/cli/arduino.js b/lib/cli/arduino.js deleted file mode 100644 index 856207d..0000000 --- a/lib/cli/arduino.js +++ /dev/null @@ -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; - - })(); -}); diff --git a/lib/cli/bluetooth.js b/lib/cli/bluetooth.js deleted file mode 100644 index 07eb738..0000000 --- a/lib/cli/bluetooth.js +++ /dev/null @@ -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; - - })(); -}); diff --git a/lib/cli/cli-commands.js b/lib/cli/cli-commands.js deleted file mode 100644 index b68e45e..0000000 --- a/lib/cli/cli-commands.js +++ /dev/null @@ -1,7 +0,0 @@ -// Make Cylon.CLI.Arduino available for other modules -// executing commands - -require("./process"); -require('./arduino'); -require('./scan'); -require('./bluetooth'); diff --git a/lib/cli/process.js b/lib/cli/process.js deleted file mode 100644 index 2e07f87..0000000 --- a/lib/cli/process.js +++ /dev/null @@ -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; - - })(); -}); diff --git a/lib/cli/scan.js b/lib/cli/scan.js deleted file mode 100644 index 208b7f8..0000000 --- a/lib/cli/scan.js +++ /dev/null @@ -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; - })(); -}); diff --git a/lib/generators/adaptor.js b/lib/generators/adaptor.js deleted file mode 100644 index edd59a3..0000000 --- a/lib/generators/adaptor.js +++ /dev/null @@ -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; diff --git a/lib/generators/adaptor/.gitignore b/lib/generators/adaptor/.gitignore deleted file mode 100644 index 91fa8cf..0000000 --- a/lib/generators/adaptor/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/node_modules/ -npm-debug.log diff --git a/lib/generators/adaptor/.jshintrc b/lib/generators/adaptor/.jshintrc deleted file mode 100644 index 9dd4203..0000000 --- a/lib/generators/adaptor/.jshintrc +++ /dev/null @@ -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" - ] -} diff --git a/lib/generators/adaptor/LICENSE b/lib/generators/adaptor/LICENSE deleted file mode 100644 index f12e11c..0000000 --- a/lib/generators/adaptor/LICENSE +++ /dev/null @@ -1 +0,0 @@ -# TODO - put your license here diff --git a/lib/generators/adaptor/Makefile b/lib/generators/adaptor/Makefile deleted file mode 100644 index 319469b..0000000 --- a/lib/generators/adaptor/Makefile +++ /dev/null @@ -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 diff --git a/lib/generators/adaptor/README.md.tpl b/lib/generators/adaptor/README.md.tpl deleted file mode 100644 index 1545283..0000000 --- a/lib/generators/adaptor/README.md.tpl +++ /dev/null @@ -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 diff --git a/lib/generators/adaptor/lib/adaptor.js.tpl b/lib/generators/adaptor/lib/adaptor.js.tpl deleted file mode 100644 index 4172f28..0000000 --- a/lib/generators/adaptor/lib/adaptor.js.tpl +++ /dev/null @@ -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 %>; diff --git a/lib/generators/adaptor/lib/adaptorName.js.tpl b/lib/generators/adaptor/lib/adaptorName.js.tpl deleted file mode 100644 index be391f4..0000000 --- a/lib/generators/adaptor/lib/adaptorName.js.tpl +++ /dev/null @@ -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'); - } -}; diff --git a/lib/generators/adaptor/lib/driver.js.tpl b/lib/generators/adaptor/lib/driver.js.tpl deleted file mode 100644 index 3f4d185..0000000 --- a/lib/generators/adaptor/lib/driver.js.tpl +++ /dev/null @@ -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 %>; diff --git a/lib/generators/adaptor/package.json.tpl b/lib/generators/adaptor/package.json.tpl deleted file mode 100644 index 91fa6a7..0000000 --- a/lib/generators/adaptor/package.json.tpl +++ /dev/null @@ -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 %>" - } -} diff --git a/lib/generators/adaptor/test/specs/adaptor.spec.js.tpl b/lib/generators/adaptor/test/specs/adaptor.spec.js.tpl deleted file mode 100644 index 23aef52..0000000 --- a/lib/generators/adaptor/test/specs/adaptor.spec.js.tpl +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -var <%= adaptorClassName %> = source("adaptor"); - -describe("Cylon.Adaptors.<%= adaptorClassName %>", function() { - var adaptor = new <%= adaptorClassName %>(); - - it("needs tests"); -}); diff --git a/lib/generators/adaptor/test/specs/adaptorName.spec.js.tpl b/lib/generators/adaptor/test/specs/adaptorName.spec.js.tpl deleted file mode 100644 index 49f3a8f..0000000 --- a/lib/generators/adaptor/test/specs/adaptorName.spec.js.tpl +++ /dev/null @@ -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'); - }); -}); diff --git a/lib/generators/adaptor/test/specs/driver.spec.js.tpl b/lib/generators/adaptor/test/specs/driver.spec.js.tpl deleted file mode 100644 index 4cc646c..0000000 --- a/lib/generators/adaptor/test/specs/driver.spec.js.tpl +++ /dev/null @@ -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"); -}); diff --git a/lib/generators/adaptor/test/support/globals.js b/lib/generators/adaptor/test/support/globals.js deleted file mode 100644 index 3a9dcc3..0000000 --- a/lib/generators/adaptor/test/support/globals.js +++ /dev/null @@ -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; diff --git a/lib/generators/adaptor/test/support/runner.js b/lib/generators/adaptor/test/support/runner.js deleted file mode 100644 index 0c256c3..0000000 --- a/lib/generators/adaptor/test/support/runner.js +++ /dev/null @@ -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); - }); -}); diff --git a/package.json b/package.json index f8b227f..9910752 100644 --- a/package.json +++ b/package.json @@ -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" } }