import JSZip from 'jszip'; import { Project } from '../types'; /** * Exports project files as a downloadable ZIP package. * Also includes a README.md configured for Hugging Face Static Space hosting! */ export async function exportProjectAsZip(project: Project): Promise { const zip = new JSZip(); // Add all project files project.files.forEach(file => { // Strip leading slash if any const cleanPath = file.name.startsWith('/') ? file.name.slice(1) : file.name; zip.file(cleanPath, file.content); }); // If no README.md in files, add Hugging Face Space metadata README const hasReadme = project.files.some(f => f.name.toLowerCase() === 'readme.md'); if (!hasReadme) { const hfReadme = `--- title: ${project.name} emoji: ⚡ colorFrom: indigo colorTo: violet sdk: static pinned: false --- # ${project.name} ${project.description} ### Powered by RiShre – AI Vibe Coding Platform Generated with the **RiShre Awakened model** (Devstral 2 / Hugging Face Inference API). This static project is ready to be hosted directly on **Hugging Face Spaces** (Static SDK) or GitHub Pages. `; zip.file('README.md', hfReadme); } const content = await zip.generateAsync({ type: 'blob' }); const downloadUrl = URL.createObjectURL(content); const link = document.createElement('a'); link.href = downloadUrl; link.download = `${project.name.toLowerCase().replace(/[^a-z0-9]/g, '-')}-rishre-project.zip`; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(downloadUrl); } /** * Downloads a single file */ export function downloadSingleFile(filename: string, content: string): void { const blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }