From 6b700d465b788abfa9aecf9f97541fd10eb119e8 Mon Sep 17 00:00:00 2001 From: Kallum Jones Date: Wed, 3 Aug 2022 16:55:12 +0100 Subject: [PATCH] Ran a reformat --- src/commands/init_command.ts | 10 ++--- src/commands/install_command.ts | 2 +- src/commands/subcommand.ts | 2 +- src/mod-manager.ts | 69 ++++++++++++++++----------------- src/mods/mods.ts | 1 - src/mods/sources/mod_source.ts | 2 + src/util/initialiser.ts | 8 ++-- src/util/print_utils.ts | 36 ++++++++--------- 8 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/commands/init_command.ts b/src/commands/init_command.ts index eaa2cef..7ea26dd 100644 --- a/src/commands/init_command.ts +++ b/src/commands/init_command.ts @@ -1,13 +1,13 @@ -import { Command } from "commander"; +import {Command} from "commander"; import Initialiser from "../util/initialiser.js"; import Subcommand from "./subcommand.js"; export default class InitCommand implements Subcommand { registerCommand(program: Command) { program.command("init") - .description("Initialises mod manager") - .action(() => { - Initialiser.initialise(); - }); + .description("Initialises mod manager") + .action(() => { + Initialiser.initialise(); + }); } } \ No newline at end of file diff --git a/src/commands/install_command.ts b/src/commands/install_command.ts index 109196f..4d9ffb3 100644 --- a/src/commands/install_command.ts +++ b/src/commands/install_command.ts @@ -1,4 +1,4 @@ -import { Command } from "commander"; +import {Command} from "commander"; import Subcommand from "./subcommand.js" import ModManager from "../mod-manager.js"; import Mods from "../mods/mods.js"; diff --git a/src/commands/subcommand.ts b/src/commands/subcommand.ts index a5808ed..648b2f7 100644 --- a/src/commands/subcommand.ts +++ b/src/commands/subcommand.ts @@ -1,4 +1,4 @@ -import { Command } from "commander"; +import {Command} from "commander"; export default interface Subcommand { registerCommand(program: Command): void; diff --git a/src/mod-manager.ts b/src/mod-manager.ts index 7617dd1..b337b25 100644 --- a/src/mod-manager.ts +++ b/src/mod-manager.ts @@ -10,50 +10,49 @@ import {Logger, pino} from "pino" export default class ModManager { - public static logger: Logger | null = null; - private static readonly LOG_FILE: string = path.join(Initialiser.getModManagerFolderPath(), "logs", `${new Date().valueOf()}.log.json`); + public static logger: Logger | null = null; + private static readonly LOG_FILE: string = path.join(Initialiser.getModManagerFolderPath(), "logs", `${new Date().valueOf()}.log.json`); - private static program: Command = new Command(); + private static program: Command = new Command(); - private static subcommands: Array = [ - new InitCommand(), - new InstallCommand() - ]; + private static subcommands: Array = [ + new InitCommand(), + new InstallCommand() + ]; - static init() { - if (Initialiser.isInitialised()) { - this.logger = ModManager.createLogger(); + static init() { + if (Initialiser.isInitialised()) { + this.logger = ModManager.createLogger(); + } + + this.program + .name('mod-manager') + .description('A package (mod) manager for Fabric Minecraft Servers'); + + for (const command of this.subcommands) { + command.registerCommand(this.program); + } + + this.program.parse(); } - - this.program - .name('mod-manager') - .description('A package (mod) manager for Fabric Minecraft Servers'); - - for (const command of this.subcommands) { - command.registerCommand(this.program); + static execute(callback: () => any): void { + if (Initialiser.isInitialised()) { + callback(); + } else { + PrintUtils.error("Mod Manager is not initialised"); + } } - this.program.parse(); - } + static createLogger(): Logger { + let logger = pino({base: {pid: undefined, hostname: undefined}}, pino.destination({dest: this.LOG_FILE})); + process.on("uncaughtException", error => { + logger.error(error); + setTimeout(() => process.exit(1), 1) + }) - static execute(callback: () => any): void { - if (Initialiser.isInitialised()) { - callback(); - } else { - PrintUtils.error("Mod Manager is not initialised"); + return logger; } - } - - static createLogger(): Logger { - let logger = pino({base: {pid: undefined, hostname: undefined}}, pino.destination({dest: this.LOG_FILE})); - process.on("uncaughtException", error => { - logger.error(error); - setTimeout(() => process.exit(1), 1) - }) - - return logger; - } } ModManager.init(); diff --git a/src/mods/mods.ts b/src/mods/mods.ts index 62bfd1d..09e21df 100644 --- a/src/mods/mods.ts +++ b/src/mods/mods.ts @@ -1,4 +1,3 @@ - import path from "path"; import Initialiser from "../util/initialiser.js"; import PrintUtils from "../util/print_utils.js"; diff --git a/src/mods/sources/mod_source.ts b/src/mods/sources/mod_source.ts index 3ec1a64..9238b27 100644 --- a/src/mods/sources/mod_source.ts +++ b/src/mods/sources/mod_source.ts @@ -1,5 +1,7 @@ export default interface ModSource { search(query: string): Promise; + install(id: string): Promise; + getName(): string; } \ No newline at end of file diff --git a/src/util/initialiser.ts b/src/util/initialiser.ts index c78a22c..73c00cf 100644 --- a/src/util/initialiser.ts +++ b/src/util/initialiser.ts @@ -35,6 +35,10 @@ export default class Initialiser { return existsSync(this.getModManagerFolderPath()); } + public static getModManagerFolderPath(): string { + return path.join(this.MOD_MANAGER_FOLDER); + } + private static isDirFabricServer(): boolean { const serverProperties = path.join("server.properties"); const fabric = path.join(".fabric"); @@ -53,8 +57,4 @@ export default class Initialiser { } } - public static getModManagerFolderPath(): string { - return path.join(this.MOD_MANAGER_FOLDER); - } - } \ No newline at end of file diff --git a/src/util/print_utils.ts b/src/util/print_utils.ts index b9e393d..4bc5bdc 100644 --- a/src/util/print_utils.ts +++ b/src/util/print_utils.ts @@ -1,24 +1,8 @@ import chalk from "chalk"; -import ora, { Ora } from "ora"; +import ora, {Ora} from "ora"; export default class PrintUtils { - static info(print: string) { - console.log(chalk.white(print)); - } - - static warn(print: string) { - console.log(chalk.yellowBright(print)); - } - - static success(print: string) { - console.log(chalk.greenBright(print)); - } - - static error(print: string) { - console.log(chalk.redBright(print)); - } - static Spinner = class { private spinner: Ora; @@ -26,7 +10,7 @@ export default class PrintUtils { if (text == null || undefined) { text = ""; } - + this.spinner = ora(text); } @@ -54,4 +38,20 @@ export default class PrintUtils { this.spinner.clear(); } } + + static info(print: string) { + console.log(chalk.white(print)); + } + + static warn(print: string) { + console.log(chalk.yellowBright(print)); + } + + static success(print: string) { + console.log(chalk.greenBright(print)); + } + + static error(print: string) { + console.log(chalk.redBright(print)); + } } \ No newline at end of file