UNPKG

4.09 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.run = void 0;
7const pkg_conf_1 = __importDefault(require("pkg-conf"));
8const index_1 = require("./index");
9const setup_1 = require("./apps/setup");
10const log_warnings_for_obsolete_environment_variables_1 = require("./helpers/log-warnings-for-obsolete-environment-variables");
11const get_log_1 = require("./helpers/get-log");
12const read_cli_options_1 = require("./bin/read-cli-options");
13const read_env_options_1 = require("./bin/read-env-options");
14const server_1 = require("./server/server");
15const default_1 = require("./apps/default");
16const resolve_app_function_1 = require("./helpers/resolve-app-function");
17const load_1 = require("./load");
18/**
19 *
20 * @param appFnOrArgv set to either a probot application function: `({ app }) => { ... }` or to process.argv
21 */
22async function run(appFnOrArgv, additionalOptions) {
23 require("dotenv").config();
24 const envOptions = read_env_options_1.readEnvOptions(additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.env);
25 const cliOptions = Array.isArray(appFnOrArgv)
26 ? read_cli_options_1.readCliOptions(appFnOrArgv)
27 : {};
28 const {
29 // log options
30 logLevel: level, logFormat, logLevelInString, sentryDsn,
31 // server options
32 host, port, webhookPath, webhookProxy,
33 // probot options
34 appId, privateKey, redisConfig, secret, baseUrl,
35 // others
36 args, } = { ...envOptions, ...cliOptions };
37 const logOptions = {
38 level,
39 logFormat,
40 logLevelInString,
41 sentryDsn,
42 };
43 const log = get_log_1.getLog(logOptions);
44 log_warnings_for_obsolete_environment_variables_1.logWarningsForObsoleteEnvironmentVariables(log);
45 const probotOptions = {
46 appId,
47 privateKey,
48 redisConfig,
49 secret,
50 baseUrl,
51 log: log.child({ name: "probot" }),
52 };
53 const serverOptions = {
54 host,
55 port,
56 webhookPath,
57 webhookProxy,
58 log: log.child({ name: "server" }),
59 Probot: index_1.Probot.defaults(probotOptions),
60 };
61 let server;
62 if (!appId || !privateKey) {
63 if (process.env.NODE_ENV === "production") {
64 if (!appId) {
65 throw new Error("Application ID is missing, and is required to run in production mode. " +
66 "To resolve, ensure the APP_ID environment variable is set.");
67 }
68 else if (!privateKey) {
69 throw new Error("Certificate is missing, and is required to run in production mode. " +
70 "To resolve, ensure either the PRIVATE_KEY or PRIVATE_KEY_PATH environment variable is set and contains a valid certificate");
71 }
72 }
73 server = new server_1.Server(serverOptions);
74 await server.load(setup_1.setupAppFactory(host, port));
75 await server.start();
76 return server;
77 }
78 if (Array.isArray(appFnOrArgv)) {
79 const pkg = await pkg_conf_1.default("probot");
80 const combinedApps = ({ app }) => {
81 load_1.load(app, server.router(), default_1.defaultApp);
82 if (Array.isArray(pkg.apps)) {
83 for (const appPath of pkg.apps) {
84 const appFn = resolve_app_function_1.resolveAppFunction(appPath);
85 load_1.load(app, server.router(), appFn);
86 }
87 }
88 const [appPath] = args;
89 const appFn = resolve_app_function_1.resolveAppFunction(appPath);
90 load_1.load(app, server.router(), appFn);
91 };
92 server = new server_1.Server(serverOptions);
93 await server.load(combinedApps);
94 await server.start();
95 return server;
96 }
97 server = new server_1.Server(serverOptions);
98 await server.load(appFnOrArgv);
99 await server.start();
100 return server;
101}
102exports.run = run;
103//# sourceMappingURL=run.js.map
\No newline at end of file