Skip to content
Permalink
Browse files
refactored builder to be able to build seperate platforms and attempt…
… to get blackberry running on a real device (still failing to get the _nativeReady set)
  • Loading branch information
gtanner committed Nov 24, 2011
1 parent b041684 commit aec62d23918ec8cf86b95cefd60a7b6a23fc540d
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 45 deletions.
@@ -1,2 +1,3 @@
pkg/
tags
.DS_Store
@@ -18,49 +18,10 @@ task('build', ['clean'], function () {

var util = require('util'),
fs = require('fs'),
files = [
"lib/platform/blackberry.js",
"lib/plugin/navigator.js",
"lib/plugin/notification.js",
"lib/plugin/accelerometer.js",
"lib/Channel.js",
"lib/builder.js",
"lib/utils.js",
"lib/exec/blackberry.js"
],
include = function (files, transform) {
files = files.map ? files : [files];
return files.map(function (file) {
var str = fs.readFileSync(file, "utf-8") + "\n";
return transform ? transform(str, file) : str;
}).join('\n');
}
output = "";
packager = require("./build/packager");

//include LICENSE
output += include("LICENSE", function (file) {
return "/*\n" + file + "\n*/\n";
});

//include require
output += include("thirdparty/browser-require/require.js");

//include modules
output += include(files, function (file, path) {
return "require.define('" + path.replace(/lib\//, "phonegap/").replace(/\.js$/, '') +
"', function (require, module, exports) {\n" + file + "});\n";
});

//include phonegap
output += include('lib/phonegap.js', function (file, path) {
return "require.define('phonegap'" +
", function (require, module, exports) {\n" + file + "});\n";
});

//include bootstrap
output += include('lib/bootstrap.js');

fs.writeFileSync(__dirname + "/pkg/phonegap.js", output);
packager.bundle("blackberry");
packager.bundle("ios");

util.puts(fs.readFileSync("build/dalek", "utf-8"));
});
@@ -0,0 +1,61 @@
var util = require('util'),
fs = require('fs');

module.exports = {
bundle: function (platform) {
var util = require('util'),
fs = require('fs'),
files = [
"lib/plugin/navigator.js",
"lib/plugin/notification.js",
"lib/plugin/accelerometer.js",
"lib/plugin/Connection.js",
"lib/plugin/network.js",
"lib/plugin/Camera.js",
"lib/plugin/" + platform + "/device.js",
"lib/Channel.js",
"lib/builder.js",
"lib/utils.js",
"lib/exec/" +platform + ".js"
],
include = function (files, transform) {
files = files.map ? files : [files];
return files.map(function (file) {
var str = fs.readFileSync(file, "utf-8") + "\n";
return transform ? transform(str, file) : str;
}).join('\n');
}
output = "";

//include LICENSE
output += include("LICENSE", function (file) {
return "/*\n" + file + "\n*/\n";
});

//include require
output += include("thirdparty/browser-require/require.js");

//include modules
output += include(files, function (file, path) {
return "require.define('" + path.replace(/lib\//, "phonegap/").replace(/\.js$/, '') +
"', function (require, module, exports) {\n" + file + "});\n";
});

//include platform
output += include('lib/platform/' + platform + '.js', function (file, path) {
return "require.define('phonegap/platform'" +
", function (require, module, exports) {\n" + file + "});\n";
});

//include phonegap
output += include('lib/phonegap.js', function (file, path) {
return "require.define('phonegap'" +
", function (require, module, exports) {\n" + file + "});\n";
});

//include bootstrap
output += include('lib/bootstrap.js');

fs.writeFileSync(__dirname + "/../pkg/phonegap." + platform + ".js", output);
}
};
@@ -88,7 +88,7 @@
Channel.join(function() {

var builder = require('phonegap/builder'),
platform = require('phonegap/platform/blackberry');
platform = require('phonegap/platform');


builder.build(platform.objects).into(window);
@@ -112,7 +112,8 @@
// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since
// it may be called before any PhoneGap JS is ready.
if (typeof _nativeReady !== 'undefined') {
if (typeof _nativeReady !== 'undefined' ||
DeviceInfo.uuid != undefined) {
_self.boot();
Channel["onNativeReady"].fire();
}
@@ -0,0 +1,109 @@
// This queue holds the currently executing command and all pending
// commands executed with PhoneGap.exec().
var commandQueue: [],
// Indicates if we're currently in the middle of flushing the command
// queue on the native side.
commandQueueFlushing: false,
/**
* Creates a gap bridge iframe used to notify the native code about queued
* commands.
*
* @private
*/
gapBridge,
createGapBridge = function() {
gapBridge = document.createElement("iframe");
gapBridge.setAttribute("style", "display:none;");
gapBridge.setAttribute("height","0px");
gapBridge.setAttribute("width","0px");
gapBridge.setAttribute("frameborder","0");
document.documentElement.appendChild(gapBridge);
};


module.exports = function() {
if (!DeviceInfo.uuid) {
alert("ERROR: Attempting to call PhoneGap.exec()"
+" before 'deviceready'. Ignoring.");
return;
}

var successCallback, failCallback, service, action, actionArgs;
var callbackId = null;
if (typeof arguments[0] !== "string") {
// FORMAT ONE
successCallback = arguments[0];
failCallback = arguments[1];
service = arguments[2];
action = arguments[3];
actionArgs = arguments[4];

// Since we need to maintain backwards compatibility, we have to pass
// an invalid callbackId even if no callback was provided since plugins
// will be expecting it. The PhoneGap.exec() implementation allocates
// an invalid callbackId and passes it even if no callbacks were given.
callbackId = 'INVALID';
} else {
// FORMAT TWO
splitCommand = arguments[0].split(".");
action = splitCommand.pop();
service = splitCommand.join(".");
actionArgs = Array.prototype.splice.call(arguments, 1);
}

// Start building the command object.
var command = {
className: service,
methodName: action,
arguments: []
};

// Register the callbacks and add the callbackId to the positional
// arguments if given.
if (successCallback || failCallback) {
callbackId = service + PhoneGap.callbackId++;
PhoneGap.callbacks[callbackId] =
{success:successCallback, fail:failCallback};
}
if (callbackId != null) {
command.arguments.push(callbackId);
}

for (var i = 0; i < actionArgs.length; ++i) {
var arg = actionArgs[i];
if (arg == undefined || arg == null) {
continue;
} else if (typeof(arg) == 'object') {
command.options = arg;
} else {
command.arguments.push(arg);
}
}

// Stringify and queue the command. We stringify to command now to
// effectively clone the command arguments in case they are mutated before
// the command is executed.
commandQueue.push(JSON.stringify(command));

// If the queue length is 1, then that means it was empty before we queued
// the given command, so let the native side know that we have some
// commands to execute, unless the queue is currently being flushed, in
// which case the command will be picked up without notification.
if (commandQueue.length == 1 && !commandQueueFlushing) {
if (!gapBridge) {
PhoneGap.createGapBridge();
}

gapBridge.src = "gap://ready";
}
}

/**
* Called by native code to retrieve all queued commands and clear the queue.
*/
PhoneGap.getAndClearQueuedCommands = function() {
json = JSON.stringify(commandQueue);
commandQueue = [];
return json;
}

@@ -17,8 +17,27 @@ module.exports = {
},
accelerometer: {
path: "phonegap/plugin/accelerometer"
},
camera: {
path: "phonegap/plugin/Camera"
},
network: {
children: {
connection: {
path: "phonegap/plugin/network"
}
}
},
device: {
path: "phonegap/plugin/blackberry/device"
}
}
},
Connection: {
path: "phonegap/plugin/Connection"
},
Camera: {
path: "phonegap/plugin/Camera"
}
}

@@ -0,0 +1,44 @@
module.exports = {
id: "ios",
objects: {
PhoneGap: {
path: "phonegap",
children: {
exec: {
path: "phonegap/exec/ios"
}
}
},
navigator: {
path: "phonegap/plugin/navigator",
children: {
notification: {
path: "phonegap/plugin/notification"
},
accelerometer: {
path: "phonegap/plugin/accelerometer"
},
camera: {
path: "phonegap/plugin/Camera"
},
network: {
children: {
connection: {
path: "phonegap/plugin/network"
}
}
},
device: {
path: "phonegap/plugin/ios/device"
}
}
},
Connection: {
path: "phonegap/plugin/Connection"
},
Camera: {
path: "phonegap/plugin/Camera"
}
}

};

0 comments on commit aec62d2

Please sign in to comment.