diff --git a/bin/cylon b/bin/cylon index 944491d..73e70b3 100755 --- a/bin/cylon +++ b/bin/cylon @@ -2,7 +2,7 @@ var Program = require('commander'), Pkg = require('../package.json'), - CliCommands = require('../dist/cli/cli-commands'), + CliCommands = require('../lib/cli/cli-commands'), fs = require('fs'); Program @@ -12,7 +12,7 @@ Program Program .command("generate ") .description("Generates a new adaptor") - .action(function(name) { require('../src/generators/adaptor')(name) }); + .action(function(name) { require('../lib/generators/adaptor')(name) }); Program .command("scan ") @@ -36,7 +36,7 @@ Program break; case 'connect': option = (option === null || option === undefined) ? '/dev/rfcomm0' : option; - CliCommands.connectToSerial(option, address); + CliCommands.bluetooth.connect(option, address); break; case 'scan': CliCommands.bluetooth.scan(); diff --git a/lib/cli/bluetooth.js b/lib/cli/bluetooth.js index d019ead..6d0f7fd 100644 --- a/lib/cli/bluetooth.js +++ b/lib/cli/bluetooth.js @@ -1,44 +1,61 @@ -(function() { - var bluetooth, os, scan; +require("./process"); - require("./process"); +var bluetooth, + scan = require("./scan"), + os = require('os'); - scan = require("./scan"); +bluetooth = { + pair: function(hciX, address) { + var process = new Cylon.Process, + platform = os.platform(); - os = require('os'); - - bluetooth = { - pair: function(hciX, address) { - var platform, process; - process = new Cylon.Process; - platform = os.platform(); - switch (platform) { - case 'linux': - return process.spawn('bluez-simple-agent', [hciX, address]); - case 'darwin': - return console.log("OS X manages Bluetooth pairing itself."); - default: - return console.log("OS not yet supported."); - } - }, - unpair: function(hciX, address) { - var platform, process; - process = new Cylon.Process; - platform = os.platform(); - switch (platform) { - case 'linux': - return process.spawn('bluez-simple-agent', [hciX, address, 'remove']); - case 'darwin': - return console.log("OS X manages Bluetooth unpairing itself."); - default: - return console.log("OS not yet supported."); - } - }, - scan: function() { - return scan('bluetooth'); + switch (platform) { + case 'linux': + 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."); } - }; + }, - module.exports = bluetooth; + unpair: function(hciX, address) { + var process = new Cylon.Process, + platform = os.platform(); -}).call(this); + switch (platform) { + case 'linux': + 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."); + } + }, + + connect: function(dev, address) { + var process = new Cylon.Process, + platform = os.platform(); + + switch (platform) { + case 'linux': + 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"); + } + }, + + scan: function() { + scan('bluetooth'); + } +}; + +module.exports = bluetooth; diff --git a/lib/cli/cli-commands.js b/lib/cli/cli-commands.js index 194104f..3d89759 100644 --- a/lib/cli/cli-commands.js +++ b/lib/cli/cli-commands.js @@ -1,22 +1,17 @@ -(function() { - var bluetooth, cliCommands, connectToSerial, scan; +var bluetooth, cliCommands, connectToSerial, scan; - scan = require('./scan'); +var cliCommands, + scan = require('./scan'), + bluetooth = require('./bluetooth'), - connectToSerial = require('./connect-to-serial'); +cliCommands = { + scan: scan, + bluetooth: { + pair: bluetooth.pair, + unpair: bluetooth.unpair, + scan: bluetooth.scan, + connect: bluetooth.connect + } +}; - bluetooth = require('./bluetooth'); - - cliCommands = { - scan: scan, - connectToSerial: connectToSerial, - bluetooth: { - pair: bluetooth.pair, - unpair: bluetooth.unpair, - scan: bluetooth.scan - } - }; - - module.exports = cliCommands; - -}).call(this); +module.exports = cliCommands; diff --git a/lib/cli/connect-to-serial.js b/lib/cli/connect-to-serial.js deleted file mode 100644 index dee3916..0000000 --- a/lib/cli/connect-to-serial.js +++ /dev/null @@ -1,24 +0,0 @@ -(function() { - var connectToSerial, os; - - require("./process"); - - os = require('os'); - - connectToSerial = function(dev, address) { - var platform, process; - process = new Cylon.Process; - platform = os.platform(); - switch (platform) { - case 'linux': - return process.spawn('sudo', ['rfcomm', 'connect', dev, address, '1']); - case 'darwin': - return console.log("OS X manages binding itself."); - default: - return console.log("OS not yet supported"); - } - }; - - module.exports = connectToSerial; - -}).call(this); diff --git a/lib/cli/process.js b/lib/cli/process.js index 84f1ee4..c8c66fe 100644 --- a/lib/cli/process.js +++ b/lib/cli/process.js @@ -1,53 +1,48 @@ -(function() { - var exec, namespace, spawn; +var spawn = require('child_process').spawn, + exec = require('child_process').exec, + namespace = require('node-namespace'); - spawn = require('child_process').spawn; +namespace("Cylon", function() { + this.Process = (function() { + function Process() {} - exec = require('child_process').exec; + 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); + } + }); + }; - namespace = require('node-namespace'); + Process.prototype.spawn = function(command, args) { + var cmd; - namespace("Cylon", function() { - return this.Process = (function() { - function Process() {} + cmd = spawn(command, args, { + stdio: 'inherit' + }); - 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) { - return console.log(err); - } - }); - return true; - }; + cmd.on('close', function(code) { + if (code !== 0) { + return console.log("ps process exited with code " + code); + } + }); - 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); - } - }); - return cmd.on('exit', 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; + return Process; - })(); - }); + })(); +}); - module.exports = Cylon.Process; - -}).call(this); +module.exports = Cylon.Process; diff --git a/lib/cli/scan.js b/lib/cli/scan.js index 58f64f9..5dd521b 100644 --- a/lib/cli/scan.js +++ b/lib/cli/scan.js @@ -1,34 +1,35 @@ -(function() { - var os, scan; +require("./process"); - require("./process"); +var scan, + os = require('os'); - os = require('os'); +scan = function(type) { + var process = new Cylon.Process, + platform = os.platform(); - scan = function(type) { - var platform, process; - process = new Cylon.Process; - platform = os.platform(); - switch (platform) { - case 'linux': - switch (type) { - case 'serial': - return process.exec("dmesg | grep tty"); - case 'bluetooth': - return process.exec("hcitool scan"); - case 'usb': - return process.exec("lsusb"); - default: - return console.log("Device type not yet supported."); - } - break; - case 'darwin': - return process.exec("ls /dev/{tty,cu}.*"); - default: - return console.log("OS not yet supported."); - } - }; + switch (platform) { + case 'linux': + switch (type) { + case 'serial': + process.exec("dmesg | grep tty"); + break; + case 'bluetooth': + process.exec("hcitool scan"); + break; + case 'usb': + process.exec("lsusb"); + break; + default: + console.log("Device type not yet supported."); + break; + } + break; + case 'darwin': + process.exec("ls /dev/{tty,cu}.*"); + break; + default: + console.log("OS not yet supported."); + } +}; - module.exports = scan; - -}).call(this); +module.exports = scan; diff --git a/src/cli/bluetooth.coffee b/src/cli/bluetooth.coffee deleted file mode 100644 index 626261c..0000000 --- a/src/cli/bluetooth.coffee +++ /dev/null @@ -1,37 +0,0 @@ -require "./process" -scan = require "./scan" -os = require('os') - -bluetooth = - pair: (hciX, address) -> - process = new Cylon.Process - platform = os.platform() - - switch platform - when 'linux' - process.spawn 'bluez-simple-agent', [hciX, address] - - when 'darwin' - console.log "OS X manages Bluetooth pairing itself." - - else - console.log "OS not yet supported." - - unpair: (hciX, address) -> - process = new Cylon.Process - platform = os.platform() - - switch platform - when 'linux' - process.spawn 'bluez-simple-agent', [hciX, address, 'remove'] - - when 'darwin' - console.log "OS X manages Bluetooth unpairing itself." - - else - console.log "OS not yet supported." - - scan: () -> - scan('bluetooth') - -module.exports = bluetooth diff --git a/src/cli/cli-commands.coffee b/src/cli/cli-commands.coffee deleted file mode 100644 index a0996f0..0000000 --- a/src/cli/cli-commands.coffee +++ /dev/null @@ -1,13 +0,0 @@ -scan = require('./scan') -connectToSerial = require('./connect-to-serial') -bluetooth = require('./bluetooth') - -cliCommands = - scan: scan - connectToSerial: connectToSerial - bluetooth: - pair: bluetooth.pair - unpair: bluetooth.unpair - scan: bluetooth.scan - -module.exports = cliCommands diff --git a/src/cli/connect-to-serial.coffee b/src/cli/connect-to-serial.coffee deleted file mode 100644 index 59c54b1..0000000 --- a/src/cli/connect-to-serial.coffee +++ /dev/null @@ -1,18 +0,0 @@ -require "./process" -os = require 'os' - -connectToSerial = (dev, address) -> - process = new Cylon.Process - platform = os.platform() - - switch platform - when 'linux' - process.spawn 'sudo', ['rfcomm', 'connect', dev, address, '1'] - - when 'darwin' - console.log "OS X manages binding itself." - - else - console.log "OS not yet supported" - -module.exports = connectToSerial diff --git a/src/cli/process.coffee b/src/cli/process.coffee deleted file mode 100644 index c4b32ae..0000000 --- a/src/cli/process.coffee +++ /dev/null @@ -1,24 +0,0 @@ -spawn = require('child_process').spawn -exec = require('child_process').exec -namespace = require 'node-namespace' - -namespace "Cylon", -> - class @Process - exec: (command) -> - exec command, (err, stdout, stderr) -> - console.log(stdout) if stdout? - console.log(stderr) if stderr? - console.log(err) if err? - - true - - spawn: (command, args) -> - cmd = spawn command, args, { stdio: 'inherit' } - - cmd.on 'close', (code) -> - console.log "ps process exited with code #{code}" if code isnt 0 - - cmd.on 'exit', (code) -> - console.log "ps process exited with code #{code}" if code isnt 0 - -module.exports = Cylon.Process diff --git a/src/cli/scan.coffee b/src/cli/scan.coffee deleted file mode 100644 index 13a8449..0000000 --- a/src/cli/scan.coffee +++ /dev/null @@ -1,29 +0,0 @@ -require "./process" -os = require('os') - -scan = (type) -> - process = new Cylon.Process - platform = os.platform() - - switch platform - when 'linux' - switch type - when 'serial' - process.exec "dmesg | grep tty" - - when 'bluetooth' - process.exec "hcitool scan" - - when 'usb' - process.exec "lsusb" - - else - console.log "Device type not yet supported." - - when 'darwin' - process.exec "ls /dev/{tty,cu}.*" - - else - console.log "OS not yet supported." - -module.exports = scan