001project_wildgrowth/backend/scripts/generate-xhs-cover-assets.ts

33 lines
876 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 预生成所有小红书封面模板 PNG 到 public/xhs-covers/
* 页面可直接用静态图,无需等 API 生成
*
* 运行npm run playground:xhs-generate
*/
import path from 'path';
import fs from 'fs/promises';
import {
generateXhsCover,
XHS_COVER_TEMPLATES,
} from '../src/services/xhsCoverTemplatesService';
async function main() {
const dir = path.join(process.cwd(), 'public', 'xhs-covers');
await fs.mkdir(dir, { recursive: true });
for (const t of XHS_COVER_TEMPLATES) {
const buffer = generateXhsCover(t.id, {});
const filepath = path.join(dir, `${t.id}.png`);
await fs.writeFile(filepath, buffer);
console.log(' ✓', t.name, `(${t.id}.png)`);
}
console.log('\n✅ 已生成', XHS_COVER_TEMPLATES.length, '张模板图 → public/xhs-covers/');
}
main().catch((e) => {
console.error(e);
process.exit(1);
});