const fs = require('fs-extra');
const path = require('path');

// 复制 js-beautify 相关文件到 dist 目录
async function copyBeautifyFiles() {
    const srcDir = path.join(__dirname);
    const destDir = path.join(__dirname, 'dist');

    // 确保目标目录存在
    await fs.ensureDir(destDir);

    // 复制 js-beautify.js 和包装器
    const filesToCopy = [
        'js-beautify.js',
        'js-beautify-wrapper.js'
    ];

    for (const file of filesToCopy) {
        const srcPath = path.join(srcDir, file);
        const destPath = path.join(destDir, file);

        if (await fs.pathExists(srcPath)) {
            await fs.copy(srcPath, destPath);
            console.log(`已复制 ${file} 到 dist 目录`);
        }
    }
}

// 如果直接运行此脚本，则执行复制操作
if (require.main === module) {
    copyBeautifyFiles().catch(console.error);
}

module.exports = { copyBeautifyFiles };