Support linking project with rnpm

The postlink script takes care of linking in libc++ and libz. So now the only setup instructions will be: `rnpm link realm`.

Resolves #226
This commit is contained in:
Scott Kyle 2016-03-23 10:51:57 -07:00
parent 02b81ac056
commit 42485045f3
3 changed files with 54 additions and 0 deletions

View File

@ -47,6 +47,10 @@
"test": "scripts/test.sh",
"prepublish": "scripts/prepublish.sh"
},
"dependencies": {
"rnpm": "1.5.2",
"xcode": "0.8.4"
},
"devDependencies": {
"babel-eslint": "^6.0.0-beta.6",
"eslint": "^2.4.0",
@ -54,6 +58,14 @@
"jsdoc": "^3.4.0",
"semver": "^5.1.0"
},
"rnpm": {
"commands": {
"postlink": "node_modules/realm/scripts/rnpm-postlink.js"
},
"ios": {
"project": "react-native/ios/RealmReact.xcodeproj"
}
},
"engines": {
"node": ">=4"
}

5
scripts/.eslintrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"env": {
"node": true
}
}

37
scripts/rnpm-postlink.js Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var rnpm = require('rnpm/src/config');
var xcode = require('xcode');
// The current working directory should be project root of the app that is linking Realm.
var config = rnpm.getProjectConfig();
if (config.ios) {
var pbxproj = config.ios.pbxprojPath;
var project = xcode.project(pbxproj).parseSync();
var target = project.getFirstTarget().uuid;
// Create a Frameworks group if necessary.
if (!project.pbxGroupByName('Frameworks')) {
var group = project.pbxCreateGroup('Frameworks', '""');
var mainGroup = project.getFirstProject().firstProject.mainGroup;
project.getPBXGroupByKey(mainGroup).children.push({
value: group,
comment: 'Frameworks',
});
}
['libc++', 'libz'].forEach(function(name) {
project.addFramework('usr/lib/' + name + '.tbd', {
lastKnownFileType: 'sourcecode.text-based-dylib-definition',
sourceTree: 'SDKROOT',
target: target,
});
});
fs.writeFileSync(pbxproj, project.writeSync());
}