UNPKG

2.31 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;
7require("dotenv").config();
8const pkg_conf_1 = __importDefault(require("pkg-conf"));
9const commander_1 = __importDefault(require("commander"));
10const index_1 = require("./index");
11const setup_1 = require("./apps/setup");
12const log_warnings_for_obsolete_environment_variables_1 = require("./helpers/log-warnings-for-obsolete-environment-variables");
13const get_log_1 = require("./helpers/get-log");
14const read_cli_options_1 = require("./bin/read-cli-options");
15const read_env_options_1 = require("./bin/read-env-options");
16async function run(appFnOrArgv) {
17 const { logLevel: level, logFormat, logLevelInString, sentryDsn, ...options } = Array.isArray(appFnOrArgv)
18 ? read_cli_options_1.readCliOptions(appFnOrArgv)
19 : read_env_options_1.readEnvOptions();
20 const log = get_log_1.getLog({ level, logFormat, logLevelInString, sentryDsn });
21 log_warnings_for_obsolete_environment_variables_1.logWarningsForObsoleteEnvironmentVariables(log);
22 const probot = new index_1.Probot({ log, ...options });
23 if (!options.id || !options.privateKey) {
24 if (process.env.NODE_ENV === "production") {
25 if (!options.id) {
26 throw new Error("Application ID is missing, and is required to run in production mode. " +
27 "To resolve, ensure the APP_ID environment variable is set.");
28 }
29 else if (!options.privateKey) {
30 throw new Error("Certificate is missing, and is required to run in production mode. " +
31 "To resolve, ensure either the PRIVATE_KEY or PRIVATE_KEY_PATH environment variable is set and contains a valid certificate");
32 }
33 }
34 probot.load(setup_1.setupAppFactory(options.host, options.port));
35 }
36 else if (Array.isArray(appFnOrArgv)) {
37 const pkg = await pkg_conf_1.default("probot");
38 probot.setup(commander_1.default.args.concat(pkg.apps || []));
39 }
40 else {
41 probot.load(appFnOrArgv);
42 }
43 probot.start();
44 return probot;
45}
46exports.run = run;
47//# sourceMappingURL=run.js.map
\No newline at end of file