const { execSync } = require('child_process');

const buildName = process.argv[2] //打包后的名字

// 执行命令并打印输出
function runCommand(command) {
    console.log(`执行命令: ${command}`);
    try {
        execSync(command, { stdio: 'inherit' });
    } catch (error) {
        console.error(`命令执行失败: ${error.message}`);
        process.exit(1);
    }
}

// 打包前的准备
runCommand(`node ./scripts/build/config.js ${buildName}`);

// 执行打包命令
runCommand('vue-cli-service build');

// 恢复配置文件
runCommand('node ./scripts/build/restore.js');

// 执行打包为zip
runCommand(`node ./scripts/build/zip.js ${buildName}`);

console.log(`----------------------------`)
console.log(`${buildName} 编译打包完成`)
