"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.serve = exports.generate = void 0;
var child_process_1 = require("child_process");
var node_path_1 = require("node:path");
var select_bin_1 = __importDefault(require("./select-bin"));
var generate = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.silent, silent = _c === void 0 ? false : _c, _d = _b.exitOnFail, exitOnFail = _d === void 0 ? true : _d, _e = _b.dir, dir = _e === void 0 ? "." : _e, _f = _b.timeout, timeout = _f === void 0 ? "1m" : _f;
    var child = child_process_1.spawn(select_bin_1["default"], [
        "generate",
        "--chdir=\"" + node_path_1.resolve(dir) + "\"",
        "--timeout=\"" + timeout + "\"",
    ]);
    if (!silent) {
        child.stderr.pipe(process.stderr);
        child.stdout.pipe(process.stdout);
    }
    if (exitOnFail)
        child.on("close", process.exit);
};
exports.generate = generate;
var serve = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.address, address = _c === void 0 ? "localhost:3000" : _c, _d = _b.dir, dir = _d === void 0 ? "." : _d, _e = _b.exitOnFail, exitOnFail = _e === void 0 ? true : _e, _f = _b.silent, silent = _f === void 0 ? false : _f;
    var child = child_process_1.spawn(select_bin_1["default"], [
        "serve",
        "--chdir=\"" + node_path_1.resolve(dir) + "\"",
        "--address=\"" + address + "\"",
    ]);
    if (!silent) {
        child.stderr.pipe(process.stderr);
        child.stdout.pipe(process.stdout);
    }
    if (exitOnFail)
        child.on("close", process.exit);
};
exports.serve = serve;
