GitHub PullRequestReviewCommentEvent at 2014-02-25 01:18:27
Repository: kodrCI
Actor: headwebmonkey
Payload: {"comment":{"url":"https://api.github.com/repos/kodr-io/kodrCI/pulls/comments/10020471","id":10020471,"diff_hunk":"@@ -0,0 +1,79 @@\n+module.exports = function(kodrCI){\n+    var pluginManager = {\n+            pluginDir: process.cwd()+\"/plugins/\",\n+            pluginLocations: []\n+        },\n+        fs = require(\"fs\"),\n+        npm = require(\"npm\"),\n+        debug = require('debug')('pluginManager'),\n+        exec = require('child_process').exec;\n+\n+    pluginManager.initialize = function(){\n+        kodrCI.utils.consoleOutput(\"Starting PluginManager...\");\n+        this.loadPlugins();\n+        for(var i in this.pluginLocations){\n+            this.registerPlugin(this.pluginDir+this.pluginLocations[i]);\n+        }\n+    }\n+\n+    pluginManager.loadPlugins = function(){\n+        kodrCI.utils.consoleOutput(\"Looking for plugins in '\"+this.pluginDir+\"'...\");\n+        this.pluginLocations = fs.readdirSync(this.pluginDir);\n+        kodrCI.utils.consoleOutput(\"Found \"+this.pluginLocations.length+\" Plugin(s)!\");\n+    }\n+\n+    pluginManager.registerPlugin = function(pluginLocation){\n+        if(!fs.existsSync(pluginLocation+\"/package.json\")){\n+            kodrCI.utils.consoleOutput(\"ERROR: No package.json found in '\"+pluginLocation+\"'\");\n+            return false;\n+        }\n+        var pluginInfo = require(pluginLocation+\"/package.json\");\n+        if (pluginInfo.config === undefined) pluginInfo.config = { enabled: true };\n+        if (pluginInfo.config.enabled === undefined) pluginInfo.config.enabled = true;\n+        if(!pluginInfo.config.enabled){\n+            kodrCI.utils.consoleOutput(\"skipping \"+pluginInfo.name);\n+            return false;\n+        }\n+        kodrCI.utils.consoleOutput(\"registering \"+pluginInfo.name);\n+        var plugin = require(pluginLocation+\"/\")(kodrCI);\n+        if(plugin.initialize === undefined){\n+            kodrCI.utils.consoleOutput(\"ERROR: Plugin '\"+pluginInfo.name+\"' does not have an 'initialize' method\");\n+            return false;\n+        }\n+        kodrCI.plugins[pluginInfo.name] = {};\n+        if(plugin.public !== undefined){\n+            kodrCI.plugins[pluginInfo.name] = plugin.public;\n+        }\n+        var finishedNPM = function(){\n+            kodrCI.utils.consoleOutput(\"initializing \"+pluginInfo.name);\n+            plugin.initialize();\n+            for(var i in plugin){\n+                if(i.indexOf(\"_pages\") !== -1){\n+                    kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n+                    kodrCI.ui.registerPage(i, pluginInfo.name, pluginLocation, kodrCI.plugins[pluginInfo.name]);\n+                }\n+                if(i.indexOf(\"_widget\") !== -1){\n+                    kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n+                    kodrCI.ui.registerWidget(i, pluginInfo.name, pluginLocation);\n+                }\n+                if(i.indexOf(\"_configuration\") !== -1){\n+                    if(plugin._updateConfiguration === undefined){\n+                        throw new Error(\"ERROR: Plugin '\"+pluginInfo.name+\"' does not have a '_updateConfiguration' method but has '_configuration'\");\n+                    }else{\n+                        kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n+                        kodrCI.plugins[pluginInfo.name][\"_updateConfiguration\"] = plugin[\"_updateConfiguration\"];\n+                        kodrCI.plugins[pluginInfo.name][\"_enable\"] = plugin[\"_enable\"];\n+                        kodrCI.plugins[pluginInfo.name][\"_disable\"] = plugin[\"_disable\"];","path":"modules/core/pluginManager.js","position":66,"original_position":66,"commit_id":"733d5db5631bc12131a0e59a449b19cbaccdb2ad","original_commit_id":"733d5db5631bc12131a0e59a449b19cbaccdb2ad","user":{"login":"headwebmonkey","id":1934708,"avatar_url":"https://gravatar.com/avatar/39fe3f827149ba52b4ac35dc5f2bcfbe?d=https%3A%2F%2Fidenticons.github.com%2F17495aff447c38b66d1c97cc6876667e.png&r=x","gravatar_id":"39fe3f827149ba52b4ac35dc5f2bcfbe","url":"https://api.github.com/users/headwebmonkey","html_url":"https://github.com/headwebmonkey","followers_url":"https://api.github.com/users/headwebmonkey/followers","following_url":"https://api.github.com/users/headwebmonkey/following{/other_user}","gists_url":"https://api.github.com/users/headwebmonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/headwebmonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/headwebmonkey/subscriptions","organizations_url":"https://api.github.com/users/headwebmonkey/orgs","repos_url":"https://api.github.com/users/headwebmonkey/repos","events_url":"https://api.github.com/users/headwebmonkey/events{/privacy}","received_events_url":"https://api.github.com/users/headwebmonkey/received_events","type":"User","site_admin":false},"body":"Then it can call the pluginManager on itself. It has access to the\npluginManager\n\n\n-KP\n\n\nOn Mon, Feb 24, 2014 at 7:38 PM, Justin J. Novack\n<notifications@github.com>wrote:\n\n> In modules/core/pluginManager.js:\n>\n> > +                if(i.indexOf(\"_pages\") !== -1){\n> > +                    kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n> > +                    kodrCI.ui.registerPage(i, pluginInfo.name, pluginLocation, kodrCI.plugins[pluginInfo.name]);\n> > +                }\n> > +                if(i.indexOf(\"_widget\") !== -1){\n> > +                    kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n> > +                    kodrCI.ui.registerWidget(i, pluginInfo.name, pluginLocation);\n> > +                }\n> > +                if(i.indexOf(\"_configuration\") !== -1){\n> > +                    if(plugin._updateConfiguration === undefined){\n> > +                        throw new Error(\"ERROR: Plugin '\"+pluginInfo.name+\"' does not have a '_updateConfiguration' method but has '_configuration'\");\n> > +                    }else{\n> > +                        kodrCI.plugins[pluginInfo.name][i] = plugin[i];\n> > +                        kodrCI.plugins[pluginInfo.name][\"_updateConfiguration\"] = plugin[\"_updateConfiguration\"];\n> > +                        kodrCI.plugins[pluginInfo.name][\"_enable\"] = plugin[\"_enable\"];\n> > +                        kodrCI.plugins[pluginInfo.name][\"_disable\"] = plugin[\"_disable\"];\n>\n> What if the plugin itself needs to \"power down\" or \"power up\" in some way?\n>\n> --\n> Reply to this email directly or view it on GitHub<https://github.com/kodr-io/kodrCI/pull/1/files#r10019147>\n> .\n>","created_at":"2014-02-25T01:18:27Z","updated_at":"2014-02-25T01:18:27Z","html_url":"https://github.com/kodr-io/kodrCI/pull/1#discussion_r10020471","pull_request_url":"https://api.github.com/repos/kodr-io/kodrCI/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/kodr-io/kodrCI/pulls/comments/10020471"},"html":{"href":"https://github.com/kodr-io/kodrCI/pull/1#discussion_r10020471"},"pull_request":{"href":"https://api.github.com/repos/kodr-io/kodrCI/pulls/1"}}}}