diff --git a/package.json b/package.json index 3b3c0494..e4d9835b 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/scripts/.eslintrc.json b/scripts/.eslintrc.json new file mode 100644 index 00000000..10d22388 --- /dev/null +++ b/scripts/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "node": true + } +} diff --git a/scripts/rnpm-postlink.js b/scripts/rnpm-postlink.js new file mode 100755 index 00000000..cd5f7c5f --- /dev/null +++ b/scripts/rnpm-postlink.js @@ -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()); +}