import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  buildMetadataSchema,
  getBuildMetadataPath
} from "./chunk-RDF2RA4E.js";
import {
  pathExists,
  readJson
} from "./chunk-VASURI4S.js";
import {
  CliError,
  CliErrorCode
} from "./chunk-MTT3QXBC.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-astro-commands/src/files/build.config.ts
init_esm_shims();
async function readBuildMetadata(projectFolder) {
  const buildMetadataPath = getBuildMetadataPath(projectFolder);
  if (!await pathExists(buildMetadataPath)) {
    throw new CliError({
      code: CliErrorCode.BuildOutputMissing({
        reason: `"${buildMetadataPath}" build output file is missing.`
      }),
      cause: null
    });
  }
  const buildMetadataJson = await readJson(buildMetadataPath);
  const parseResult = buildMetadataSchema.safeParse(buildMetadataJson);
  if (parseResult.success) {
    return parseResult.data;
  }
  throw new CliError({
    code: CliErrorCode.BuildOutputMissing({
      reason: `"${buildMetadataPath}" can't be read.`
    }),
    cause: parseResult.error
  });
}

// ../cli-astro-commands/src/files/assert-build-output-exists.ts
init_esm_shims();
async function assertBuildOutputExists(projectFolder) {
  const buildMetadata = await readBuildMetadata(projectFolder);
  const targets = [
    buildMetadata.appManifestPath,
    buildMetadata.outDir,
    buildMetadata.clientDir,
    ...buildMetadata.serverDir ? [buildMetadata.serverDir] : []
  ];
  for (const target of targets) {
    if (!await pathExists(target)) {
      throw new CliError({
        code: CliErrorCode.BuildOutputMissing({
          reason: `"${target}" build output file is missing.`
        }),
        cause: null
      });
    }
  }
}

export {
  readBuildMetadata,
  assertBuildOutputExists
};
//# sourceMappingURL=chunk-BQGAAIC6.js.map