feat: load example templates on startup

This commit is contained in:
Developer 2026-02-12 08:12:01 +00:00
parent 82e4fc91a4
commit fff24a08ed
2 changed files with 35 additions and 0 deletions

30
src/config/loader.ts Normal file
View File

@ -0,0 +1,30 @@
import { parseTemplate } from '../engine/parser';
import type { Template } from '../types/template';
export async function loadExampleTemplates(): Promise<Map<string, Template>> {
const templates = new Map<string, Template>();
const examples = [
'daily-todo.yaml',
'food-order-simple.yaml',
'fancy-receipt.yaml',
'ticket-list.yaml',
'long-text.yaml'
];
for (const filename of examples) {
try {
const file = Bun.file(`./templates/examples/${filename}`);
if (await file.exists()) {
const content = await file.text();
const template = parseTemplate(content);
templates.set(template.id, template);
console.log(`✅ Loaded example template: ${template.name}`);
}
} catch (err) {
console.error(`❌ Failed to load ${filename}:`, err);
}
}
return templates;
}

View File

@ -1,6 +1,11 @@
import { Hono } from 'hono'; import { Hono } from 'hono';
import { serveStatic } from 'hono/bun'; import { serveStatic } from 'hono/bun';
import { apiRoutes } from './api/routes'; import { apiRoutes } from './api/routes';
import { loadExampleTemplates } from './config/loader';
// 加载示例模板
const templates = await loadExampleTemplates();
console.log(`📋 Loaded ${templates.size} example templates`);
const app = new Hono(); const app = new Hono();