UNPKG

1.43 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.load = void 0;
4const deprecation_1 = require("deprecation");
5const get_router_1 = require("./get-router");
6const DEPRECATED_APP_KEYS = [
7 "auth",
8 "load",
9 "log",
10 "on",
11 "receive",
12 "route",
13 "router",
14];
15let didDeprecate = false;
16function bindMethod(app, key) {
17 return typeof app[key] === "function" ? app[key].bind(app) : app[key];
18}
19/**
20 * Loads an ApplicationFunction into the current Application
21 * @param appFn - Probot application function to load
22 */
23function load(app, router, appFn) {
24 const deprecatedApp = DEPRECATED_APP_KEYS.reduce((api, key) => {
25 Object.defineProperty(api, key, {
26 get() {
27 if (didDeprecate)
28 return bindMethod(app, key);
29 app.log.warn(new deprecation_1.Deprecation('[probot] "(app) => {}" is deprecated. Use "({ app }) => {}" instead'));
30 didDeprecate = true;
31 return bindMethod(app, key);
32 },
33 });
34 return api;
35 }, {});
36 if (Array.isArray(appFn)) {
37 appFn.forEach((fn) => load(app, router, fn));
38 }
39 else {
40 appFn(Object.assign(deprecatedApp, {
41 app,
42 getRouter: get_router_1.getRouter.bind(null, router || app.router),
43 }));
44 }
45 return app;
46}
47exports.load = load;
48//# sourceMappingURL=load.js.map
\No newline at end of file