"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
    for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
        to[j] = from[i];
    return to;
};
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 select_bin_1 = __importDefault(require("./select-bin"));
var generate = function (_a) {
    var _b = _a === void 0 ? { pages: [] } : _a, _c = _b.silent, silent = _c === void 0 ? false : _c, _d = _b.exitOnFail, exitOnFail = _d === void 0 ? true : _d, cwd = _b.cwd, _e = _b.timeout, timeout = _e === void 0 ? "1m" : _e, _f = _b.directory, directory = _f === void 0 ? "build" : _f, _g = _b.allow404, allow404 = _g === void 0 ? false : _g, _h = _b.concurrency, concurrency = _h === void 0 ? 30 : _h, _j = _b.url, url = _j === void 0 ? "http://127.0.0.1:3000" : _j, _k = _b.pages, pages = _k === void 0 ? [] : _k;
    var child = child_process_1.spawn(select_bin_1["default"], __spreadArray([
        "generate",
        "--timeout=" + timeout,
        "--directory=" + directory,
        allow404 ? "--allow404" : "",
        "--concurrency=" + concurrency,
        "--url=" + url
    ], pages.map(function (page) { return "--pages=" + page; })), {
        cwd: cwd || process.cwd()
    });
    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 ? "http://localhost:3000" : _c, cwd = _b.cwd, _d = _b.exitOnFail, exitOnFail = _d === void 0 ? true : _d, _e = _b.silent, silent = _e === void 0 ? false : _e;
    var child = child_process_1.spawn(select_bin_1["default"], [
        "serve",
        "--address=" + address,
    ], {
        cwd: cwd || process.cwd()
    });
    if (!silent) {
        child.stderr.pipe(process.stderr);
        child.stdout.pipe(process.stdout);
    }
    if (exitOnFail)
        child.on("close", process.exit);
};
exports.serve = serve;
