UNPKG

yw-auto-deploy-tool

Version:

一个自动打包、上传并部署的脚本工具

52 lines (40 loc) 1.42 kB
#!/usr/bin/env node const path = require('path'); const fs = require('fs'); const { zipDist, uploadToSFTP, execUnzipOnServer } = require('../lib'); // 自动查找 deploy.config.js const configPath = path.resolve(process.cwd(), 'deploy.config.js'); (async () => { console.log('🚀 开始自动部署...'); // 检查配置文件是否存在 if (!fs.existsSync(configPath)) { console.error('❌ 未找到 deploy.config.js,是否忘记执行初始化?'); process.exit(1); } // 读取配置 let config; try { config = require(configPath); } catch (error) { console.error('❌ 配置文件解析失败:', error); process.exit(1); } const { paths, sshConfig } = config; // 检查必要字段 if (!paths || !sshConfig) { console.error('❌ deploy.config.js 缺少 paths 或 sshConfig 配置'); process.exit(1); } try { // 打包 zip const zipPath = await zipDist(paths.localDistDir, paths.localZipPath); // 上传 zip await uploadToSFTP(sshConfig, zipPath, paths.remoteZipPath); // 执行远程解压 await execUnzipOnServer(sshConfig, paths.remoteZipPath, paths.remoteUnzipDir); console.log('🎉 自动部署完成!'); } catch (err) { console.error('❌ 自动部署失败:', err.message); process.exit(1); } })();