"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiRunner = void 0;
const child_process_1 = require("child_process");
class ApiRunner {
    constructor({ logger, path, port }) {
        this.start = () => {
            this.stop();
            this.write('Starting api runner...');
            this.process = (0, child_process_1.spawn)('yarn', ['api:start', '-p', this.port.toString()], { cwd: this.path });
            this.process.stdout.on('data', (msg) => {
                this.write(msg.toString());
            });
            this.process.stderr.on('data', (msg) => {
                this.write(msg.toString());
            });
        };
        this.stop = () => {
            if (this.process) {
                this.write('Stopping api runner...');
                (0, child_process_1.spawn)('yarn', ['api:stop'], { cwd: this.path }).on('exit', () => {
                    this.process.kill(9);
                });
            }
        };
        this.write = (msg) => {
            this.logger.add(msg.replace(/\n$/, ''));
        };
        this.logger = logger;
        this.path = path;
        this.port = port;
    }
}
exports.ApiRunner = ApiRunner;
//# sourceMappingURL=apiRunner.js.map