import fs from 'node:fs'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; const localRoot = process.cwd(); const distDir = path.join(localRoot, 'dist'); const webroot = process.env.CMS_WEBROOT || '/usr/local/www/clawdie'; const protectedPaths = (process.env.CMS_DEPLOY_PROTECT || 'sites') .split(',') .map((entry) => entry.trim()) .filter(Boolean); if (!fs.existsSync(distDir)) { console.error(`Build output not found: ${distDir}`); process.exit(1); } const rsyncArgs = ['-av', '--delete']; for (const protectedPath of protectedPaths) { rsyncArgs.push('--filter'); rsyncArgs.push(`P ${protectedPath}/`); } rsyncArgs.push(`${distDir}/`); rsyncArgs.push(`${webroot}/`); const result = spawnSync('rsync', rsyncArgs, { stdio: 'inherit', env: process.env, }); if (result.status !== 0) { process.exit(result.status ?? 1); }