feat: load example templates on startup
This commit is contained in:
parent
82e4fc91a4
commit
fff24a08ed
30
src/config/loader.ts
Normal file
30
src/config/loader.ts
Normal 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;
|
||||
}
|
||||
@ -1,6 +1,11 @@
|
||||
import { Hono } from 'hono';
|
||||
import { serveStatic } from 'hono/bun';
|
||||
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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user