Support updating private code in /updateserver (#7183)

This commit is contained in:
Annika
2020-08-09 20:24:32 -07:00
committed by GitHub
parent 4dba9e44e3
commit 2b809f99e4

View File

@@ -735,7 +735,7 @@ export const commands: ChatCommands = {
async updateserver(target, room, user, connection) {
if (!this.canUseConsole()) return false;
const isPrivate = toID(target) === 'private';
if (Monitor.updateServerLock) {
return this.errorReply(`/updateserver - Another update is already in progress (or a previous update crashed).`);
}
@@ -746,7 +746,7 @@ export const commands: ChatCommands = {
this.stafflog(`$ ${command}`);
return new Promise((resolve, reject) => {
child_process.exec(command, {
cwd: __dirname,
cwd: `${__dirname}/../../${isPrivate ? Config.privatecodepath || '../main-private/' : ``}`,
}, (error, stdout, stderr) => {
let log = `[o] ${stdout}[e] ${stderr}`;
if (error) log = `[c] ${error.code}\n${log}`;
@@ -757,13 +757,13 @@ export const commands: ChatCommands = {
};
this.sendReply(`Fetching newest version...`);
this.addGlobalModAction(`${user.name} used /updateserver`);
this.addGlobalModAction(`${user.name} used /updateserver ${isPrivate ? `private` : `public`}`);
let [code, stdout, stderr] = await exec(`git fetch`);
if (code) throw new Error(`updateserver: Crash while fetching - make sure this is a Git repository`);
if (!stdout && !stderr) {
if (!isPrivate && !stdout && !stderr) {
this.sendReply(`There were no updates.`);
[code, stdout, stderr] = await exec('node ../../build');
[code, stdout, stderr] = await exec('node ./build');
if (stderr) {
return this.errorReply(`Crash while rebuilding: ${stderr}`);
}
@@ -815,11 +815,13 @@ export const commands: ChatCommands = {
await exec(`git stash pop`);
this.sendReply(`FAILED, old changes restored.`);
}
[code, stdout, stderr] = await exec('node ../../build');
if (stderr) {
return this.errorReply(`Crash while rebuilding: ${stderr}`);
if (!isPrivate) {
[code, stdout, stderr] = await exec('node ./build');
if (stderr) {
return this.errorReply(`Crash while rebuilding: ${stderr}`);
}
this.sendReply(`Rebuilt.`);
}
this.sendReply(`Rebuilt.`);
Monitor.updateServerLock = false;
},