Skip to content

Commit

Permalink
node.js based build script for android working. updates to readme too
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil Maj committed Jan 12, 2012
1 parent 3550ad4 commit 694fb5e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
16 changes: 11 additions & 5 deletions README.md
Expand Up @@ -46,17 +46,23 @@ To use this plugin you will need to make sure you've registered your Facebook ap

# Getting Started

We've provided a few `install` scripts to get you rolling pretty quick.
We've provided a few `install` scripts to get you rolling pretty quick. PLEASE NOTE: only Android works for the `install` scripts at this time.

1. Download the latest version of PhoneGap from www.phonegap.com.

2. Create an Android or iOS PhoneGap project. Let's assume you have this
project under `~/phonegap-facebook`.

3. Depending what you've got handy, you could:
* ruby: `./install ~/phonegap-facebook`
* node: `node install.js ~/phonegap-facebook`
* Windows: `install.bat ~/phonegap-facebook`
3. Make sure you pull down all of the submodules by running `git
submodule update --init`.

4. Depending what you've got handy, you could:
* ruby (TODO!): `./install ~/phonegap-facebook <platform>`
* node: `node install.js ~/phonegap-facebook <platform>`
* Windows (TODO!): `install.bat ~/phonegap-facebook
<platform>`

In the above, `<platform>` represents either "android" or "ios".

If you don't like this script magic, you can always roll up your sleeves
and get into the nitty-gritty for the platform of your choice:
Expand Down
53 changes: 43 additions & 10 deletions install.js
@@ -1,13 +1,46 @@
function replaceInFile(filename, regexp, replacement) {
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile(filename, 1, true).ReadAll();
s = s.replace(regexp, replacement);
var f = fso.OpenTextFile(filename, 2, true);
f.Write(s);
f.Close();
var fs = require('fs'),
util = require('util'),
exec = require('child_process').exec,
puts = function(error, stdout, stderr) { util.puts(stdout); },
shell = function(command) { exec(command, puts); };

var appDir = process.argv[2],
platform = process.argv[3].toLowerCase();

// Normalize slash
if (appDir[appDir.length-1] != '/') {
appDir = appDir + '/';
}

file = File.expand_path(ARGV[0])
if (platform == 'android') {
// Add connect plugin to plugins.xml
var pluginsFile = appDir + 'res/xml/plugins.xml';
var pluginsXml = fs.readFileSync(pluginsFile).toString();
pluginsXml = pluginsXml.replace(/<\/plugins>/gi,'<plugin name="com.phonegap.facebook.Connect" value="com.phonegap.facebook.ConnectPlugin" /></plugins>');
fs.writeFileSync(pluginsFile, pluginsXml);

// Add placeholder element for facebook app secret
var manifestFile = appDir + 'AndroidManifest.xml';
var manifestXml = fs.readFileSync(manifestFile).toString();
manifestXml = manifestXml.replace(/<\/application>/gi, '<meta-data android:name="app_secret" android:value="your_app_secret" /></application>');
fs.writeFileSync(manifestFile, manifestXml);

// Generate and patch the facebook-js, then copy it into the
// application dir.
shell("cd lib/facebook-js-sdk && php all.js.php >> ../facebook_js_sdk.js && cd .. && patch < facebook-js-patch && cp lib/facebook_js_sdk.js " + appDir + "assets/www");

replaceInFile(file, /<plugin name="com.phonegap.facebook.Connect" value="com.phonegap.facebook.ConnectPlugin" \/>\n/gm, "");
replaceInFile(file, /\s*<\/plugins>/gm, "\t<plugin name=\"com.phonegap.facebook.Connect\" value=\"com.phonegap.facebook.ConnectPlugin\" />\n</plugins>");
// Create a facebook-android-sdk.jar file and copy it into the project
// dir
shell("cd lib/facebook-android-sdk/facebook && jar cf facebook-android-sdk.jar src && cp facebook-android-sdk.jar " + appDir + "libs");

// Copy native ConnectPlugin source into app dir
shell("cp -r native/android/ " + appDir);

// Copy ConnectPlugin JS into app dir
shell("cp www/pg-plugin-fb-connect.js " + appDir + "assets/www");

// Remind user to edit AndroidManifest.xml with their App Secret.
console.log('All done! Remember to update your AndroidManifest.xml with your APP_SECRET, as provided by Facebook. It\'s in a <meta-data> element that we just added to your manifest file! Go do it! Nao!');
} else if (platform == 'ios') {
console.log('Sorry dawg, not yet yo! Follow the manual iOS installation instructions in the README.');
}

0 comments on commit 694fb5e

Please sign in to comment.