Support loading from script or module

This commit is contained in:
Brandon Keepers 2017-03-11 22:38:58 -06:00
parent dfba43664a
commit e66acd40a4
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
3 changed files with 26 additions and 16 deletions

View File

@ -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);
});

22
bin/probot.js Executable file
View File

@ -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 || []));

View File

@ -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",