import fs from 'fs';

// 读取grade3.json文件
const data = JSON.parse(
    fs.readFileSync('miniprogram/demo/grade3.json', 'utf8'),
);

// 提取所有汉字
const hanzi = Object.keys(data);

// 生成TypeScript代码
const output = `/**
 * 从 grade3.json 中提取的所有汉字
 * 总共 ${hanzi.length} 个汉字
 */
export const SUPPORT_HANZI: string[] = [
    ${hanzi.map((h) => `'${h}'`).join(', ')}
];
`;

// 写入文件
fs.writeFileSync('miniprogram/constants/copyWords.ts', output);

console.log(`Generated copyWords.ts with ${hanzi.length} hanzi`);
console.log('First 10:', hanzi.slice(0, 10));
console.log('Last 10:', hanzi.slice(-10));
