forked from facebookarchive/react-native-fbsdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios_setup.js
120 lines (108 loc) · 4.54 KB
/
ios_setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 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. Copy the script into your react native project root
2. npm install the packages: plist, xcode, adm-zip.
3. do 'node ios_setup.js <AppID> <AppName>'.
*/
const fs = require('fs');
const path = require('path');
const plist = require('plist');
const spawn = require('child_process').spawn;
const xcode = require('xcode');
const AdmZip = require('adm-zip');
const frameworkDir = 'ios/Frameworks/';
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: ' + __filename + ' <APPID> <APPNAME>');
process.exit(-1);
}
const appId = process.argv[2];
const appName = process.argv[3];
// Download the FBSDK frameworks into a directory ./ios/Frameworks
try {
fs.accessSync(frameworkDir, fs.F_OK);
} catch (e) {
fs.mkdirSync(frameworkDir);
}
const zipFilePath = path.join(frameworkDir, 'fbsdk.zip');
const out = fs.createWriteStream(zipFilePath);
const curl = spawn('curl', ['-#k', frameworkUrl]);
curl.stdout.on('data', function(data) {
out.write(data);
});
curl.stdout.on('end', function(data) {
out.end();
});
curl.on('exit', function(exitCode) {
if (exitCode !== 0) {
console.log('Download failed.');
} else {
const zip = new AdmZip(zipFilePath);
zip.extractAllTo(frameworkDir, true);
fs.unlink(zipFilePath);
console.log('Finished downloading the FBSDK frameworks');
}
});
// Correct the FRAMEWORK_SEARCH_PATHS for RCTFBSDK
const rctfbsdkProjectPath = './node_modules/react-native-fbsdk/ios/RCTFBSDK.xcodeproj/project.pbxproj';
const rctfbsdkProject = xcode.project(rctfbsdkProjectPath);
rctfbsdkProject.parse(function (err) {
if (err) {
console.log(err);
return;
}
rctfbsdkProject.updateBuildProperty('FRAMEWORK_SEARCH_PATHS','"$(PROJECT_DIR)/../../../ios/Frameworks"');
fs.writeFileSync(rctfbsdkProjectPath, rctfbsdkProject.writeSync());
console.log('Updated RCTFBSDK FRAMEWORK_SEARCH_PATHS');
});
// Link the FBSDK*Kit.frameworks.
const files = fs.readdirSync('./ios/');
var myProjName = files.filter(function (f) { return f.substr(-10) === '.xcodeproj'; })[0];
const myProjPath = './ios/' + myProjName + '/project.pbxproj';
myProjName = myProjName.replace('.xcodeproj', '');
console.log('Updating target:' + myProjName + ' at ' + myProjPath + ' ...');
const myProj = xcode.project(myProjPath);
myProj.parse(function (err) {
if (err) {
console.log(err);
return;
}
// Need to create a Frameworks group: https://github.com/alunny/node-xcode/issues/43
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 });
// 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);
});
// Update Info.plist
var plistDirPath = '';
files.map(function(file) {
return path.join('./ios/', file);
}).filter(function(file) {
return fs.statSync(file).isDirectory();
}).forEach(function(file) {
if (fs.readdirSync(file).indexOf('Base.lproj') !== -1) {
plistDirPath = file;
}
});
const plistFilePath = 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);