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 reinstalling the current version #2192

Merged
merged 3 commits into from
Mar 3, 2019
Merged
Changes from all commits
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
54 changes: 54 additions & 0 deletions packages/core/src/commands/reinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Chalk from "chalk";
import cli from "cli-ux";
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 ReinstallCommand extends BaseCommand {
public static description: string = "Reinstall the core";

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

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

if (flags.force) {
return this.performInstall(flags);
}

try {
await confirm("Are you sure you want to reinstall?", async () => {
try {
await this.performInstall(flags);
} catch (err) {
this.error(err.message);
} finally {
cli.action.stop();
}
});
} catch (err) {
this.error(err.message);
}
}

private async performInstall(flags: CommandFlags): Promise<void> {
cli.action.start(`Reinstalling ${this.config.version}`);

await installFromChannel(this.config.name, this.config.version);

cli.action.stop();

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

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