* 复制组件 README.md 文件到文档网站的 public/markdown 目录
*/
const fs = require('fs');
const path = require('path');
const { fileURLToPath } = require('url');
const targetDir = path.resolve(__dirname, '../public/markdown');
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const createExampleMarkdown = (filename, content) => {
const filePath = path.join(targetDir, filename);
fs.writeFileSync(filePath, content);
console.log(`Created example Markdown file: ${filePath}`);
};
const components = [
'badge',
'cell',
'dialog',
'collapse',
'highlight',
'icon',
'image',
'loading',
'popup',
'rate',
'toast'
];
if (!fs.existsSync(path.join(targetDir, 'button.md'))) {
console.log('Creating example button.md file...');
createExampleMarkdown('button.md', '# Button 按钮\n\n按钮用于触发一个操作,如提交表单。');
}
if (!fs.existsSync(path.join(targetDir, 'theme.md'))) {
console.log('Creating example theme.md file...');
createExampleMarkdown('theme.md', '# 主题定制\n\nSilkUI 提供了一套默认主题,支持灵活的样式定制。');
}
components.forEach(component => {
const filePath = path.join(targetDir, `${component}.md`);
if (!fs.existsSync(filePath)) {
console.log(`Creating example ${component}.md file...`);
createExampleMarkdown(`${component}.md`, `# ${component.charAt(0).toUpperCase() + component.slice(1)} 组件\n\n这是 ${component} 组件的文档。`);
}
});
console.log('Markdown directory created successfully!');
console.log('Markdown files copied successfully!');