#2 implement debugger
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "./debugger.mjs";
|
||||
const log = new DebugBuilder("client", "selfUpdater");
|
||||
import simpleGit from 'simple-git';
|
||||
import { restartService } from './serviceHandler.mjs'
|
||||
import { launchProcess } from './subprocessHandler.mjs'
|
||||
@@ -17,14 +19,14 @@ export const checkForUpdates = async () => {
|
||||
const localCommitHash = await git.revparse(['HEAD']);
|
||||
|
||||
if (latestCommitHash !== localCommitHash) {
|
||||
console.log('An update is available. Updating...');
|
||||
log.INFO('An update is available. Updating...');
|
||||
|
||||
// Check if there have been any changes to the code
|
||||
const gitStatus = await git.status()
|
||||
console.log(gitStatus);
|
||||
log.INFO(gitStatus);
|
||||
if (gitStatus.modified.length > 0){
|
||||
// There is locally modified code
|
||||
console.log("There is locally modified code, resetting...");
|
||||
log.INFO("There is locally modified code, resetting...");
|
||||
await git.stash();
|
||||
await git.reset('hard', ['origin/master']);
|
||||
}
|
||||
@@ -33,25 +35,25 @@ export const checkForUpdates = async () => {
|
||||
await git.pull();
|
||||
|
||||
// Run the post-update script
|
||||
console.log('Running post-update script...');
|
||||
log.INFO('Running post-update script...');
|
||||
await launchProcess("bash", ['./post-update.sh'], true);
|
||||
|
||||
// Restart the application to apply the updates
|
||||
console.log('Update completed successfully. Restarting the application...');
|
||||
log.INFO('Update completed successfully. Restarting the application...');
|
||||
restartApplication();
|
||||
|
||||
return true
|
||||
} else {
|
||||
console.log('The application is up to date.');
|
||||
log.INFO('The application is up to date.');
|
||||
return false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking for updates:', error);
|
||||
log.ERROR('Error checking for updates:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to restart the application
|
||||
export const restartApplication = () => {
|
||||
console.log('Restarting the application...');
|
||||
log.INFO('Restarting the application...');
|
||||
restartService('discord-radio-bot');
|
||||
}
|
||||
Reference in New Issue
Block a user