start of bb support. for platform + build commands
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/d240242d Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/d240242d Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/d240242d Branch: refs/heads/cordova-client Commit: d240242d599cc9d68ad5d2e89ab85ab3ac0d42f8 Parents: 8bb3780 Author: Fil Maj <maj....@gmail.com> Authored: Wed Sep 26 12:02:21 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Wed Sep 26 12:02:21 2012 -0700 ---------------------------------------------------------------------- README.md | 1 + package.json | 3 +- platforms.js | 2 +- src/build.js | 126 +++++++++++++++++++++++++++++++++++++++++++------- src/platform.js | 6 +- src/util.js | 11 ++++- 6 files changed, 126 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index ed6d6f5..ee5a631 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ * [nodejs](http://nodejs.org/) * [git](https://help.github.com/articles/set-up-git) * SDKs for every platform you wish to support + - [BlackBerry WebWorks SDK](http://developer.blackberry.com) - [iOS SDK](http://developer.apple.com) - [Android SDK](http://developer.android.com) - **NOTE** This tool will not work unless you have the absolute latest updates for all http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 997fde8..1ebe39b 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "node-xcode":"git://github.com/imhotep/node-xcode.git", "express":"3.0", "shelljs":"0.0.7", - "ncallbacks":"1.0.0" + "ncallbacks":"1.0.0", + "prompt":"0.2.7" }, "devDependencies": { "jasmine-node":">=1.0.0" http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/platforms.js ---------------------------------------------------------------------- diff --git a/platforms.js b/platforms.js index 4acc953..544aa3d 100644 --- a/platforms.js +++ b/platforms.js @@ -1 +1 @@ -module.exports = ['ios', 'android', 'blackberry']; +module.exports = ['ios', 'android', 'blackberry-10']; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/src/build.js ---------------------------------------------------------------------- diff --git a/src/build.js b/src/build.js index f813f68..1ad5cc1 100644 --- a/src/build.js +++ b/src/build.js @@ -5,25 +5,46 @@ var cordova_util = require('./util'), shell = require('shelljs'), et = require('elementtree'), android_parser= require('./metadata/android_parser'), + blackberry_parser= require('./metadata/blackberry_parser'), ios_parser = require('./metadata/ios_parser'), n = require('ncallbacks'), + prompt = require('prompt'), util = require('util'); -function shell_out_to_debug(projectRoot, platform, www_target, js) { +function shell_out_to_debug(projectRoot, platform) { + var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 'debug > /dev/null'); + // TODO: wait for https://issues.apache.org/jira/browse/CB-1548 to be fixed before we axe this + // TODO: this is bb10 only for now + if (platform.indexOf('blackberry') > -1) { + cmd = 'ant -f ' + path.join(projectRoot, 'platforms', platform, 'build.xml') + ' qnx build'; + } + var response = shell.exec(cmd, {silent:true}); + if (response.code > 0) throw 'An error occurred while building the ' + platform + ' project. ' + response.output; +} + +function copy_www(projectRoot, platformRoot) { // Clean out the existing www. - shell.rm('-rf', path.join(www_target, 'www')); + var target = path.join(platformRoot, 'www'); + shell.rm('-rf', target); // Copy app assets into native package - shell.cp('-r', path.join(projectRoot, 'www'), www_target); + shell.cp('-r', path.join(projectRoot, 'www'), target); +} - // Copy in the appropriate JS - var jsPath = path.join(www_target, 'cordova.js'); - fs.writeFileSync(jsPath, fs.readFileSync(js)); +function copy_js(jsPath, platformPath) { + fs.writeFileSync(path.join(platformPath, 'www', 'cordova.js'), fs.readFileSync(jsPath, 'utf-8'), 'utf-8'); +} - // shell out to debug command - var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 'debug > /dev/null'); - var response = shell.exec(cmd, {silent:true}); - if (response.code > 0) throw 'An error occurred while building the ' + platform + ' project. ' + response.output; +function write_project_properties(cordovaConfig, projFile) { + // TODO: eventually support all blackberry sub-platforms + var props = fs.readFileSync(projFile, 'utf-8'); + props.replace(/qnx\.bbwp\.dir=.*$/, 'qnx.bbwp.dir=' + cordovaConfig.qnx.bbwp); + props.replace(/qnx\.sigtool\.password=.*$/, 'qnx.sigtool.password=' + cordovaConfig.qnx.signing_password); + props.replace(/qnx\.device\.ip=.*$/, 'qnx.device.ip=' + cordovaConfig.qnx.device_ip); + props.replace(/qnx\.device\.password=.*$/, 'qnx.device.password=' + cordovaConfig.qnx.device_password); + props.replace(/qnx\.sim\.ip=.*$/, 'qnx.sim.ip=' + cordovaConfig.qnx.sim_ip); + props.replace(/qnx\.sim\.password=.*$/, 'qnx.sim.password=' + cordovaConfig.qnx.sim_password); + fs.writeFileSync(projFile, props, 'utf-8'); } module.exports = function build (callback) { @@ -47,24 +68,95 @@ module.exports = function build (callback) { // Iterate over each added platform platforms.forEach(function(platform) { // Figure out paths based on platform - var assetsPath, js, parser; + // TODO this is fugly, lots of repetition. + var assetsPath, js, parser, platformPath; switch (platform) { case 'android': - assetsPath = path.join(projectRoot, 'platforms', 'android', 'assets'); + platformPath = path.join(projectRoot, 'platforms', 'android'); + assetsPath = path.join(platformPath, 'assets'); + parser = new android_parser(platformPath); + // Update the related platform project from the config + parser.update_from_config(cfg); + copy_www(projectRoot, assetsPath); js = path.join(__dirname, '..', 'lib', 'android', 'framework', 'assets', 'js', 'cordova.android.js'); - parser = new android_parser(path.join(projectRoot, 'platforms', 'android')); + copy_js(js, assetsPath); + shell_out_to_debug(projectRoot, 'android'); + end(); + break; + case 'blackberry-10': + platformPath = path.join(projectRoot, 'platforms', 'blackberry-10'); + js = path.join(__dirname, '..', 'lib', 'android', 'framework', 'assets', 'js', 'cordova.android.js'); + parser = new blackberry_parser(platformPath); + // Update the related platform project from the config parser.update_from_config(cfg); - shell_out_to_debug(projectRoot, 'android', assetsPath, js); + copy_www(projectRoot, platformPath); + + // Do we have BB config? + var dotFile = path.join(projectRoot, '.cordova'); + var dot = JSON.parse(fs.readFileSync(dotFile, 'utf-8')); + if (dot.blackberry === undefined || dot.blackberry.qnx === undefined) { + // Let's save relevant BB SDK + signing info to .cordova + console.log('Looks like we need some of your BlackBerry development environment information. We\'ll just ask you a few questions and we\'ll be on our way to building.'); + prompt.start(); + prompt.get([{ + name:'bbwp', + required:true, + description:'Enter the full path to your BB10 bbwp executable' + },{ + name:'signing_password', + required:true, + description:'Enter your BlackBerry signing password', + hidden:true + },{ + name:'device_ip', + description:'Enter the IP to your BB10 device' + },{ + name:'device_password', + description:'Enter the password for your BB10 device' + },{ + name:'sim_ip', + description:'Enter the IP to your BB10 simulator' + },{ + name:'sim_password', + description:'Enter the password for your BB10 simulator' + } + ], function(err, results) { + if (err) throw 'Error during BlackBerry configuration retrieval'; + // Write out .cordova file + if (dot.blackberry === undefined) dot.blackberry = {}; + if (dot.blackberry.qnx === undefined) dot.blackberry.qnx = {}; + dot.blackberry.qnx.bbwp = results.bbwp; + dot.blackberry.qnx.signing_password = results.signing_password; + dot.blackberry.qnx.device_ip = results.device_ip; + dot.blackberry.qnx.device_password = results.device_password; + dot.blackberry.qnx.sim_ip = results.sim_ip; + dot.blackberry.qnx.sim_password = results.sim_password; + fs.writeFileSync(dotFile, JSON.stringify(dot), 'utf-8'); + console.log('Perfect! If you need to change any of these properties, just edit the .cordova file in the root of your cordova project (it\'s just JSON, you\'ll be OK).'); + // Update project.properties + write_project_properties(dot, path.join(platformPath, 'project.properties')); + // shell it + shell_out_to_debug(projectRoot, 'blackberry-10'); + end(); + }); + return; + } + // Write out config stuff to project.properties file + write_project_properties(dot, path.join(platformPath, 'project.properties')); + // Shell it + shell_out_to_debug(projectRoot, 'blackberry-10'); end(); break; case 'ios': - assetsPath = path.join(projectRoot, 'platforms', 'ios'); + platformPath = path.join(projectRoot, 'platforms', 'ios'); js = path.join(__dirname, '..', 'lib', 'ios', 'CordovaLib', 'javascript', 'cordova.ios.js'); - parser = new ios_parser(path.join(projectRoot, 'platforms', 'ios')); + parser = new ios_parser(platformPath); // Update the related platform project from the config parser.update_from_config(cfg, function() { - shell_out_to_debug(projectRoot, 'ios', assetsPath, js); + copy_www(projectRoot, platformPath); + copy_js(js, platformPath); + shell_out_to_debug(projectRoot, 'ios'); end(); }); break; http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/src/platform.js ---------------------------------------------------------------------- diff --git a/src/platform.js b/src/platform.js index 4f73917..2d349ee 100644 --- a/src/platform.js +++ b/src/platform.js @@ -44,17 +44,17 @@ module.exports = function platform(command, target, callback) { throw new Error('Platform "' + target + '" already exists' ); } // directory doesn't exist, run platform's create script - var bin = path.join(__dirname, '..', 'lib', target, 'bin', 'create'); + var bin = path.join(__dirname, '..', 'lib', cordova_util.underlyingLib(target), 'bin', 'create'); var pkg = cfg.packageName().replace(/[^\w.]/g,'_'); var name = cfg.name().replace(/\W/g,'_'); - var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (target=='blackberry'?name:pkg), name); + var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (cordova_util.underlyingLib(target)=='blackberry'?name:pkg), name); var create = shell.exec(command, {silent:true}); if (create.code > 0) { throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output); } cfg.add_platform(target); // TODO: this is fugly - switch(target) { + switch(cordova_util.underlyingLib(target)) { case 'android': var android = new android_parser(output); android.update_from_config(cfg); http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d240242d/src/util.js ---------------------------------------------------------------------- diff --git a/src/util.js b/src/util.js index fa0a77f..008c17e 100644 --- a/src/util.js +++ b/src/util.js @@ -9,6 +9,7 @@ var repos = { blackberry:'https://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks.git' }; + module.exports = { // Runs up the directory chain looking for a .cordova directory. // IF it is found we are in a Cordova project. @@ -29,7 +30,7 @@ module.exports = { // Determines whether the library has a copy of the specified // Cordova implementation havePlatformLib: function havePlatformLib(platform) { - var dir = path.join(__dirname, '..', 'lib', platform); + var dir = path.join(__dirname, '..', 'lib', module.exports.underlyingLib(platform)); return fs.existsSync(dir); }, /** @@ -39,6 +40,7 @@ module.exports = { */ getPlatformLib: function getPlatformLib(target) { // verify platform is supported + target = module.exports.underlyingLib(target); if (!repos[target]) { throw new Error('platform "' + target + '" not found.'); } @@ -71,5 +73,12 @@ module.exports = { if (checkout.code > 0) { throw ('An error occured during git-checkout of ' + outPath + ' to tag ' + cordova_lib_tag + '. ' + checkout.output); } + }, + underlyingLib:function underlyingLib(name) { + var pos = name.indexOf('-'); + if (pos > -1) { + name = name.substr(0, pos); + } + return name; } };