'use strict';

const consola = require('../shared/cli.81cce562.cjs');
const index = require('../shared/cli.3e065eec.cjs');
const kit_bb49e233 = require('../shared/cli.de27c2e0.cjs');
require('events');
require('fs');
require('path');
require('util');
require('stream');
require('os');
require('node:fs');
require('node:module');
require('node:url');
require('node:fs/promises');
require('node:os');
require('crypto');
require('module');
require('perf_hooks');
require('vm');
require('url');
require('assert');
require('buffer');
require('tty');
require('node:path');
require('constants');
require('net');
require('child_process');

const preview = index.defineRemixCommand({
  meta: {
    name: "preview",
    usage: "npx remix preview|start [--dotenv] [rootDir]",
    description: "Launches a server for local testing after `remix build`."
  },
  async invoke(args) {
    process.env.NODE_ENV = process.env.NODE_ENV || "production";
    const cwd = kit_bb49e233.resolve(args._[0] || ".");
    const remix = await kit_bb49e233.loadRemix({
      cwd,
      dotenv: {
        cwd,
        fileName: args.dotenv
      }
    });
    remix.hook("build:error", (err) => {
      consola.consola.error("Remix Preview Error:", err);
      process.exit(1);
    });
    consola.consola.info("Node.js version:", process.versions.node);
    consola.consola.info("Working dir:", kit_bb49e233.relative(cwd, remix.options.buildDir));
    consola.consola.log("");
    consola.consola.info("Starting preview.");
    consola.consola.log("");
    const builder = await kit_bb49e233.getBuilder(remix);
    await builder.preview(remix);
    return "wait";
  }
});

exports.default = preview;
