forked from facebookarchive/react-native-fbsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
561 additions
and
2,118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
include_defs("xplat//js/JS_DEFS") | ||
|
||
js_library( | ||
name = "react-native-fbsdk", | ||
srcs = js_glob( | ||
[ | ||
"**/*", | ||
], | ||
excludes = [ | ||
"bin/ios_setup.js", | ||
], | ||
), | ||
visibility = ["PUBLIC"], | ||
worker = "xplat//js:experimental-packager", | ||
deps = [ | ||
"xplat//js:node_modules", | ||
"xplat//js:react-native", | ||
"xplat//js:react-native-RNTester", | ||
"xplat//js:react-native-addons-node_modules", | ||
], | ||
) |
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
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,150 +1,157 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
/* | ||
Copyright 2004-present Facebook. All Rights Reserved. | ||
A node script to help set up FBSDK frameworks for use with https://github.com/facebook/react-native-fbsdk | ||
after you have already run `rnpm install react-native-fbsdk`. | ||
Note that you need to create a Facebook App in https://developers.facebook.com/ | ||
and get the Facebook APP ID and Facebook APP Name in order to set up the Info.plist. | ||
Usage: | ||
1. add to the package.json of your react-native project the following: | ||
1. add to the 'script' section in package.json of your react-native project the following: | ||
'"ios:setup": "node ./node_modules/react-native-fbsdk/bin/ios_setup.js"'. | ||
2. do 'npm run ios:setup <AppID> <AppName>'. | ||
*/ | ||
|
||
'use strict' | ||
'use strict'; | ||
|
||
/* eslint-disable no-console */ | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const plist = require('plist') | ||
const xcode = require('xcode') | ||
const AdmZip = require('adm-zip') | ||
const ProgressBar = require('progress') | ||
const got = require('got') | ||
const fall = require('fastfall')() | ||
const pump = require('pump') | ||
const AdmZip = require('adm-zip'); | ||
const ProgressBar = require('progress'); | ||
|
||
const progressBarPattern = ' downloading [:bar] :rate/bps :percent :etas' | ||
const frameworkDir = 'ios/Frameworks/' | ||
const zipFileName = 'fbsdk.zip' | ||
const zipFilePath = path.join(frameworkDir, zipFileName) | ||
const frameworkUrl = 'https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip' | ||
const fall = require('fastfall'); | ||
const fs = require('fs'); | ||
const got = require('got'); | ||
const path = require('path'); | ||
const plist = require('plist'); | ||
const pump = require('pump'); | ||
const xcode = require('xcode'); | ||
|
||
const progressBarPattern = ' downloading [:bar] :rate/bps :percent :etas'; | ||
const frameworkDir = 'ios/Frameworks/'; | ||
const zipFileName = 'fbsdk.zip'; | ||
const zipFilePath = path.join(frameworkDir, zipFileName); | ||
const frameworkUrl = 'https://origincache.facebook.com/developers/resources/?id=facebook-ios-sdk-current.zip'; | ||
|
||
// Get Facebook App ID and App Name. | ||
if (process.argv.length <= 3) { | ||
console.log('Usage: ios_setup.js <APPID> <APPNAME>') | ||
process.exit(-1) | ||
console.log('Usage: ios_setup.js <APPID> <APPNAME>'); | ||
process.exit(-1); | ||
} | ||
|
||
const appId = process.argv[2] | ||
const appName = process.argv[3] | ||
const appId = process.argv[2]; | ||
const appName = process.argv[3]; | ||
|
||
function downloadFbSdk (next) { | ||
try { | ||
fs.accessSync(frameworkDir, fs.F_OK) | ||
fs.accessSync(frameworkDir, fs.F_OK); | ||
} catch (e) { | ||
fs.mkdirSync(frameworkDir) | ||
fs.mkdirSync(frameworkDir); | ||
} | ||
|
||
var bar = null | ||
var bar = null; | ||
var download = got.stream(frameworkUrl) | ||
.on('data', chunk => { | ||
bar.tick(chunk.length) | ||
bar.tick(chunk.length); | ||
}) | ||
.on('response', res => { | ||
const len = parseInt(res.headers['content-length'], 10) | ||
const len = parseInt(res.headers['content-length'], 10); | ||
bar = new ProgressBar(progressBarPattern, { | ||
complete: '=', | ||
incomplete: ' ', | ||
width: 20, | ||
total: len | ||
}) | ||
}) | ||
total: len, | ||
}); | ||
}); | ||
|
||
var writeToFile = fs.createWriteStream(zipFilePath) | ||
pump(download, writeToFile, next) | ||
var writeToFile = fs.createWriteStream(zipFilePath); | ||
pump(download, writeToFile, next); | ||
} | ||
|
||
function unzipFramework (next) { | ||
console.log('Unzipping the framework') | ||
const zip = new AdmZip(zipFilePath) | ||
zip.extractAllTo(frameworkDir, true) | ||
fs.unlinkSync(zipFilePath) | ||
console.log('Framework Unzipped!') | ||
next() | ||
console.log('Unzipping the framework'); | ||
const zip = new AdmZip(zipFilePath); | ||
zip.extractAllTo(frameworkDir, true); | ||
fs.unlinkSync(zipFilePath); | ||
console.log('Framework Unzipped!'); | ||
next(); | ||
} | ||
|
||
function correctSearchPaths (next) { | ||
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj' | ||
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath) | ||
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj'; | ||
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath); | ||
rctfbsdkProject.parse(function (err) { | ||
if (err) { | ||
return next(err) | ||
return next(err); | ||
} | ||
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"') | ||
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync()) | ||
console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS') | ||
next() | ||
}) | ||
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/../../../ios/Frameworks"'); | ||
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync()); | ||
console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS'); | ||
next(); | ||
}); | ||
} | ||
|
||
function updateFBSDKFrameworks (next) { | ||
const files = fs.readdirSync('./ios/') | ||
var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj' })[0] | ||
const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj') | ||
myProjName = myProjName.replace('.xcodeproj', '') | ||
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...') | ||
const files = fs.readdirSync('./ios/'); | ||
var myProjName = files.filter((f) => { return f.substr(-10) === '.xcodeproj'; })[0]; | ||
const myProjPath = path.join('./ios/', myProjName, '/project.pbxproj'); | ||
myProjName = myProjName.replace('.xcodeproj', ''); | ||
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...'); | ||
|
||
const myProj = xcode.project(myProjPath) | ||
const myProj = xcode.project(myProjPath); | ||
myProj.parse(function (err) { | ||
if (err) { | ||
return next(err) | ||
return next(err); | ||
} | ||
myProj.pbxCreateGroup('Frameworks', './ios/Frameworks') | ||
myProj.pbxCreateGroup('Frameworks', './ios/Frameworks'); | ||
|
||
// NOTE: Assumes first target is the app. | ||
const target = myProj.getFirstTarget().uuid | ||
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true }) | ||
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true }) | ||
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true }) | ||
const target = myProj.getFirstTarget().uuid; | ||
myProj.addFramework('./ios/Frameworks/FBSDKCoreKit.framework', { 'customFramework': true, 'target': target, 'link': true }); | ||
myProj.addFramework('./ios/Frameworks/FBSDKShareKit.framework', { 'customFramework': true, 'target': target, 'link': true }); | ||
myProj.addFramework('./ios/Frameworks/FBSDKLoginKit.framework', { 'customFramework': true, 'target': target, 'link': true }); | ||
|
||
// WARNING: this will overwrite any existing search paths | ||
myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"') | ||
fs.writeFileSync(myProjPath, myProj.writeSync()) | ||
console.log('Finished updating ' + myProjPath) | ||
myProj.updateBuildProperty('FRAMEWORK_SEARCH_PATHS', '"$(PROJECT_DIR)/Frameworks/"'); | ||
fs.writeFileSync(myProjPath, myProj.writeSync()); | ||
console.log('Finished updating ' + myProjPath); | ||
|
||
next(null, files) | ||
}) | ||
next(null, files); | ||
}); | ||
} | ||
|
||
function updatePlist (files, next) { | ||
console.dir(files) | ||
var plistDirPath = '' | ||
console.dir(files); | ||
var plistDirPath = ''; | ||
files.map(function (file) { | ||
return path.join('./ios/', file) | ||
return path.join('./ios/', file); | ||
}).filter(function (file) { | ||
return fs.statSync(file).isDirectory() | ||
return fs.statSync(file).isDirectory(); | ||
}).forEach(function (file) { | ||
if (fs.readdirSync(file).indexOf('Base.lproj') !== -1) { | ||
plistDirPath = file | ||
plistDirPath = file; | ||
} | ||
}) | ||
const plistFilePath = path.join(plistDirPath, '/Info.plist') | ||
const plistFile = fs.readFileSync(plistFilePath, 'utf8') | ||
const plistObject = plist.parse(plistFile) | ||
plistObject.CFBundleURLTypes = [{CFBundleURLSchemes: ['fb' + appId]}] | ||
plistObject.FacebookAppID = appId | ||
plistObject.FacebookDisplayName = appName | ||
plistObject.LSApplicationQueriesSchemes = ['fbapi', 'fb-messenger-api', 'fbauth2', 'fbshareextension'] | ||
plistObject.NSLocationWhenInUseUsageDescription = '' | ||
fs.writeFileSync(plistFilePath, plist.build(plistObject)) | ||
console.log('Finished updating ' + plistFilePath) | ||
next() | ||
}); | ||
const plistFilePath = path.join(plistDirPath, '/Info.plist'); | ||
const plistFile = fs.readFileSync(plistFilePath, 'utf8'); | ||
const plistObject = plist.parse(plistFile); | ||
plistObject.CFBundleURLTypes = [{CFBundleURLSchemes: ['fb' + appId]}]; | ||
plistObject.FacebookAppID = appId; | ||
plistObject.FacebookDisplayName = appName; | ||
plistObject.LSApplicationQueriesSchemes = ['fbapi', 'fb-messenger-api', 'fbauth2', 'fbshareextension']; | ||
plistObject.NSLocationWhenInUseUsageDescription = ''; | ||
fs.writeFileSync(plistFilePath, plist.build(plistObject)); | ||
console.log('Finished updating ' + plistFilePath); | ||
next(); | ||
} | ||
|
||
function done (err) { | ||
if (err) console.error(err) | ||
else console.log('DONE!') | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log('DONE!'); | ||
} | ||
} | ||
|
||
fall([downloadFbSdk, unzipFramework, correctSearchPaths, updateFBSDKFrameworks, updatePlist], done) | ||
fall([downloadFbSdk, unzipFramework, correctSearchPaths, updateFBSDKFrameworks, updatePlist], done); |
Oops, something went wrong.