"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const build_1 = require("@weex-cli/build");
const device_1 = require("@weex-cli/device");
const runner_1 = require("../base/runner");
const config_1 = require("../common/config");
const const_1 = require("../common/const");
const DEBUG = require("debug");
const debug = DEBUG('run');
class IosRunner extends runner_1.default {
    constructor(options) {
        super(options, const_1.PLATFORM_TYPES.ios);
    }
    async setNativeConfig() {
        const config = this.config;
        const wsServer = this.wsServer;
        const serverInfo = wsServer.getServerInfo();
        config_1.default[this.type].resolve(Object.assign({
            Ws: `ws://${serverInfo.hostname}:${serverInfo.port}`,
            port: serverInfo.port,
            ip: serverInfo.hostname,
            platform: const_1.PLATFORM_TYPES.ios,
        }, config.nativeConfig), config.projectPath);
    }
    async buildNative(options = {}) {
        const config = this.config;
        const iosBuilder = new build_1.IosBuilder({
            projectPath: config.projectPath,
            preCmds: ['pod update'],
        });
        this.transmitEvent(iosBuilder);
        const { appPath } = await iosBuilder.run(Object.assign({
            onOutCallback: outString => {
            },
            onErrorCallback: outString => {
            },
        }, options));
        return appPath;
    }
    async installAndLaunchApp(appPath) {
        const config = this.config;
        const iosDevice = new device_1.IosDevices();
        this.transmitEvent(iosDevice);
        await iosDevice.run({
            id: config.deviceId,
            applicationId: config.applicationId,
            appPath,
        });
    }
}
exports.default = IosRunner;
