{"action":"created","comment":{"url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/comments/41065308","id":41065308,"diff_hunk":"@@ -1,40 +1,71 @@\n+var fs = require('fs');\n+var path = require('path');\n+\n+// This function gets called after every plugin addition, as specified in plugin.xml\n module.exports = function(context) {\n+\n+    var options = context.opts;\n     var Q = context.requireCordovaModule('q');\n-    var npm = context.requireCordovaModule('npm');\n-    var fs = require('fs');\n-    var path = require('path');\n \n     // package.json file is a sister folder to 'lib' folder, in which we currently are executing this script from\n-    var packageJSONDir = path.join(__dirname, '../'); \n+    var packageJSONDir = path.join(__dirname, '../');\n     var packageJSONLocation = path.join(packageJSONDir, 'package.json');\n-    var dependencies = JSON.parse(fs.readFileSync(packageJSONLocation, 'utf-8')).dependencies;\n-    \n+    var packageJSON = JSON.parse(fs.readFileSync(packageJSONLocation, 'utf-8'));\n+\n+    var pluginName = packageJSON.name;\n+\n+\n+    // This function checks if the pluginSpec provided refers to 'cordova-plugin-liverelad'\n+    var isLiveReloadPlugin = function(pluginSpec) {\n+\n+        // A plugin can be installed via an npm package, a path or a git url. \n+        //     e.g: https://github.com/omefire/cordova-plugin-livereload.git\n+        //          https://github.com/schacon/simplegit \n+        //          cordova-plugin-livereload\n+        //          ../cordova-plugin-livereload/\n+        //          ../plugin/\n+        //          C:\\Plugins\\cordova-plugin-livereload\\\n+        //          C:\\Plugins\\plugin\\\n+        // Instead of testing for all those possibilities,\n+        // ... let's test instead for whether the livereload name is contained in the npm package name, the local folder path or the git url\n+        return pluginSpec.indexOf(pluginName) != -1;\n+    };\n+\n+    // Only install livereload dependencies if 'cordova-plugin-livereload' is among the plugins we've just installed\n+    // ... Otherwise, livereload dependencies get installed after every plugin install\n+    if (options.plugins.filter(isLiveReloadPlugin).length === 0) {","path":"lib/dependenciesInstall.js","position":42,"original_position":42,"commit_id":"29f2fce350bf2b0ae9e46ae068116c1177b23ce1","original_commit_id":"29f2fce350bf2b0ae9e46ae068116c1177b23ce1","user":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"body":"hmmm.... going with Array.prototype.some(), I will have to use:\r\n```if ( ! options.plugins.some(isLiveReloadPlugin)) { ...```\r\n\r\nI find that a bit hard to read.","created_at":"2015-10-02T20:41:00Z","updated_at":"2015-10-02T20:41:00Z","html_url":"https://github.com/omefire/cordova-plugin-livereload/pull/14#discussion_r41065308","pull_request_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/comments/41065308"},"html":{"href":"https://github.com/omefire/cordova-plugin-livereload/pull/14#discussion_r41065308"},"pull_request":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14","id":46601518,"html_url":"https://github.com/omefire/cordova-plugin-livereload/pull/14","diff_url":"https://github.com/omefire/cordova-plugin-livereload/pull/14.diff","patch_url":"https://github.com/omefire/cordova-plugin-livereload/pull/14.patch","issue_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/14","number":14,"state":"open","locked":false,"title":"BugFix: Don't add livereload dependencies on after plugin addition","user":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-02T04:01:31Z","updated_at":"2015-10-02T20:41:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c813ce8e15f1ece6075100d61cb4c1cbd653b36","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14/commits","review_comments_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14/comments","review_comment_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/comments{/number}","comments_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/14/comments","statuses_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/statuses/29f2fce350bf2b0ae9e46ae068116c1177b23ce1","head":{"label":"omefire:DepsGetInstalledAfterEveryPluginInstall","ref":"DepsGetInstalledAfterEveryPluginInstall","sha":"29f2fce350bf2b0ae9e46ae068116c1177b23ce1","user":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"repo":{"id":41187987,"name":"cordova-plugin-livereload","full_name":"omefire/cordova-plugin-livereload","owner":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/omefire/cordova-plugin-livereload","description":"LiveReload Plugin for Cordova","fork":false,"url":"https://api.github.com/repos/omefire/cordova-plugin-livereload","forks_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/forks","keys_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/keys{/key_id}","collaborators_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/teams","hooks_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/hooks","issue_events_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/events{/number}","events_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/events","assignees_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/assignees{/user}","branches_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/branches{/branch}","tags_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/tags","blobs_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/refs{/sha}","trees_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/trees{/sha}","statuses_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/statuses/{sha}","languages_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/languages","stargazers_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/stargazers","contributors_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/contributors","subscribers_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/subscribers","subscription_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/subscription","commits_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/commits{/sha}","git_commits_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/commits{/sha}","comments_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/comments{/number}","issue_comment_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/comments{/number}","contents_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/contents/{+path}","compare_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/compare/{base}...{head}","merges_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/merges","archive_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/downloads","issues_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues{/number}","pulls_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls{/number}","milestones_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/milestones{/number}","notifications_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/labels{/name}","releases_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/releases{/id}","created_at":"2015-08-22T03:16:46Z","updated_at":"2015-08-24T18:09:33Z","pushed_at":"2015-10-02T04:01:31Z","git_url":"git://github.com/omefire/cordova-plugin-livereload.git","ssh_url":"git@github.com:omefire/cordova-plugin-livereload.git","clone_url":"https://github.com/omefire/cordova-plugin-livereload.git","svn_url":"https://github.com/omefire/cordova-plugin-livereload","homepage":null,"size":508,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"base":{"label":"omefire:master","ref":"master","sha":"16d827e1e6783c5c22acc008bd4778a89ce99840","user":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"repo":{"id":41187987,"name":"cordova-plugin-livereload","full_name":"omefire/cordova-plugin-livereload","owner":{"login":"omefire","id":4992035,"avatar_url":"https://avatars.githubusercontent.com/u/4992035?v=3","gravatar_id":"","url":"https://api.github.com/users/omefire","html_url":"https://github.com/omefire","followers_url":"https://api.github.com/users/omefire/followers","following_url":"https://api.github.com/users/omefire/following{/other_user}","gists_url":"https://api.github.com/users/omefire/gists{/gist_id}","starred_url":"https://api.github.com/users/omefire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omefire/subscriptions","organizations_url":"https://api.github.com/users/omefire/orgs","repos_url":"https://api.github.com/users/omefire/repos","events_url":"https://api.github.com/users/omefire/events{/privacy}","received_events_url":"https://api.github.com/users/omefire/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/omefire/cordova-plugin-livereload","description":"LiveReload Plugin for Cordova","fork":false,"url":"https://api.github.com/repos/omefire/cordova-plugin-livereload","forks_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/forks","keys_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/keys{/key_id}","collaborators_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/teams","hooks_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/hooks","issue_events_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/events{/number}","events_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/events","assignees_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/assignees{/user}","branches_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/branches{/branch}","tags_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/tags","blobs_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/refs{/sha}","trees_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/trees{/sha}","statuses_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/statuses/{sha}","languages_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/languages","stargazers_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/stargazers","contributors_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/contributors","subscribers_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/subscribers","subscription_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/subscription","commits_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/commits{/sha}","git_commits_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/git/commits{/sha}","comments_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/comments{/number}","issue_comment_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/comments{/number}","contents_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/contents/{+path}","compare_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/compare/{base}...{head}","merges_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/merges","archive_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/downloads","issues_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues{/number}","pulls_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls{/number}","milestones_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/milestones{/number}","notifications_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/labels{/name}","releases_url":"https://api.github.com/repos/omefire/cordova-plugin-livereload/releases{/id}","created_at":"2015-08-22T03:16:46Z","updated_at":"2015-08-24T18:09:33Z","pushed_at":"2015-10-02T04:01:31Z","git_url":"git://github.com/omefire/cordova-plugin-livereload.git","ssh_url":"git@github.com:omefire/cordova-plugin-livereload.git","clone_url":"https://github.com/omefire/cordova-plugin-livereload.git","svn_url":"https://github.com/omefire/cordova-plugin-livereload","homepage":null,"size":508,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14"},"html":{"href":"https://github.com/omefire/cordova-plugin-livereload/pull/14"},"issue":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/14"},"comments":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/omefire/cordova-plugin-livereload/statuses/29f2fce350bf2b0ae9e46ae068116c1177b23ce1"}}}}