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 DEPRECATED_APP_KEYS = [
|
7 | "auth",
|
8 | "load",
|
9 | "log",
|
10 | "on",
|
11 | "receive",
|
12 | "route",
|
13 | "router",
|
14 | ];
|
15 | let didDeprecate = false;
|
16 | function bindMethod(app, key) {
|
17 | return typeof app[key] === "function" ? app[key].bind(app) : app[key];
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function 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 | }
|
47 | exports.load = load;
|
48 |
|
\ | No newline at end of file |