1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.impMain = void 0;
|
4 | const configure_1 = require("./lib/configure");
|
5 | const logging_1 = require("./lib/logging");
|
6 | const sharprunner_1 = require("./lib/sharprunner");
|
7 | const EXIT_SUCCESS = 0;
|
8 | const EXIT_DATA_ERROR = 65;
|
9 | const EXIT_INTERNAL_ERROR = 70;
|
10 | const EXIT_CONFIG_ERROR = 78;
|
11 | const EXIT_SIGINT = 130;
|
12 | function impMain(argv) {
|
13 | return new Promise((resolve, reject) => {
|
14 | process.on("SIGINT", () => {
|
15 | logging_1.logger.info("Caught interrupt signal (Ctrl-C). Exiting!");
|
16 | return reject(EXIT_SIGINT);
|
17 | });
|
18 | const quietKey = configure_1.cmdLineOptions.quiet["key"];
|
19 | if (argv.indexOf(`-${quietKey}`) > -1) {
|
20 | (0, logging_1.suppressLogOutput)();
|
21 | }
|
22 | let debugMode = false;
|
23 | const debugKey = configure_1.cmdLineOptions.debug["key"];
|
24 | if (argv.indexOf(`-${debugKey}`) > -1) {
|
25 | (0, logging_1.applyDebugConfiguration)();
|
26 | debugMode = true;
|
27 | }
|
28 | (0, configure_1.getConfig)(argv)
|
29 | .then((configObject) => {
|
30 | if (configObject.loggingOptions !== undefined) {
|
31 | (0, logging_1.applyUserConfiguration)(configObject.loggingOptions, debugMode);
|
32 | }
|
33 | return Promise.resolve(configObject);
|
34 | })
|
35 | .then((configObject) => {
|
36 | return (0, sharprunner_1.processImageList)(configObject);
|
37 | })
|
38 | .then((retVal) => {
|
39 | logging_1.logger.info(`Processed ${retVal} pipes!`);
|
40 | return resolve(EXIT_SUCCESS);
|
41 | })
|
42 | .catch((err) => {
|
43 | if (err instanceof configure_1.ImpConfigureError) {
|
44 | logging_1.logger.error(err.message);
|
45 | logging_1.logger.fatal("Could not determine configuration for ImP!");
|
46 | return reject(EXIT_CONFIG_ERROR);
|
47 | }
|
48 | if (err instanceof sharprunner_1.SharpRunnerError) {
|
49 | logging_1.logger.error(err.message);
|
50 | logging_1.logger.fatal("Could not process images!");
|
51 | return reject(EXIT_DATA_ERROR);
|
52 | }
|
53 | logging_1.logger.error("Whoops, that was unexpected!");
|
54 | logging_1.logger.error(err.message);
|
55 | logging_1.logger.fatal("An unexpected error occured. Aborting!");
|
56 | return reject(EXIT_INTERNAL_ERROR);
|
57 | });
|
58 | });
|
59 | }
|
60 | exports.impMain = impMain;
|
61 |
|
\ | No newline at end of file |