Commits

Damon Oehlman  committed 3981c32

General refinements

  • Participants
  • Parent commits b372d0d
  • Tags v0.0.4

Comments (0)

Files changed (8)

File lib/commands/build.js

-var tasks = require('../tasks'),
+var debug = require('debug')('worx'),
+    tasks = require('../tasks'),
     out = require('out');
 
 exports.desc = 'Build the current project';
 
 exports.args = {
-    deploy: 'Deploy the build to the device'
+    signingPass: String
 };
 
 // export runner
 exports.run = function(opts, callback) {
-    tasks.run(['build'], process.cwd()).on('complete', function(err) {
+    debug('starting the build task');
+    tasks.run(['build'], process.cwd(), opts).on('complete', function(err) {
         if (err) return out.error(err);
 
     });

File lib/commands/deploy.js

 
 exports.desc = 'Deploy previously generated output files to the device';
 
-exports.args = {};
+exports.args = {
+    device: String
+};
 
 // export runner
 exports.run = function(opts, callback) {
-    tasks.run(['deploy'], process.cwd()).on('complete', function(err) {
+    tasks.run(['deploy'], process.cwd(), opts).on('complete', function(err) {
         if (err) return out.error(err);
 
     });

File lib/commands/install-debugtoken.js

+module.exports = require('../runTask');
+
+exports.args = {
+    device: 'target device name'
+};

File lib/commands/register-device.js

+var config = require('../config'),
+    out = require('out'),
+    prompt = require('prompt');
+
+exports.desc = 'Register a device configuration';
+
+exports.run = function(opts, callback) {
+    var args = opts.argv.remain,
+        deviceName = args[0];
+
+    // if we don't have a devicename, then abort with an error
+    if (! deviceName) {
+        callback(new Error('A device name is required for the register-device command: worx register-device %name%'));
+    }
+
+    // load the config, apply the changed setting and then save the config
+    config.load(function(cfg) {
+        // ensure we have a devices node within the configuration 
+        cfg.devices = cfg.devices || {};
+
+        out('Please provide the device ip and development mode password:');
+
+        // TODO: add validation rules
+        prompt.get(['ip', 'password'], function(err, result) {
+            if (err) return callback(err);
+
+            // update the configuration and save
+            cfg.devices[deviceName] = result;
+            config.save(cfg, callback);
+        });
+    });
+};

File lib/config.js

     configFile = path.resolve(homePath, '.worx'),
 
     defaultConfig = {
-        deviceIp: '169.254.0.1'
     },
 
     config;

File lib/runTask.js

+var debug = require('debug')('worx'),
+    tasks = require('./tasks'),
+    out = require('out');
+
+// export runner
+exports.run = function(opts, callback) {
+    var task = opts.argv.cooked[0],
+        runner = tasks.run.apply(null, [[task], process.cwd(), opts]);
+
+    debug('starting the ' + task + ' task');
+    runner.on('complete', function(err) {
+        if (err) return out.error(err);
+
+    });
+};

File lib/tasks.js

 var async = require('async'),
+    debug = require('debug')('worx'),
     fs = require('fs'),
     path = require('path'),
     mkdirp = require('mkdirp'),
         detached: true,
         stdio: 'inherit'
     },
-    requiredSettings = ['deviceIP', 'devicePass', 'sdkpath'],
+    requiredSettings = ['sdkpath'],
     projectFiles = [];
 
 // discover the nature of the project through 
     var done = this.async();
 
     // load the tool config
+    debug('loading the config');
     config.load(function(cfg) {
         // load the local config
         config.loadLocal(targetPath, function(localConfig) {
         return done(new Error('Missing settings: "' + missingSettings.join(', ') + '" please update worx configuration'));
     }
 
-    // ensure we have the deviceIp
-    if (! cfg.deviceIP) return 
-
     // ensure we have the bbwp command available
+    debug('checking bbwp exists within sdk path: ' + cfg.sdkpath);
     fs.exists(path.resolve(cfg.sdkpath, 'bbwp'), function(exists) {
         if (! exists) return done(new Error('Unable to find the bbwp command, ensure sdkpath configuration settings has been configured'));
 
 });
 
 task('prepare', ['loadConfig', 'checkConfig'], function(targetPath) {
-    mkdirp(path.resolve(targetPath, 'output'), this.async());
+    var outputPath = path.resolve(targetPath, 'output');
+
+    debug('preparing, creating output path: ' + outputPath);
+    mkdirp(outputPath, this.async());
 });
 
 task('package', ['discovery', 'prepare'], function(targetPath) {
     out('!{bold}creating archive');
 });
 
-task('build', ['package', 'prepare'], function(targetPath) {
+task('build', ['package', 'prepare'], function(targetPath, opts) {
     var cfg = _.clone(this.context.results.loadConfig),
         args = [
             path.resolve(targetPath, 'output', cfg.projectName + '.zip'),
             path.resolve('output')
         ];
 
-    if (config.signingPass) {
-        args = args.concat(['-g', config.signingPass]);
+    if (opts.signingPass) {
+        args = args.concat(['-g', opts.signingPass]);
     }
     else {
         args.push('-d');
     ).on('exit', this.async());
 });
 
-task('deploy', ['prepare'], function(targetPath) {
+task('deploy', ['prepare'], function(targetPath, opts) {
     var cfg = this.context.results.loadConfig,
-        args = [
-            '-installApp',
-            // '-launchApp',
-            '-password',
-            cfg.devicePass,
-            '-device',
-            cfg.deviceIP,
-            path.resolve(targetPath, 'output', 'device', cfg.projectName + '.bar')
-        ],
-        proc = spawn(path.resolve(cfg.toolsPath, 'blackberry-deploy' + commandExt), args, procOpts);
+        barFile = path.resolve(targetPath, 'output', 'device', cfg.projectName + '.bar')
 
-    
     out('!{bold}pushing to the device');
-    proc.on('exit', this.async());
+    blackberryDeploy(this, targetPath, opts, ['-installApp'], [barFile]);
+});
+
+task('install-debugtoken', ['prepare'], function(targetPath, opts) {
+    var tokenFile = opts.argv.remain[0];
+
+    // if we have no token file raise an exception
+    if (! tokenFile) throw new Error('token file required');
+
+    out('!{bold}installing debug token to device');
+    blackberryDeploy(this, targetPath, opts, ['-installDebugToken', tokenFile]);
 });
 
+/* internal helpers */
+
+function blackberryDeploy(task, targetPath, opts, args, endArgs) {
+    var cfg = task.context.results.loadConfig,
+        done = task.async(),
+        deviceCfg,
+        args, 
+        proc;
+
+    // ensure we have opts
+    opts = opts || {};
+
+    // use 'default' if the device name is not specified
+    deviceName = opts.device || 'default';
+
+    // check that we have a device configuration
+    deviceCfg = cfg.devices[deviceName];
+    debug('using device configuration: ' + deviceName, deviceCfg);
+
+    // if we have no device config then error out
+    if (! deviceCfg) return done(new Error('Device configuration not found for "' + deviceName + '", use the register-device command to supply details'));
+
+    args = args.concat([
+        '-device',
+        deviceCfg.ip,
+        '-password',
+        deviceCfg.password
+    ]).concat(endArgs || []);
+    
+    // console.log(args);
+    // console.log(targetPath, cfg.toolsPath);
+
+    // start the deploy process    
+    proc = spawn(path.resolve(cfg.toolsPath, 'blackberry-deploy' + commandExt), args, procOpts);
+    
+    proc.on('exit', done);
+}
+
 exports.run = task.run;

File package.json

   },
   "dependencies": {
     "async": "0.2.x",
+    "debug": "*",
     "fstream": "0.1.x",
     "mkdirp": "0.3.x",
+    "prompt": "0.2.x",
     "scaffolder": "0.7.x",
     "taskify": "0.5.x",
     "out": "0.4.x",