1
0
Fork 0

included extra stuff

refactor/models
Bsian 2019-11-01 23:15:39 +00:00
parent 0c4902fb61
commit d918cd30bd
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 49 additions and 12 deletions

View File

@ -14,27 +14,64 @@ export default class Pull extends Command {
public async run(message: Message) { public async run(message: Message) {
try { try {
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`); const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\ngit pull\n\`\`\``);
let pull: string; let pull: string;
try { try {
pull = await this.client.util.exec('git pull'); pull = await this.client.util.exec('git pull');
} catch (error) { } catch (error) {
return updateMessage.edit(`${this.client.stores.emojis.error} ***Could not fetch latest commit***\n\`\`\`sh\n${error.message}\n\`\`\``); const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Could not fetch latest commit***`)
}
if (pull.includes('Already up to date')) return updateMessage.edit(`${this.client.stores.emojis.success} ***No updates available***`);
if (!pull.includes('origin/master')) return updateMessage.edit(`${this.client.stores.emojis.error} ***Unexpected output:***\n\`\`\`sh\n${pull}\n\`\`\``);
const passedPull = await updateMessage.edit(`${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Rebuilding files...***\n\`\`\`sh\n${pull}\n\`\`\``);
try {
await this.client.util.exec('cd ../ && tsc -p ./tsconfig.json');
} catch (error) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`)
.replace(/```$/, `${error.message}\n\`\`\``); .replace(/```$/, `${error.message}\n\`\`\``);
return updateMessage.edit(updatedMessage); return updateMessage.edit(updatedMessage);
} }
if (pull.includes('Already up to date')) {
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***No updates available***`)
.replace(/```$/, `${pull}\n\`\`\``);
return updateMessage.edit(updatedMessage);
}
if (!pull.includes('origin/master')) {
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`)
.replace(/```$/, `${pull}\n\`\`\``);
return updateMessage.edit(updatedMessage);
}
const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`)
.replace(/```$/, `${pull}\nyarn install\n\`\`\``);
const passedPull = await updateMessage.edit(continueMessage);
const finalMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`);
let install: string;
try {
install = await this.client.util.exec('yarn install');
} catch (error) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Failed to reinstall dependencies***`)
.replace(/```$/, `${error.message}\n\`\`\``);
return updateMessage.edit(updatedMessage);
}
let updatedPackages: Message;
if (install.includes('Already up-to-date')) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
updatedPackages = await updateMessage.edit(updatedMessage);
} else if (install.includes('success Saved lockfile.')) {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
updatedPackages = await updateMessage.edit(updatedMessage);
} else {
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`)
.replace(/```$/, `${pull}\n\`\`\``);
return updateMessage.edit(updatedMessage);
}
let build: string;
try {
build = await this.client.util.exec('yarn run build');
} catch (error) {
const updatedMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.error} ***Failed to rebuild files***`)
.replace(/```$/, `${error.message}\n\`\`\``);
return updateMessage.edit(updatedMessage);
}
const finalMessage = updatedPackages.content.replace(`${this.client.stores.emojis.loading} ***Rebuilding files...***`, `${this.client.stores.emojis.success} ***Files rebuilt***`)
.replace(/```$/, `${build}\n\`\`\``);
return updateMessage.edit(finalMessage); return updateMessage.edit(finalMessage);
} catch (error) { } catch (error) {