mirror of
https://github.com/zhigang1992/probot.github.io.git
synced 2026-01-12 22:49:53 +08:00
130 lines
4.6 KiB
HTML
130 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>plugin.js - Documentation</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"></script>
|
|
<script src="scripts/prettify/lang-css.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
<body>
|
|
|
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
<label for="nav-trigger" class="navicon-button x">
|
|
<div class="navicon"></div>
|
|
</label>
|
|
|
|
<label for="nav-trigger" class="overlay"></label>
|
|
|
|
<nav>
|
|
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Context.html">Context</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#config">config</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#issue">issue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Context.html#repo">repo</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Robot.html">Robot</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#on">on</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Robot.html#route">route</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
|
|
</nav>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">plugin.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>module.exports = pluginLoaderFactory;
|
|
|
|
function pluginLoaderFactory(probot, opts = {}) {
|
|
if (!probot) {
|
|
throw new TypeError('expected probot instance');
|
|
}
|
|
|
|
// We could eventually support a different base dir to load plugins from.
|
|
const basedir = opts.basedir || process.cwd();
|
|
// These are mostly to ease testing
|
|
const autoloader = opts.autoloader || require('load-plugins');
|
|
const resolver = opts.resolver || require('resolve').sync;
|
|
|
|
/**
|
|
* Resolves a plugin by name from the basedir
|
|
* @param {string} pluginName - Module name of plugin
|
|
*/
|
|
function resolvePlugin(pluginName) {
|
|
try {
|
|
return resolver(pluginName, {basedir});
|
|
} catch (err) {
|
|
err.message = `Failed to resolve plugin "${pluginName}". Is it installed?
|
|
Original error message:
|
|
${err.message}`;
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load a plugin via filepath or function
|
|
* @param {string} pluginName - Plugin name (for error messaging)
|
|
* @param {string|Function} plugin - Path to plugin module or function
|
|
*/
|
|
function loadPlugin(pluginName, plugin) {
|
|
try {
|
|
probot.load(typeof plugin === 'string' ? require(plugin) : plugin);
|
|
} catch (err) {
|
|
err.message = `Failed to load plugin "${pluginName}". This is a problem with the plugin itself; not probot.
|
|
Original error message:
|
|
${err.message}`;
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Loads all accessible plugin modules beginning with "probot-"
|
|
*/
|
|
function autoload() {
|
|
const plugins = autoloader('probot-*');
|
|
Object.keys(plugins).forEach(pluginName => {
|
|
loadPlugin(pluginName, plugins[pluginName]);
|
|
probot.logger.info(`Automatically loaded plugin: ${pluginName}`);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Loads an explicit list of plugin modules
|
|
* @param {string[]} [pluginNames=[]] - List of plugin module names
|
|
*/
|
|
function load(pluginNames = []) {
|
|
pluginNames.forEach(pluginName => {
|
|
const pluginPath = resolvePlugin(pluginName);
|
|
loadPlugin(pluginName, pluginPath);
|
|
probot.logger.debug(`Loaded plugin: ${pluginName}`);
|
|
});
|
|
}
|
|
|
|
return {load, autoload};
|
|
}
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Aug 18 2017 11:12:36 GMT-0500 (CDT) using the Minami theme.
|
|
</footer>
|
|
|
|
<script>prettyPrint();</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|