2017-03-18 12:04:23 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
require('dotenv').config();
|
|
|
|
|
2017-04-27 05:39:01 +08:00
|
|
|
const pkgConf = require('pkg-conf');
|
2017-03-18 12:04:23 +08:00
|
|
|
const program = require('commander');
|
2017-04-27 05:39:01 +08:00
|
|
|
|
2017-04-25 14:02:08 +08:00
|
|
|
const {findPrivateKey} = require('../lib/private-key');
|
2017-03-18 12:04:23 +08:00
|
|
|
|
|
|
|
program
|
|
|
|
.usage('[options] <plugins...>')
|
2017-06-06 10:04:26 +08:00
|
|
|
.option('-a, --app <id>', 'ID of the GitHub App', process.env.APP_ID)
|
2017-06-28 00:50:21 +08:00
|
|
|
.option('-s, --secret <secret>', 'Webhook secret of the GitHub App', process.env.WEBHOOK_SECRET)
|
2017-03-18 12:04:23 +08:00
|
|
|
.option('-p, --port <n>', 'Port to start the server on', process.env.PORT || 3000)
|
2017-06-06 10:04:26 +08:00
|
|
|
.option('-P, --private-key <file>', 'Path to certificate of the GitHub App', findPrivateKey)
|
2017-04-27 05:39:01 +08:00
|
|
|
.option('-t, --tunnel <subdomain>', 'Expose your local bot to the internet', process.env.SUBDOMAIN || process.env.NODE_ENV !== 'production')
|
2017-03-18 12:04:23 +08:00
|
|
|
.parse(process.argv);
|
|
|
|
|
2017-06-06 10:04:26 +08:00
|
|
|
if (!program.app) {
|
|
|
|
console.warn('Missing GitHub App ID.\nUse --app flag or set APP_ID environment variable.');
|
2017-03-20 00:51:45 +08:00
|
|
|
program.help();
|
|
|
|
}
|
|
|
|
|
2017-04-29 20:50:59 +08:00
|
|
|
if (!program.privateKey) {
|
|
|
|
program.privateKey = findPrivateKey();
|
|
|
|
}
|
|
|
|
|
2017-04-27 05:39:01 +08:00
|
|
|
if (program.tunnel) {
|
2017-04-09 05:52:53 +08:00
|
|
|
try {
|
2017-06-11 14:06:53 +08:00
|
|
|
const setupTunnel = require('../lib/tunnel');
|
|
|
|
setupTunnel(program.tunnel, program.port).then(tunnel => {
|
|
|
|
console.log('Listening on ' + tunnel.url);
|
|
|
|
}).catch(err => {
|
|
|
|
console.warn('Could not open tunnel: ', err.message);
|
|
|
|
});
|
2017-04-27 05:39:01 +08:00
|
|
|
} catch (err) {
|
2017-04-09 05:52:53 +08:00
|
|
|
console.warn('Run `npm install --save-dev localtunnel` to enable localtunnel.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 12:04:23 +08:00
|
|
|
const createProbot = require('../');
|
|
|
|
|
|
|
|
const probot = createProbot({
|
2017-06-06 10:04:26 +08:00
|
|
|
id: program.app,
|
2017-03-18 12:04:23 +08:00
|
|
|
secret: program.secret,
|
2017-03-20 00:58:12 +08:00
|
|
|
cert: program.privateKey,
|
2017-03-18 12:04:23 +08:00
|
|
|
port: program.port
|
|
|
|
});
|
|
|
|
|
|
|
|
pkgConf('probot').then(pkg => {
|
2017-04-17 16:46:35 +08:00
|
|
|
const plugins = require('../lib/plugin')(probot);
|
|
|
|
const requestedPlugins = program.args.concat(pkg.plugins || []);
|
2017-03-18 12:04:23 +08:00
|
|
|
|
2017-04-27 05:39:01 +08:00
|
|
|
// If we have explicitly requested plugins, load them; otherwise use autoloading
|
|
|
|
if (requestedPlugins.length > 0) {
|
2017-04-17 16:46:35 +08:00
|
|
|
plugins.load(requestedPlugins);
|
|
|
|
} else {
|
|
|
|
plugins.autoload();
|
|
|
|
}
|
2017-03-18 12:04:23 +08:00
|
|
|
probot.start();
|
|
|
|
});
|