"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Copyright 2017-2020 Plexus Interop Deutsche Bank AG
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var child_process_1 = require("child_process");
function simpleSpawn(execPath, args, printOutput) {
    if (args === void 0) { args = []; }
    if (printOutput === void 0) { printOutput = false; }
    return new Promise(function (resolve, reject) {
        var errorsBuffer = [];
        var child = child_process_1.spawn(execPath, args, {
            detached: true
        });
        child.stdout.on('data', function (data) {
            if (printOutput) {
                console.log("" + data);
            }
        });
        child.stderr.on('data', function (data) {
            if (printOutput) {
                console.error("" + data);
            }
            else {
                errorsBuffer.push("" + data);
            }
        });
        child.on('exit', function (code, signal) {
            if (code !== 0) {
                if (errorsBuffer.length > 0) {
                    console.error(errorsBuffer.join('\n'));
                }
                reject(new Error("Child process completed with error code: " + code + ", please use --verbose flag to see whole output"));
            }
            else {
                resolve();
            }
        });
        child.on('error', function (error) {
            console.error('Process finished with error', error);
            reject(error);
        });
    });
}
exports.simpleSpawn = simpleSpawn;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb21tb24vcHJvY2Vzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRztBQUNILCtDQUFzQztBQUV0QyxTQUFnQixXQUFXLENBQUMsUUFBZ0IsRUFBRSxJQUFtQixFQUFFLFdBQT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