forked from Wizcorp/phonegap-facebook-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node.js based build script for android working. updates to readme too
- Loading branch information
Fil Maj
committed
Jan 12, 2012
1 parent
3550ad4
commit 694fb5e
Showing
2 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} |