UNPKG

2.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.impMain = void 0;
4const configure_1 = require("./lib/configure");
5const logging_1 = require("./lib/logging");
6const sharprunner_1 = require("./lib/sharprunner");
7const EXIT_SUCCESS = 0;
8const EXIT_DATA_ERROR = 65;
9const EXIT_INTERNAL_ERROR = 70;
10const EXIT_CONFIG_ERROR = 78;
11const EXIT_SIGINT = 130;
12function 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}
60exports.impMain = impMain;
61//# sourceMappingURL=main.js.map
\No newline at end of file