Skip to content

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.

5.6 KB
Raw Blame
// Chép thư viện dùng chung + font OFL (có dấu tiếng Việt) từ node_modules vào engine/vendor và engine/fonts.
// Chạy tự động sau `npm install` (postinstall). Chạy lại an toàn.
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const ENGINE = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.dirname(ENGINE);
const NM = path.join(ROOT, 'node_modules');
const VENDOR = path.join(ENGINE, 'vendor');
const FONTS = path.join(ENGINE, 'fonts');

function copy(src, dst) {
  fs.mkdirSync(path.dirname(dst), { recursive: true });
  fs.copyFileSync(src, dst);
}

// ---- vendor ----
const vendorFiles = [
  ['gsap/dist/gsap.min.js', 'gsap.min.js'],
  ['three/build/three.module.js', 'three.module.js'],
  ['three/build/three.core.js', 'three.core.js'],
  ['three/LICENSE', 'LICENSE-three.txt'],
  ['gsap/README.md', 'README-gsap.md'],
];
for (const [src, dst] of vendorFiles) {
  const s = path.join(NM, src);
  if (fs.existsSync(s)) copy(s, path.join(VENDOR, dst));
  else console.warn('[setup] thiếu', src);
}

// ---- fonts ----
// Chỉ font OFL CÓ subset "vietnamese" thật (setup kiểm file tồn tại, thiếu thì bỏ cả họ và báo).
// [gói fontsource, family, các file css (weight[-italic]), loại, vai trò]
const fontSets = [
  ['barlow-condensed', 'Barlow Condensed', ['500', '600', '700', '800'], 'condensed', 'sans đậm hẹp: tiêu đề in hoa'],
  ['oswald', 'Oswald', ['400', '500', '600', '700'], 'condensed', 'sans hẹp kiểu Oswald/Bebas'],
  ['anton', 'Anton', ['400'], 'condensed', 'poster hẹp rất đậm'],
  ['be-vietnam-pro', 'Be Vietnam Pro', ['400', '500', '600', '700', '800'], 'sans', 'sans thường: thân bài, phụ đề'],
  ['montserrat', 'Montserrat', ['400', '500', '600', '700', '800', '900'], 'sans', 'sans hình học đậm'],
  ['manrope', 'Manrope', ['400', '500', '600', '700', '800'], 'sans', 'sans UI hiện đại (Inter/DM Sans/Outfit)'],
  ['space-grotesk', 'Space Grotesk', ['400', '500', '700'], 'sans', 'grotesk kỹ thuật'],
  ['nunito', 'Nunito', ['400', '600', '700', '800', '900'], 'rounded', 'sans tròn'],
  ['baloo-2', 'Baloo 2', ['500', '600', '700', '800'], 'rounded', 'tròn mập: hoạt hình, vui'],
  ['playfair-display', 'Playfair Display', ['400', '600', '700', '900', '400-italic', '700-italic'], 'serif', 'serif tương phản cao'],
  ['lora', 'Lora', ['400', '600', '700', '400-italic', '700-italic'], 'serif', 'serif đọc dài'],
  ['cormorant-garamond', 'Cormorant Garamond', ['400', '500', '600', '700', '400-italic', '600-italic'], 'serif', 'serif thanh lịch, cổ điển'],
  ['alfa-slab-one', 'Alfa Slab One', ['400'], 'slab', 'slab/poster'],
  ['bungee', 'Bungee', ['400'], 'display', 'display khối, biển hiệu, retro'],
  ['bangers', 'Bangers', ['400'], 'comic', 'truyện tranh'],
  ['patrick-hand', 'Patrick Hand', ['400'], 'hand', 'viết tay dễ đọc'],
  ['mali', 'Mali', ['400', '500', '600', '700'], 'hand', 'viết tay tròn, ghi chú'],
  ['dancing-script', 'Dancing Script', ['400', '700'], 'script', 'chữ ký, script'],
  ['lobster', 'Lobster', ['400'], 'script', 'script đậm, logo'],
  ['pacifico', 'Pacifico', ['400'], 'script', 'script tròn, vui'],
  ['jetbrains-mono', 'JetBrains Mono', ['400', '500', '700'], 'mono', 'mono: số, terminal'],
  ['ibm-plex-mono', 'IBM Plex Mono', ['400', '500', '600'], 'mono', 'mono kỹ thuật/hồ sơ'],
  ['space-mono', 'Space Mono', ['400', '700'], 'mono', 'mono retro, máy chữ'],
  ['vt323', 'VT323', ['400'], 'pixel', 'pixel/retro CRT'],
  ['grenze-gotisch', 'Grenze Gotisch', ['400', '500', '600', '700', '800'], 'gothic', 'gothic/blackletter, trung cổ'],
];
const SUBSETS = ['vietnamese', 'latin-ext', 'latin'];
let css = '/* Sinh tự động bởi engine/setup.mjs. Font OFL từ @fontsource. Không sửa tay. */\n';
const manifest = [];
for (const [pkg, family, weights, kind, role] of fontSets) {
  const dir = path.join(NM, '@fontsource', pkg);
  if (!fs.existsSync(dir)) { console.warn('[setup] thiếu gói font', pkg); continue; }
  const missingVi = weights.filter((w) => {
    const [wt, it] = w.split('-');
    return !fs.existsSync(path.join(dir, 'files', `${pkg}-vietnamese-${wt}-${it || 'normal'}.woff2`));
  });
  if (missingVi.length) { console.warn(`[setup] BỎ ${family}: không có subset vietnamese cho ${missingVi.join(',')}`); continue; }
  css += `\n/* ${family} (${kind}): ${role} */\n`;
  for (const w of weights) {
    const src = fs.readFileSync(path.join(dir, `${w}.css`), 'utf8');
    for (const b of src.split('@font-face').slice(1)) {
      const m = b.match(/url\(\.\/files\/([^)]+?\.woff2)\)/);
      if (!m) continue;
      const file = m[1];
      if (!SUBSETS.some((s) => file.includes(`-${s}-`))) continue;
      copy(path.join(dir, 'files', file), path.join(FONTS, file));
      const body = b.replace(/src:[^;]+;/, `src: url(./${file}) format('woff2');`).replace(/font-display:\s*swap/, 'font-display: block');
      css += '@font-face' + body.trimEnd() + '\n';
    }
  }
  manifest.push({ family, kind, role, weights: weights.filter((w) => !w.includes('italic')).map(Number), italic: weights.filter((w) => w.includes('italic')).map((w) => Number(w.split('-')[0])) });
  const lic = ['LICENSE', 'LICENSE.md', 'OFL.txt'].map((f) => path.join(dir, f)).find((f) => fs.existsSync(f));
  if (lic) copy(lic, path.join(FONTS, 'licenses', `${pkg}.txt`));
}
fs.writeFileSync(path.join(FONTS, 'fonts.css'), css);
fs.writeFileSync(path.join(FONTS, 'fonts.json'), JSON.stringify(manifest, null, 2));
console.log(`[setup] engine/vendor + engine/fonts sẵn sàng (${manifest.length} họ font có tiếng Việt)`);