const fs = require('fs');
const path = require('path');
const sourceDir = './node_modules/beehole-store-admin/dist';
const targetDir = './';

// 使用fs.stat()方法检查目录是否存在
fs.stat(sourceDir, (err, stats) => {
    if (err) {
        if (err.code === 'ENOENT') {
            console.log('Directory does not exist. please run "npm install" first.');
        } else {
            console.error('Error checking directory:', err);
        }
    } else {
        if (stats.isDirectory()) {
            copyDirectory(sourceDir, targetDir);
            console.log('ready!');
        } else {
            console.log('Path exists, but it is not a directory.');
        }
    }
});
function copyDirectory(sourceDir, targetDir) {
    if (!fs.existsSync(targetDir)) {
        fs.mkdirSync(targetDir);
    }

    const files = fs.readdirSync(sourceDir);

    files.forEach((file) => {
        const sourcePath = path.join(sourceDir, file);
        const targetPath = path.join(targetDir, file);

        if (fs.lstatSync(sourcePath).isDirectory()) {
            copyDirectory(sourcePath, targetPath);
        } else {
            fs.copyFileSync(sourcePath, targetPath);
        }
    });
}

