import simpleGit from 'simple-git'; import { restartService } from './serviceHandler.mjs' const git = simpleGit(); // Function to check for updates export const checkForUpdates = async () => { try { // Fetch remote changes await git.fetch(); // Get the latest commit hash const latestCommitHash = await git.revparse(['@{u}']); // Compare with the local commit hash const localCommitHash = await git.revparse(['HEAD']); if (latestCommitHash !== localCommitHash) { console.log('An update is available. Updating...'); // Pull the latest changes from the remote repository await git.pull(); console.log('Update completed successfully. Restarting the application...'); // Restart the application to apply the updates restartApplication(); } else { console.log('The application is up to date.'); } } catch (error) { console.error('Error checking for updates:', error); } } // Function to restart the application const restartApplication = () => { console.log('Restarting the application...'); restartService('discord-radio-bot'); }