1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.runConsoleApplication = runConsoleApplication;
|
7 | exports.ConsoleApplicationContext = void 0;
|
8 |
|
9 | var _chalk = _interopRequireDefault(require("chalk"));
|
10 |
|
11 | var _invalidCommandLineUsageError = require("./invalidCommandLineUsageError");
|
12 |
|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14 |
|
15 | class ConsoleApplicationContext {
|
16 | async waitForExit() {
|
17 | return new Promise(resolve => {
|
18 | process.on("SIGINT", () => {
|
19 | resolve();
|
20 | });
|
21 | });
|
22 | }
|
23 |
|
24 | }
|
25 |
|
26 | exports.ConsoleApplicationContext = ConsoleApplicationContext;
|
27 |
|
28 | async 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 |
|
48 | function runConsoleApplication(entryPoint) {
|
49 |
|
50 | runConsoleApplicationInternal(entryPoint);
|
51 | }
|
52 |
|
\ | No newline at end of file |