{"action":"created","comment":{"url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/comments/50680756","id":50680756,"diff_hunk":"@@ -1,94 +1,14 @@\n-const fs = require('fs-extra');\n const path = require('path');\n-const compose = require('lodash.flowright');\n+const semver = require('semver');\n \n-const SETTINGS_PATCH_PATTERN = `include ':app'`;\n-const BUILD_PATCH_PATTERN = `dependencies {`;\n-const MAIN_ACTIVITY_IMPORT_PATTERN = `import android.app.Activity;`;\n-const MAIN_ACTIVITY_PACKAGE_PATTERN = `.addPackage(new MainReactPackage())`;\n-\n-const readFile = (file) =>\n-  () => fs.readFileSync(file, 'utf8');\n-\n-const writeFile = (file, content) => content ?\n-  fs.writeFileSync(file, content, 'utf8') :\n-  (c) => fs.writeFileSync(file, c, 'utf8');\n-\n-const replace = (scope, pattern, patch) =>\n-  scope.replace(pattern, `${pattern}\\n${patch}`);\n-\n-module.exports = function registerNativeAndroidModule(name, dependencyConfig, projectConfig) {\n-  const BUILD_PATCH = `    compile project(':${name}')`;\n-  const SETTINGS_PATCH = `include ':${name}'\\n` +\n-    `project(':${name}').projectDir = ` +\n-    `new File(rootProject.projectDir, '../node_modules/${name}/${dependencyConfig.sourceDir}')`;\n-\n-  /**\n-   * Replace SETTINGS_PATCH_PATTERN by patch in the passed content\n-   * @param  {String} content Content of the Settings.gradle file\n-   * @return {String}         Patched content of Settings.gradle\n-   */\n-  const patchProjectSettings = (content) =>\n-    replace(content, SETTINGS_PATCH_PATTERN, SETTINGS_PATCH);\n-\n-  /**\n-   * Replace BUILD_PATCH_PATTERN by patch in the passed content\n-   * @param  {String} content Content of the Build.gradle file\n-   * @return {String}         Patched content of Build.gradle\n-   */\n-  const patchProjectBuild = (content) =>\n-    replace(content, BUILD_PATCH_PATTERN, BUILD_PATCH);\n-\n-  const getMainActivityPatch = () =>\n-    `                .addPackage(${dependencyConfig.packageInstance})`;\n-\n-  /**\n-   * Make a MainActivity.java program patcher\n-   * @param  {String}   importPath Import path, e.g. com.oblador.vectoricons.VectorIconsPackage;\n-   * @param  {String}   instance   Code to instance a package, e.g. new VectorIconsPackage();\n-   * @return {Function}            Patcher function\n-   */\n-  const makeMainActivityPatcher = (content) => {\n-    const patched = replace(\n-      content, MAIN_ACTIVITY_IMPORT_PATTERN, dependencyConfig.packageImportPath\n-    );\n-\n-    return replace(\n-      patched, MAIN_ACTIVITY_PACKAGE_PATTERN, getMainActivityPatch()\n-    );\n-  };\n-\n-  const applySettingsGradlePatch = compose(\n-    writeFile(projectConfig.settingsGradlePath),\n-    patchProjectSettings,\n-    readFile(projectConfig.settingsGradlePath)\n-  );\n-\n-  const applyBuildGradlePatch = compose(\n-    writeFile(projectConfig.buildGradlePath),\n-    patchProjectBuild,\n-    readFile(projectConfig.buildGradlePath)\n-  );\n-\n-  const applyMainActivityPatch = compose(\n-    writeFile(projectConfig.mainActivityPath),\n-    makeMainActivityPatcher,\n-    readFile(projectConfig.mainActivityPath)\n-  );\n-\n-  /**\n-   * Check if module has been installed already\n-   */\n-  const isInstalled = compose(\n-    (content) => ~content.indexOf(getMainActivityPatch()),\n-    readFile(projectConfig.mainActivityPath)\n+module.exports = function registerNativeModule(name, dependencyConfig, projectConfig) {\n+  const rnpkg = require(\n+    path.join(projectConfig.folder, 'node_modules', 'react-native', 'package.json')\n   );","path":"src/android/registerNativeModule.js","position":89,"original_position":89,"commit_id":"1bc4b5eb7b018400ba95fe95066531b3c973bd39","original_commit_id":"1bc4b5eb7b018400ba95fe95066531b3c973bd39","user":{"login":"grabbou","id":2464966,"avatar_url":"https://avatars.githubusercontent.com/u/2464966?v=3","gravatar_id":"","url":"https://api.github.com/users/grabbou","html_url":"https://github.com/grabbou","followers_url":"https://api.github.com/users/grabbou/followers","following_url":"https://api.github.com/users/grabbou/following{/other_user}","gists_url":"https://api.github.com/users/grabbou/gists{/gist_id}","starred_url":"https://api.github.com/users/grabbou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grabbou/subscriptions","organizations_url":"https://api.github.com/users/grabbou/orgs","repos_url":"https://api.github.com/users/grabbou/repos","events_url":"https://api.github.com/users/grabbou/events{/privacy}","received_events_url":"https://api.github.com/users/grabbou/received_events","type":"User","site_admin":false},"body":"Obviously this will be cached, but since we read package json anyway in `link` & `unlink` to get dependencies, you could just pass the version to the function w/o calling require. Should be easier to test.","created_at":"2016-01-25T11:09:49Z","updated_at":"2016-01-25T11:09:49Z","html_url":"https://github.com/rnpm/rnpm-plugin-link/pull/22#discussion_r50680756","pull_request_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/comments/50680756"},"html":{"href":"https://github.com/rnpm/rnpm-plugin-link/pull/22#discussion_r50680756"},"pull_request":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22","id":57009464,"html_url":"https://github.com/rnpm/rnpm-plugin-link/pull/22","diff_url":"https://github.com/rnpm/rnpm-plugin-link/pull/22.diff","patch_url":"https://github.com/rnpm/rnpm-plugin-link/pull/22.patch","issue_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/22","number":22,"state":"open","locked":false,"title":"Support react-native 0.18+","user":{"login":"Kureev","id":2273613,"avatar_url":"https://avatars.githubusercontent.com/u/2273613?v=3","gravatar_id":"","url":"https://api.github.com/users/Kureev","html_url":"https://github.com/Kureev","followers_url":"https://api.github.com/users/Kureev/followers","following_url":"https://api.github.com/users/Kureev/following{/other_user}","gists_url":"https://api.github.com/users/Kureev/gists{/gist_id}","starred_url":"https://api.github.com/users/Kureev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kureev/subscriptions","organizations_url":"https://api.github.com/users/Kureev/orgs","repos_url":"https://api.github.com/users/Kureev/repos","events_url":"https://api.github.com/users/Kureev/events{/privacy}","received_events_url":"https://api.github.com/users/Kureev/received_events","type":"User","site_admin":false},"body":"## Story:\r\n- Detect an installed version of the `react-native`\r\n- Based on the installed version we're using a specific patch\r\n\r\nThis PR introduce two versions of the patch: for `react-native` < 0.18.0 and `react-native` > 0.18.0.\r\n\r\nShould fix https://github.com/rnpm/rnpm/issues/77","created_at":"2016-01-24T18:11:39Z","updated_at":"2016-01-25T11:09:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"666203af5972284571735e604f10a5626bdf5dbe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22/commits","review_comments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22/comments","review_comment_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/22/comments","statuses_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/statuses/1bc4b5eb7b018400ba95fe95066531b3c973bd39","head":{"label":"rnpm:feature/support-0.18","ref":"feature/support-0.18","sha":"1bc4b5eb7b018400ba95fe95066531b3c973bd39","user":{"login":"rnpm","id":16019332,"avatar_url":"https://avatars.githubusercontent.com/u/16019332?v=3","gravatar_id":"","url":"https://api.github.com/users/rnpm","html_url":"https://github.com/rnpm","followers_url":"https://api.github.com/users/rnpm/followers","following_url":"https://api.github.com/users/rnpm/following{/other_user}","gists_url":"https://api.github.com/users/rnpm/gists{/gist_id}","starred_url":"https://api.github.com/users/rnpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnpm/subscriptions","organizations_url":"https://api.github.com/users/rnpm/orgs","repos_url":"https://api.github.com/users/rnpm/repos","events_url":"https://api.github.com/users/rnpm/events{/privacy}","received_events_url":"https://api.github.com/users/rnpm/received_events","type":"Organization","site_admin":false},"repo":{"id":46947718,"name":"rnpm-plugin-link","full_name":"rnpm/rnpm-plugin-link","owner":{"login":"rnpm","id":16019332,"avatar_url":"https://avatars.githubusercontent.com/u/16019332?v=3","gravatar_id":"","url":"https://api.github.com/users/rnpm","html_url":"https://github.com/rnpm","followers_url":"https://api.github.com/users/rnpm/followers","following_url":"https://api.github.com/users/rnpm/following{/other_user}","gists_url":"https://api.github.com/users/rnpm/gists{/gist_id}","starred_url":"https://api.github.com/users/rnpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnpm/subscriptions","organizations_url":"https://api.github.com/users/rnpm/orgs","repos_url":"https://api.github.com/users/rnpm/repos","events_url":"https://api.github.com/users/rnpm/events{/privacy}","received_events_url":"https://api.github.com/users/rnpm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rnpm/rnpm-plugin-link","description":"Allows linking dependencies to your React Native project","fork":false,"url":"https://api.github.com/repos/rnpm/rnpm-plugin-link","forks_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/forks","keys_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/teams","hooks_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/hooks","issue_events_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/events{/number}","events_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/events","assignees_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/assignees{/user}","branches_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/branches{/branch}","tags_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/tags","blobs_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/refs{/sha}","trees_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/statuses/{sha}","languages_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/languages","stargazers_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/stargazers","contributors_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/contributors","subscribers_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/subscribers","subscription_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/subscription","commits_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/commits{/sha}","git_commits_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/commits{/sha}","comments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/comments{/number}","issue_comment_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/comments{/number}","contents_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/contents/{+path}","compare_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/merges","archive_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/downloads","issues_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues{/number}","pulls_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls{/number}","milestones_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/milestones{/number}","notifications_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/labels{/name}","releases_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/releases{/id}","deployments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/deployments","created_at":"2015-11-26T21:35:32Z","updated_at":"2016-01-21T00:42:46Z","pushed_at":"2016-01-25T05:59:01Z","git_url":"git://github.com/rnpm/rnpm-plugin-link.git","ssh_url":"git@github.com:rnpm/rnpm-plugin-link.git","clone_url":"https://github.com/rnpm/rnpm-plugin-link.git","svn_url":"https://github.com/rnpm/rnpm-plugin-link","homepage":"","size":92,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":2,"default_branch":"master"}},"base":{"label":"rnpm:master","ref":"master","sha":"68aafa720a68558a7a2fe1c75b4b70ab27d411a7","user":{"login":"rnpm","id":16019332,"avatar_url":"https://avatars.githubusercontent.com/u/16019332?v=3","gravatar_id":"","url":"https://api.github.com/users/rnpm","html_url":"https://github.com/rnpm","followers_url":"https://api.github.com/users/rnpm/followers","following_url":"https://api.github.com/users/rnpm/following{/other_user}","gists_url":"https://api.github.com/users/rnpm/gists{/gist_id}","starred_url":"https://api.github.com/users/rnpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnpm/subscriptions","organizations_url":"https://api.github.com/users/rnpm/orgs","repos_url":"https://api.github.com/users/rnpm/repos","events_url":"https://api.github.com/users/rnpm/events{/privacy}","received_events_url":"https://api.github.com/users/rnpm/received_events","type":"Organization","site_admin":false},"repo":{"id":46947718,"name":"rnpm-plugin-link","full_name":"rnpm/rnpm-plugin-link","owner":{"login":"rnpm","id":16019332,"avatar_url":"https://avatars.githubusercontent.com/u/16019332?v=3","gravatar_id":"","url":"https://api.github.com/users/rnpm","html_url":"https://github.com/rnpm","followers_url":"https://api.github.com/users/rnpm/followers","following_url":"https://api.github.com/users/rnpm/following{/other_user}","gists_url":"https://api.github.com/users/rnpm/gists{/gist_id}","starred_url":"https://api.github.com/users/rnpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnpm/subscriptions","organizations_url":"https://api.github.com/users/rnpm/orgs","repos_url":"https://api.github.com/users/rnpm/repos","events_url":"https://api.github.com/users/rnpm/events{/privacy}","received_events_url":"https://api.github.com/users/rnpm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rnpm/rnpm-plugin-link","description":"Allows linking dependencies to your React Native project","fork":false,"url":"https://api.github.com/repos/rnpm/rnpm-plugin-link","forks_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/forks","keys_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/teams","hooks_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/hooks","issue_events_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/events{/number}","events_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/events","assignees_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/assignees{/user}","branches_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/branches{/branch}","tags_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/tags","blobs_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/refs{/sha}","trees_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/statuses/{sha}","languages_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/languages","stargazers_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/stargazers","contributors_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/contributors","subscribers_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/subscribers","subscription_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/subscription","commits_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/commits{/sha}","git_commits_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/git/commits{/sha}","comments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/comments{/number}","issue_comment_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/comments{/number}","contents_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/contents/{+path}","compare_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/merges","archive_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/downloads","issues_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues{/number}","pulls_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls{/number}","milestones_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/milestones{/number}","notifications_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/labels{/name}","releases_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/releases{/id}","deployments_url":"https://api.github.com/repos/rnpm/rnpm-plugin-link/deployments","created_at":"2015-11-26T21:35:32Z","updated_at":"2016-01-21T00:42:46Z","pushed_at":"2016-01-25T05:59:01Z","git_url":"git://github.com/rnpm/rnpm-plugin-link.git","ssh_url":"git@github.com:rnpm/rnpm-plugin-link.git","clone_url":"https://github.com/rnpm/rnpm-plugin-link.git","svn_url":"https://github.com/rnpm/rnpm-plugin-link","homepage":"","size":92,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22"},"html":{"href":"https://github.com/rnpm/rnpm-plugin-link/pull/22"},"issue":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/22"},"comments":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/rnpm/rnpm-plugin-link/statuses/1bc4b5eb7b018400ba95fe95066531b3c973bd39"}}}}