#!/usr/bin/env node
"use strict";
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 render_engine_1 = require("@ui-studio/render-engine");
const options_1 = require("./options");
const screen_1 = require("./screen");
const server_1 = require("./server");
const apiRunner_1 = require("./apiRunner");
const clientRunner_1 = require("./clientRunner");
const componentsRunner_1 = require("./componentsRunner");
const watcher_1 = require("./watcher");
const run = () => __awaiter(void 0, void 0, void 0, function* () {
    const { DEV, SERVER_PORT, REPO_PATH, GENERATED_CODE_PATH, PREVIEW_CLIENT_PORT, PREVIEW_SERVER_PORT, } = yield (0, options_1.getOptions)();
    const screen = new screen_1.Screen();
    const server = new server_1.Server({
        REPO_PATH,
        SERVER_PORT,
        PREVIEW_CLIENT_PORT,
    });
    const apiRunner = new apiRunner_1.ApiRunner({
        logger: screen.bottomLeft,
        path: REPO_PATH,
        port: PREVIEW_SERVER_PORT,
    });
    const clientRunner = new clientRunner_1.ClientRunner({
        logger: screen.bottomRight,
        path: GENERATED_CODE_PATH,
        port: PREVIEW_CLIENT_PORT,
        clientUrl: `http://localhost:${SERVER_PORT}`,
    });
    const componentsRunner = new componentsRunner_1.ComponentsRunner({
        logger: screen.topRight,
        path: REPO_PATH,
    });
    const watcher = new watcher_1.Watcher({
        path: REPO_PATH,
        clientRunner,
        componentsRunner,
        server,
    });
    screen.screen.key(['escape', 'q', 'C-c'], () => {
        watcher.stop();
        apiRunner.stop();
        clientRunner.stop();
        componentsRunner.stop();
        return process.exit(0);
    });
    yield (0, render_engine_1.run)(REPO_PATH, DEV);
    yield componentsRunner.run();
    server.start();
    apiRunner.start();
    clientRunner.start();
    watcher.watch();
});
if (typeof require !== 'undefined' && require.main === module) {
    run();
}
//# sourceMappingURL=index.js.map