diff --git a/bin/probot b/bin/probot deleted file mode 100755 index fdbb400..0000000 --- a/bin/probot +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env node - -// TODO: -// - exec specific script -// - help - -const path = require('path'); -const probot = require('../index.js'); - -const scripts = process.argv.slice(2); - -scripts.forEach(script => { - require(path.resolve(process.cwd(), script))(probot); -}); diff --git a/bin/probot.js b/bin/probot.js new file mode 100755 index 0000000..ecf8af2 --- /dev/null +++ b/bin/probot.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +const resolve = require('resolve'); +const pkgConf = require('pkg-conf'); +const probot = require('../index.js'); + +function loadPlugins(plugins) { + plugins.forEach(plugin => { + resolve(plugin, {basedir: process.cwd()}, (err, path) => { + if (err) { + throw err; + } else { + probot.log.trace('loading plugin %s', path); + require(path)(probot); + return path; + } + }); + }); +} + +loadPlugins(process.argv.slice(2)); +pkgConf('probot').then(pkg => loadPlugins(pkg.plugins || [])); diff --git a/package.json b/package.json index 2fc1798..44b84a3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "a trainable robot that responds to activity on GitHub", "main": "index.js", "bin": { - "probot": "./bin/probot" + "probot": "./bin/probot.js" }, "scripts": { "start": "node index.js", @@ -16,7 +16,9 @@ "bunyan": "^1.8.5", "dotenv-safe": "^4.0.3", "github-integration": "^1.0.0", - "github-webhook-handler": "^0.6.0" + "github-webhook-handler": "^0.6.0", + "pkg-conf": "^2.0.0", + "resolve": "^1.3.2" }, "devDependencies": { "expect": "^1.20.2",