"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var common_1 = require("../common");
var bundle_1 = require("./bundle");
var init_1 = require("./init");
var PATH = common_1.constants.PATH;
function start(args) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var target, settings;
        return tslib_1.__generator(this, function (_a) {
            target = args.target, settings = args.settings;
            switch (target) {
                case 'electron':
                    return [2, startElectron({ settings: settings })];
                case 'web':
                    return [2, startWeb({ settings: settings })];
                default:
                    common_1.log.info();
                    common_1.log.warn("\uD83D\uDE29  The target \"" + common_1.log.yellow(target) + "\" is not supported.");
                    common_1.log.info();
            }
            return [2];
        });
    });
}
exports.start = start;
function startElectron(args) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var settings, prod, port, renderer, dir, cmd, childProcess;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    settings = args.settings;
                    prod = false;
                    port = settings.electron.port;
                    return [4, init_1.init({ settings: settings, prod: prod })];
                case 1:
                    _a.sent();
                    common_1.log.info();
                    common_1.logElectronInfo({ settings: settings, port: true });
                    return [4, bundle_1.bundleElectron({
                            settings: settings,
                            prod: false,
                            main: true,
                            renderer: false,
                            summary: false,
                        })];
                case 2:
                    _a.sent();
                    common_1.log.info();
                    renderer = common_1.parcel.electronRendererBundler(settings);
                    return [4, renderer.serve(port)];
                case 3:
                    _a.sent();
                    dir = common_1.fsPath.resolve(PATH.UIHARNESS);
                    cmd = "electron " + dir;
                    childProcess = common_1.execa.shell(cmd);
                    childProcess.stdout.pipe(process.stdout);
                    return [4, childProcess];
                case 4:
                    _a.sent();
                    return [2];
            }
        });
    });
}
exports.startElectron = startElectron;
function startWeb(args) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var settings, prod, port, renderer;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    settings = args.settings;
                    prod = false;
                    port = settings.web.port;
                    return [4, init_1.init({ settings: settings, prod: prod })];
                case 1:
                    _a.sent();
                    common_1.log.info();
                    common_1.logWebInfo({ settings: settings, port: true });
                    renderer = common_1.parcel.webBundler(settings);
                    return [4, renderer.serve(port)];
                case 2:
                    _a.sent();
                    return [2];
            }
        });
    });
}
exports.startWeb = startWeb;
//# sourceMappingURL=start.js.map