// push.js const fs = require('fs'); const path = require('path'); // 读取命令行参数 const args = process.argv.slice(2); const platform = args[0]; // 'windows' 或 'linux' const target = args[1]; // 目标配置键,如 'dir' if (!platform || !target) { console.error('用法: node push.js <平台> <目标配置键>'); console.error('示例: node push.js windows dir'); process.exit(1); } try { // 读取配置文件 const configPath = path.join(__dirname, 'local.json'); const configData = JSON.parse(fs.readFileSync(configPath, 'utf8')); // 验证参数 if (!configData[platform]) { console.error(`错误: 配置文件中找不到平台 "${platform}"`); process.exit(1); } if (!configData[target]) { console.error(`错误: 配置文件中找不到目标 "${target}"`); process.exit(1); } // 获取源文件和目标目录 const sourceFile = path.resolve(__dirname, configData[platform]); const targetDir = configData[target]; // 获取源文件名 const sourceFileName = path.basename(sourceFile); // 创建目标路径 const targetPath = path.join(targetDir, sourceFileName); // 确保目标目录存在 if (!fs.existsSync(targetDir)) { console.log(`创建目录: ${targetDir}`); fs.mkdirSync(targetDir, { recursive: true }); } // 复制文件 fs.copyFileSync(sourceFile, targetPath); console.log(`成功复制文件:`); console.log(` 从: ${sourceFile}`); console.log(` 到: ${targetPath}`); } catch (error) { console.error(`错误: ${error.message}`); process.exit(1); }