import { watch } from 'fs' import { execSync } from 'child_process' import { join } from 'path' import { fileURLToPath } from 'url' import { dirname } from 'path' const __dirname = dirname(fileURLToPath(import.meta.url)) const SRC_DIR = join(__dirname, 'src') const DEPLOY_SCRIPT = join(__dirname, 'deploy.sh') const COOLDOWN_MS = 5000 let timer = null console.log(`Watching ${SRC_DIR} for changes...`) console.log('Auto-deploying to copelk on save') console.log('Press Ctrl+C to stop\n') watch(SRC_DIR, { recursive: true }, (event, filename) => { if (!filename) return console.log(`[${new Date().toLocaleTimeString()}] ${event}: ${filename}`) if (timer) clearTimeout(timer) timer = setTimeout(() => { console.log('\nDeploying...\n') try { execSync(`bash ${DEPLOY_SCRIPT}`, { stdio: 'inherit' }) console.log('\nWatching for next change...\n') } catch (e) { console.error('Deploy failed:', e.message) } }, COOLDOWN_MS) })