"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XcodebuildCommandService = void 0;
const constants = require("../../constants");
const yok_1 = require("../../common/yok");
class XcodebuildCommandService {
    constructor($childProcess, $errors, $logger) {
        this.$childProcess = $childProcess;
        this.$errors = $errors;
        this.$logger = $logger;
    }
    async executeCommand(args, options) {
        const { message, cwd, stdio, spawnOptions } = options;
        this.$logger.info(message || "Xcode build...");
        const childProcessOptions = { cwd, stdio: stdio || "inherit" };
        try {
            const commandResult = await this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", childProcessOptions, spawnOptions || {
                emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME },
                throwError: true,
            });
            return commandResult;
        }
        catch (err) {
            this.$errors.fail(err.message);
        }
    }
}
exports.XcodebuildCommandService = XcodebuildCommandService;
yok_1.injector.register("xcodebuildCommandService", XcodebuildCommandService);
