#!/usr/bin/env node

/**
 * Setup script to enable auto-updates in development mode
 * Creates app-update.yml in the Electron development app bundle
 */

const fs = require('fs');
const path = require('path');

const electronPath = path.join(
  __dirname,
  '..',
  'node_modules',
  'electron',
  'dist',
  'Electron.app',
  'Contents',
  'Resources'
);

const appUpdatePath = path.join(electronPath, 'app-update.yml');

const appUpdateContent = `provider: github
owner: instructure
repo: inst-agent
private: true
updaterCacheDirName: instructure-agent-updater
`;

// Create directory if it doesn't exist
if (!fs.existsSync(electronPath)) {
  console.log('Creating Resources directory...');
  fs.mkdirSync(electronPath, { recursive: true });
}

// Write app-update.yml
fs.writeFileSync(appUpdatePath, appUpdateContent, 'utf8');

console.log('✅ Dev update configuration created!');
console.log(`   Location: ${appUpdatePath}`);
console.log('');
console.log('You can now test auto-updates in development mode.');
console.log('Run: npm start');
