Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add support for forced updates #2190

Merged
merged 6 commits into from
Mar 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update update.ts
  • Loading branch information
faustbrian authored Mar 2, 2019
commit 257c56a929f82a65b527a7a4089df4430a2a034e
56 changes: 41 additions & 15 deletions packages/core/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ import { removeSync } from "fs-extra";
import { confirm } from "../helpers/prompts";
import { checkForUpdates, installFromChannel } from "../helpers/update";
import { BaseCommand } from "./command";
import { CommandFlags } from "../../types";
import { flags } from "@oclif/command";

export class UpdateCommand extends BaseCommand {
public static description: string = "Update the core installation";

public static flags: CommandFlags = {
force: flags.boolean({
description: "force an update",
}),
};

public async run(): Promise<void> {
const { flags } = await this.parseWithNetwork(UpdateCommand);

const state = await checkForUpdates(this);

if (flags.force) {
return this.performUpdate(flags, state);
}

if (!state.ready) {
this.log(`You already have the latest version (${state.currentVersion})`);

Expand All @@ -29,21 +43,7 @@ export class UpdateCommand extends BaseCommand {

await confirm("Would you like to update?", async () => {
try {
cli.action.start(`Updating from ${currentVersion} to ${newVersion}`);

await installFromChannel(state.name, state.channel);

cli.action.stop();

removeSync(state.cache);

this.warn(`Version ${newVersion} has been installed.`);

const { flags } = await this.parseWithNetwork(UpdateCommand);

await this.restartProcess(`${flags.token}-core`);
await this.restartProcess(`${flags.token}-relay`);
await this.restartProcess(`${flags.token}-forger`);
await this.performUpdate(flags, state);
} catch (err) {
this.error(err.message);
} finally {
Expand All @@ -54,4 +54,30 @@ export class UpdateCommand extends BaseCommand {
this.error(err.message);
}
}

private async performUpdate(flags: CommandFlags, state: Record<string, any>): Promise<void> {
let installVersion;

if (flags.force) {
cli.action.start(`Updating from ${state.currentVersion} to ${state.newVersion}`);

installVersion = state.newVersion;
} else {
cli.action.start(`Reinstalling ${state.currentVersion}`);

installVersion = state.currentVersion;
}

await installFromChannel(state.name, installVersion);

cli.action.stop();

removeSync(state.cache);

this.warn(`Version ${installVersion} has been installed.`);

await this.restartProcess(`${flags.token}-core`);
await this.restartProcess(`${flags.token}-relay`);
await this.restartProcess(`${flags.token}-forger`);
}
}