Commits

Anonymous committed 72d8fc2

Building complete, deploy todo

Comments (0)

Files changed (2)

lib/commands/build.js

-var tasks = require('../tasks');
+var tasks = require('../tasks'),
+    out = require('out');
 
 exports.desc = 'Build the current project';
 
 exports.args = {
+    deploy: 'Deploy the build to the device'
 };
 
 // export runner
 exports.run = function(opts, callback) {
-    tasks.run(['package'], process.cwd());
+    tasks.run(['build'], process.cwd()).on('complete', function(err) {
+        if (err) return out.error(err);
+
+    });
 };
     out = require('out'),
     spawn = require('child_process').spawn,
     config = require('./config'),
+    _ = require('underscore'),
+    commandExt = process.platform == 'win32' ? '.bat' : '',
     reIgnoreFiles = /^(\.git|node_modules|Jakefile|\.DS_Store|template|output|lib|package.json)/,
     ignoreExtensions = ['.DS_Store', '.bar', '.zip'],
+    procOpts = {
+        detached: true,
+        stdio: 'inherit'
+    },
     projectFiles = [];
 
 // discover the nature of the project through 
-task('discovery', function(targetPath) {
+task('discovery', ['prepare'], function(targetPath) {
     var reader = fstream.Reader({
             path: targetPath,
             filter: function(entry) {
     out('!{bold}analyzing project structure');
 });
 
-task('prepare', function(targetPath) {
+task('loadConfig', function(targetPath) {
+    var done = this.async();
+
+    // load the tool config
+    config.load(function(cfg) {
+        // load the local config
+        config.loadLocal(targetPath, function(localConfig) {
+            done(null, _.extend({}, cfg, localConfig));
+        });
+    });
+});
+
+task('checkConfig', ['loadConfig'], function(targetPath) {
+    var done = this.async(),
+        cfg = this.context.results.loadConfig;
+
+    if (! cfg.sdkpath) return done(new Error('sdkpath setting not configured, cannot continue'));
+
+    // ensure we have the bbwp command available
+    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'));
+
+        done();
+    });
+});
+
+task('prepare', ['loadConfig', 'checkConfig'], function(targetPath) {
     mkdirp(path.resolve(targetPath, 'output'), this.async());
 });
 
 task('package', ['discovery', 'prepare'], function(targetPath) {
     var done = this.async(),
+        cfg = _.clone(this.context.results.loadConfig),
         basePath = path.resolve(targetPath),
-        relativeFiles, proc;
+        relativeFiles, proc,
+        targetFile = path.join('output', cfg.projectName + '.zip'),
+        args = [targetFile];
 
-    // load the local config
-    config.loadLocal(targetPath, function(cfg) {
-        var targetFile = path.join('output', cfg.projectName + '.zip'),
-            args = [targetFile];
+    relativeFiles = projectFiles.map(function(filename) {
+        return filename.slice(basePath.length + 1);
+    });
 
-        relativeFiles = projectFiles.map(function(filename) {
-            return filename.slice(basePath.length + 1);
-        });
+    proc = spawn('zip', args.concat(relativeFiles), {
+        cwd: path.resolve(targetPath)
+    });
 
-        proc = spawn('zip', args.concat(relativeFiles), {
-            cwd: path.resolve(targetPath)
-        });
+    proc.stdout.on('data', function(buffer) {
+        console.log(buffer.toString());
+    });
+    proc.on('exit', function(code) {
+        out('!{bold}zip completed with exit code: ' + code);
+        done();
+    });
 
-        proc.stdout.on('data', function(buffer) {
-            console.log(buffer.toString());
-        });
-        proc.on('exit', function(code) {
-            out('!{bold}zip completed with exit code: ' + code);
-            done();
-        });
+    out('!{bold}creating archive');
+});
 
-        out('!{bold}creating archive');
-    });
+task('build', ['package', 'prepare'], function(targetPath) {
+    var cfg = _.clone(this.context.results.loadConfig),
+        args = [
+            path.resolve(targetPath, 'output', cfg.projectName + '.zip'),
+            '-o',
+            path.resolve('output')
+        ];
+
+    if (config.signingPass) {
+        args = args.concat(['-g', config.signingPass]);
+    }
+    else {
+        args.push('-d');
+    }
+
+    out('!{bold}building bar file');
+    spawn(
+        path.resolve(cfg.sdkpath, 'bbwp' + commandExt),
+        args, 
+        procOpts
+    ).on('exit', this.async());
 });
 
 exports.run = task.run;