Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.
#!/usr/bin/env node
// Đồng bộ templates/catalog.json từ frontmatter của templates/guidance/*.md.
// node scripts/sync-catalog.mjs
// name = title trong frontmatter; category/genre/technique/difficulty/narration lấy từ frontmatter;
// blurb (1 câu mô tả cái nhìn thấy) giữ từ catalog cũ — mẫu mới thì để trống, tự viết tay sau.
import fs from 'node:fs';
import path from 'node:path';
import { GUIDANCE_DIR, TEMPLATES_DIR } from '../packs/registry.mjs';
// Chỉ mẫu gốc (id 3 chữ số, trong repo). Mẫu trong gói (~/.lumreels/packs) không vào catalog.json:
// packs/registry.mjs listTemplates() tự gộp gốc + gói.
const G = GUIDANCE_DIR;
const OUT = path.join(TEMPLATES_DIR, 'catalog.json');
export function frontmatter(md) {
const m = md.match(/^---\r?\n([\s\S]*?)\r?\n---/);
const o = {};
if (m) for (const line of m[1].split(/\r?\n/)) {
const kv = line.match(/^(\w+):\s*(.*?)\s*(#.*)?$/);
if (kv) o[kv[1]] = /^".*"$/.test(kv[2]) ? kv[2].slice(1, -1) : kv[2];
}
return o;
}
const list = (v) => String(v || '').replace(/^\[|\]$/g, '').split(',').map((s) => s.trim()).filter(Boolean);
const old = fs.existsSync(OUT) ? JSON.parse(fs.readFileSync(OUT, 'utf8')) : [];
const blurbs = Object.fromEntries(old.map((t) => [t.id, t.blurb || '']));
const items = fs.readdirSync(G).filter((f) => /^\d{3}\.md$/.test(f)).sort().map((f) => {
const fm = frontmatter(fs.readFileSync(path.join(G, f), 'utf8'));
const id = f.slice(0, 3);
return {
id, name: fm.title || `Mẫu ${id}`, blurb: blurbs[id] || '',
category: fm.category || 'faceless', genre: fm.genre || '',
technique: list(fm.technique), difficulty: Number(fm.difficulty) || null, narration: fm.narration === 'true',
};
});
fs.writeFileSync(OUT, JSON.stringify(items, null, 1) + '\n');
console.log(`catalog.json: ${items.length} mẫu`);
// Mẫu chưa có ảnh đại diện trong repo (templates/thumbs/<id>.webp) → lưới UI chỉ hiện poster SVG trên máy vừa clone.
const noThumb = items.filter((t) => !fs.existsSync(path.join(TEMPLATES_DIR, 'thumbs', `${t.id}.webp`))).map((t) => t.id);
if (noThumb.length) console.log(`chưa có ảnh đại diện: ${noThumb.join(', ')} → dựng thử 1 job rồi: node scripts/make-thumbs.mjs <id> <jobId>`);