From 042500f850883041693cfb1b78571d4246ffd864 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Sun, 3 Mar 2019 05:49:18 +0200 Subject: [PATCH 1/3] Create reinstall.ts --- packages/core/src/commands/reinstall.ts | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 packages/core/src/commands/reinstall.ts diff --git a/packages/core/src/commands/reinstall.ts b/packages/core/src/commands/reinstall.ts new file mode 100644 index 0000000000..8bbbf519ee --- /dev/null +++ b/packages/core/src/commands/reinstall.ts @@ -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 { + const { flags } = await this.parseWithNetwork(ReinstallCommand); + + if (flags.force) { + return this.execute(flags); + } + + try { + await confirm("Are you sure you want to reinstall?", async () => { + try { + await this.execute(flags); + } catch (err) { + this.error(err.message); + } finally { + cli.action.stop(); + } + }); + } catch (err) { + this.error(err.message); + } + } + + private async execute(flags: CommandFlags, state: Record): Promise { + 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`); + } +} From a774d1c5f371ee69a919ffe88a7cfda7141263a5 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Sun, 3 Mar 2019 05:54:14 +0200 Subject: [PATCH 2/3] Update reinstall.ts --- packages/core/src/commands/reinstall.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/commands/reinstall.ts b/packages/core/src/commands/reinstall.ts index 8bbbf519ee..4269bf3d8f 100644 --- a/packages/core/src/commands/reinstall.ts +++ b/packages/core/src/commands/reinstall.ts @@ -20,13 +20,13 @@ export class ReinstallCommand extends BaseCommand { const { flags } = await this.parseWithNetwork(ReinstallCommand); if (flags.force) { - return this.execute(flags); + return this.performInstall(flags); } try { await confirm("Are you sure you want to reinstall?", async () => { try { - await this.execute(flags); + await this.performInstall(flags); } catch (err) { this.error(err.message); } finally { @@ -38,7 +38,7 @@ export class ReinstallCommand extends BaseCommand { } } - private async execute(flags: CommandFlags, state: Record): Promise { + private async performInstall(flags: CommandFlags, state: Record): Promise { cli.action.start(`Reinstalling ${this.config.version}`); await installFromChannel(this.config.name, this.config.version); From 3ba780cf72b4c7ae95fdd34bfcf8e8e7cb54f56a Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Sun, 3 Mar 2019 05:54:25 +0200 Subject: [PATCH 3/3] Update reinstall.ts --- packages/core/src/commands/reinstall.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/commands/reinstall.ts b/packages/core/src/commands/reinstall.ts index 4269bf3d8f..91cef47194 100644 --- a/packages/core/src/commands/reinstall.ts +++ b/packages/core/src/commands/reinstall.ts @@ -38,7 +38,7 @@ export class ReinstallCommand extends BaseCommand { } } - private async performInstall(flags: CommandFlags, state: Record): Promise { + private async performInstall(flags: CommandFlags): Promise { cli.action.start(`Reinstalling ${this.config.version}`); await installFromChannel(this.config.name, this.config.version);