#!/usr/bin/env node
"use strict";
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const imperative_1 = require("@zowe/imperative");
const Constants_1 = require("./Constants");
const util_1 = require("util");
const DaemonDecider_1 = require("./daemon/DaemonDecider");
const path_1 = require("path");
// TODO(Kelosky): if we remove this, imperative fails to find config in package.json & we must debug this.
const config = {
    configurationModule: (0, path_1.join)(__dirname, "imperative")
};
(() => __awaiter(void 0, void 0, void 0, function* () {
    try {
        if (process.argv.includes("--daemon") || process.env.npm_lifecycle_event === "postinstall") {
            config.daemonMode = true;
        }
        yield imperative_1.Imperative.init(config);
        const daemonDecider = new DaemonDecider_1.DaemonDecider(process.argv);
        daemonDecider.init();
        imperative_1.Imperative.api.appLogger.trace("Init was successful");
        daemonDecider.runOrUseDaemon();
    }
    catch (initErr) {
        if (initErr === null || initErr === void 0 ? void 0 : initErr.suppressDump) {
            imperative_1.Imperative.console.fatal(initErr.message);
        }
        else {
            imperative_1.Imperative.console.fatal("Error initializing " + Constants_1.Constants.DISPLAY_NAME +
                ":\n "
                + (0, util_1.inspect)(initErr));
        }
        process.exit(1);
    }
}))();
//# sourceMappingURL=main.js.map