1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.load = void 0;
|
4 | const deprecation_1 = require("deprecation");
|
5 | const get_router_1 = require("./get-router");
|
6 | const resolve_app_function_1 = require("./helpers/resolve-app-function");
|
7 | const DEPRECATED_APP_KEYS = [
|
8 | "auth",
|
9 | "load",
|
10 | "log",
|
11 | "on",
|
12 | "receive",
|
13 | "route",
|
14 | "router",
|
15 | ];
|
16 | let didDeprecate = false;
|
17 | function bindMethod(app, key) {
|
18 | return typeof app[key] === "function" ? app[key].bind(app) : app[key];
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | async 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 | }
|
50 | exports.load = load;
|
51 |
|
\ | No newline at end of file |