Something went wrong. Try again.
A fork of @slices.network/slices forked from slices.network/slices
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#!/usr/bin/env -S deno run --allow-read --allow-write
import { walk } from "@std/fs";import { relative, join } from "@std/path";import { encodeBase64 } from "@std/encoding/base64";
const TEMPLATE_DIR = join(import.meta.dirname!, "..", "src", "templates", "deno-ssr");const OUTPUT_FILE = join(import.meta.dirname!, "..", "src", "templates", "embedded.ts");
interface TemplateFile { path: string; content: string;}
async function embedTemplates() { console.log("Embedding templates from:", TEMPLATE_DIR);
const templates: TemplateFile[] = [];
// Walk through all files in the template directory for await (const entry of walk(TEMPLATE_DIR, { includeFiles: true, includeDirs: false })) { const relativePath = relative(TEMPLATE_DIR, entry.path); const content = await Deno.readFile(entry.path); const base64Content = encodeBase64(content);
templates.push({ path: relativePath, content: base64Content, });
console.log(` Embedded: ${relativePath}`); }
// Generate TypeScript file with embedded templates const output = `// Auto-generated file - DO NOT EDIT// Generated by scripts/embed-templates.ts
export interface EmbeddedTemplate { path: string; content: string; // Base64 encoded}
export const EMBEDDED_TEMPLATES: EmbeddedTemplate[] = ${JSON.stringify(templates, null, 2)};
export function getTemplateContent(path: string): Uint8Array | undefined { const template = EMBEDDED_TEMPLATES.find(t => t.path === path); if (!template) return undefined;
const binaryString = atob(template.content); const bytes = new Uint8Array(binaryString.length); for (let i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } return bytes;}
export function getAllTemplates(): Map<string, Uint8Array> { const result = new Map<string, Uint8Array>(); for (const template of EMBEDDED_TEMPLATES) { const binaryString = atob(template.content); const bytes = new Uint8Array(binaryString.length); for (let i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } result.set(template.path, bytes); } return result;}`;
await Deno.writeTextFile(OUTPUT_FILE, output); console.log(`\nGenerated: ${OUTPUT_FILE}`); console.log(`Total templates embedded: ${templates.length}`);}
if (import.meta.main) { await embedTemplates();}