#!/usr/bin/env node
import {
  readTextFileIfExists,
  writeTextFile
} from "./chunk-IAYRNVUC.mjs";

// src/services/project/workspace-codegen.ts
import {
  generateAuthoritativeFiles,
  generateSeedFiles,
  isFrameworkOwnedSetupProfilesSeed
} from "@dreamboard-games/sdk/codegen";
var STARTER_UI_SEED_FILES = /* @__PURE__ */ new Set([
  "ui/interaction-routes.tsx",
  "ui/setup-screen.tsx",
  "ui/styles.ts",
  "ui/ui-contract-typing-smoke.tsx"
]);
async function applyWorkspaceCodegen(options) {
  const { projectRoot, manifest } = options;
  const authoritativeFiles = generateAuthoritativeFiles(manifest);
  const seedFiles = generateSeedFiles(manifest);
  const written = [];
  const skipped = [];
  const merged = [];
  const existingUiAppBeforeSeeds = await readTextFileIfExists(
    `${projectRoot}/ui/App.tsx`
  );
  const shouldWriteStarterUiSeedFiles = existingUiAppBeforeSeeds === null || existingUiAppBeforeSeeds.trim().length === 0;
  for (const [relativePath, content] of Object.entries(authoritativeFiles)) {
    const filePath = `${projectRoot}/${relativePath}`;
    const existingContent = await readTextFileIfExists(filePath);
    await writeTextFile(filePath, content);
    if (existingContent !== content) {
      written.push(relativePath);
    }
  }
  for (const [relativePath, content] of Object.entries(seedFiles)) {
    const filePath = `${projectRoot}/${relativePath}`;
    const existingContent = await readTextFileIfExists(filePath);
    if (STARTER_UI_SEED_FILES.has(relativePath) && !shouldWriteStarterUiSeedFiles && existingContent === null) {
      skipped.push(relativePath);
      continue;
    }
    const shouldRefreshFrameworkSeed = relativePath === "app/setup-profiles.ts" && isFrameworkOwnedSetupProfilesSeed(existingContent);
    if (shouldRefreshFrameworkSeed) {
      await writeTextFile(filePath, content);
      if (existingContent !== content) {
        written.push(relativePath);
      }
      continue;
    }
    const hasExistingContent = existingContent !== null && existingContent.trim().length > 0;
    if (hasExistingContent) {
      skipped.push(relativePath);
      continue;
    }
    await writeTextFile(filePath, content);
    written.push(relativePath);
  }
  written.sort();
  skipped.sort();
  merged.sort();
  return { written, skipped, merged };
}

export {
  applyWorkspaceCodegen
};
//# sourceMappingURL=chunk-G42BGGG2.mjs.map