File size: 1,991 Bytes
ffe328b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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<void> {
  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);
}