UNPKG

1.63 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 resolve_app_function_1 = require("./helpers/resolve-app-function");
7const DEPRECATED_APP_KEYS = [
8 "auth",
9 "load",
10 "log",
11 "on",
12 "receive",
13 "route",
14 "router",
15];
16let didDeprecate = false;
17function bindMethod(app, key) {
18 return typeof app[key] === "function" ? app[key].bind(app) : app[key];
19}
20/**
21 * Loads an ApplicationFunction into the current Application
22 * @param appFn - Probot application function to load
23 */
24async function load(app, router, appFn) {
25 const deprecatedApp = DEPRECATED_APP_KEYS.reduce((api, key) => {
26 Object.defineProperty(api, key, {
27 get() {
28 if (didDeprecate)
29 return bindMethod(app, key);
30 app.log.warn(new deprecation_1.Deprecation('[probot] "(app) => {}" is deprecated. Use "({ app }) => {}" instead'));
31 didDeprecate = true;
32 return bindMethod(app, key);
33 },
34 });
35 return api;
36 }, {});
37 if (Array.isArray(appFn)) {
38 for (const fn of appFn) {
39 await load(app, router, fn);
40 }
41 return app;
42 }
43 const fn = typeof appFn === "string" ? resolve_app_function_1.resolveAppFunction(appFn) : appFn;
44 await fn(Object.assign(deprecatedApp, {
45 app,
46 getRouter: get_router_1.getRouter.bind(null, router || app.router),
47 }));
48 return app;
49}
50exports.load = load;
51//# sourceMappingURL=load.js.map
\No newline at end of file