UNPKG

1.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.runConsoleApplication = runConsoleApplication;
7exports.ConsoleApplicationContext = void 0;
8
9var _chalk = _interopRequireDefault(require("chalk"));
10
11var _invalidCommandLineUsageError = require("./invalidCommandLineUsageError");
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15class ConsoleApplicationContext {
16 async waitForExit() {
17 return new Promise(resolve => {
18 process.on("SIGINT", () => {
19 resolve();
20 });
21 });
22 }
23
24}
25
26exports.ConsoleApplicationContext = ConsoleApplicationContext;
27
28async function runConsoleApplicationInternal(entryPoint) {
29 try {
30 const context = new ConsoleApplicationContext();
31 await entryPoint(context);
32 process.exit(0);
33 } catch (error) {
34 if (error instanceof _invalidCommandLineUsageError.InvalidCommandLineUsageError) {
35 console.log(error.message);
36 console.log(error.commandLineUsage);
37 } else if (error instanceof Error) {
38 console.log(_chalk.default.red("FATAL ERROR"));
39 console.log(error.message);
40 } else {
41 console.log(error);
42 }
43
44 process.exit(-1);
45 }
46}
47
48function runConsoleApplication(entryPoint) {
49 // tslint:disable-next-line no-floating-promises
50 runConsoleApplicationInternal(entryPoint);
51}
52//# sourceMappingURL=consoleApplication.js.map
\No newline at end of file