"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeTemplateBundle = exports.writeCreateAppTemplate = exports.isDestinationEmpty = exports.VITE_REACT_TS_TEMPLATE = exports.CREATE_APP_TEMPLATE_FILES = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const TEMPLATE_FILES = [
    {
        relativePath: 'package.json',
        contents: `{
  "name": "rivet-created-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@vitejs/plugin-react": "^5.1.1",
    "typescript": "~5.9.3",
    "vite": "^7.3.1",
    "react": "^19.2.0",
    "react-dom": "^19.2.0"
  },
  "devDependencies": {
    "@types/react": "^19.2.7",
    "@types/react-dom": "^19.2.3"
  }
}
`,
    },
    {
        relativePath: 'index.html',
        contents: `<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Rivet Created App</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
`,
    },
    {
        relativePath: 'tsconfig.json',
        contents: `{
  "files": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ]
}
`,
    },
    {
        relativePath: 'tsconfig.app.json',
        contents: `{
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "ES2022",
    "useDefineForClassFields": true,
    "lib": ["ES2022", "DOM", "DOM.Iterable"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}
`,
    },
    {
        relativePath: 'tsconfig.node.json',
        contents: `{
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
    "target": "ES2023",
    "lib": ["ES2023"],
    "module": "ESNext",
    "skipLibCheck": true,
    "moduleResolution": "Bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "moduleDetection": "force",
    "noEmit": true,
    "strict": true
  },
  "include": ["vite.config.ts"]
}
`,
    },
    {
        relativePath: 'vite.config.ts',
        contents: `import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
});
`,
    },
    {
        relativePath: '.gitignore',
        contents: `node_modules
dist
.DS_Store
.env
.env.local
`,
    },
    {
        relativePath: 'src/main.tsx',
        contents: `import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
);
`,
    },
    {
        relativePath: 'src/App.tsx',
        contents: `const App = () => {
  return (
    <main className="app-shell">
      <section className="hero">
        <p className="eyebrow">Created with Rivet</p>
        <h1>Describe what should exist, then refine it visually.</h1>
        <p className="lede">
          This starter will be replaced by Rivet's creation agent.
        </p>
      </section>
    </main>
  );
};

export default App;
`,
    },
    {
        relativePath: 'src/index.css',
        contents: `:root {
  color: #111111;
  background: #f7f4ef;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px;
}

.hero {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 16px;
  color: #ff3300;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(42px, 7vw, 88px);
  line-height: 0.95;
  letter-spacing: 0;
}

.lede {
  max-width: 560px;
  margin: 24px 0 0;
  color: #555555;
  font-size: 20px;
  line-height: 1.5;
}
`,
    },
];
exports.CREATE_APP_TEMPLATE_FILES = TEMPLATE_FILES;
exports.VITE_REACT_TS_TEMPLATE = {
    files: TEMPLATE_FILES,
    devCommand: { cmd: 'npm', args: ['run', 'dev'] },
    buildCommand: { cmd: 'npm', args: ['run', 'build'] },
    packageManager: 'npm',
};
/**
 * Return true when the destination can receive a generated app.
 *
 * The MCP zero-to-one flow persists artifacts under `.rivet/` before commit,
 * so a destination whose only entry is `.rivet` is still considered empty for
 * the purpose of starting a new session. This matches the commit-time check in
 * `WorktreeOrchestrator.assertDestinationAvailable` so retries on the same
 * path don't fail at create while commit would have proceeded.
 */
const isDestinationEmpty = (destinationPath) => {
    if (!fs_1.default.existsSync(destinationPath)) {
        return true;
    }
    const entries = fs_1.default.readdirSync(destinationPath);
    return entries.filter((entry) => entry !== '.rivet').length === 0;
};
exports.isDestinationEmpty = isDestinationEmpty;
/**
 * Write the embedded Vite template into the destination folder.
 *
 * @effect Creates directories and writes files at destinationPath
 */
const writeCreateAppTemplate = (destinationPath) => {
    (0, exports.writeTemplateBundle)(exports.VITE_REACT_TS_TEMPLATE, destinationPath);
};
exports.writeCreateAppTemplate = writeCreateAppTemplate;
/**
 * Write an arbitrary template bundle to a destination directory. Used by the
 * MCP fresh-scaffold flow so callers can pin a specific bundle per worktree.
 *
 * @effect Creates directories and writes files at destinationPath
 */
const writeTemplateBundle = (bundle, destinationPath) => {
    for (const file of bundle.files) {
        const absolutePath = path_1.default.join(destinationPath, file.relativePath);
        fs_1.default.mkdirSync(path_1.default.dirname(absolutePath), { recursive: true });
        fs_1.default.writeFileSync(absolutePath, file.contents, 'utf8');
    }
};
exports.writeTemplateBundle = writeTemplateBundle;
//# sourceMappingURL=viteReactTs.js.map