import { randomUUID } from "node:crypto";
import { join, relative, resolve } from "node:path";
import { build as runBuild } from "@zuplo/core/cli";
import { logger } from "../common/logger.js";
import { ConsoleOutput, printDiagnosticsToConsole } from "../common/output.js";
export async function build(argv) {
    const sourceDirectory = resolve(join(relative(process.cwd(), argv.dir)));
    const customDomain = argv.customDomain ?? undefined;
    const buildId = randomUUID();
    try {
        const result = await runBuild({
            buildId,
            output: new ConsoleOutput(),
            sourceDirectory,
            command: "build",
            logger,
            urls: customDomain
                ? {
                    api: {
                        defaultUrl: customDomain,
                        urls: [customDomain],
                    },
                }
                : undefined,
        });
        if (result.status === "Failed") {
            process.exit(1);
        }
        else {
            process.exit();
        }
    }
    catch (err) {
        printDiagnosticsToConsole(`Build error occurred: ${err.message}`);
    }
}
//# sourceMappingURL=handler.js.map