diff --git a/.gitignore b/.gitignore index 8b03ab2..56f1372 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,6 @@ dist .yarn/install-state.gz .pnp.* -server/ \ No newline at end of file +server/ + +.idea/ \ No newline at end of file diff --git a/src/commands/init_command.ts b/src/commands/init_command.ts index b8c018b..eaa2cef 100644 --- a/src/commands/init_command.ts +++ b/src/commands/init_command.ts @@ -2,15 +2,12 @@ import { Command } from "commander"; import Initialiser from "../util/initialiser.js"; import Subcommand from "./subcommand.js"; -export default class InitCommand extends Subcommand { +export default class InitCommand implements Subcommand { registerCommand(program: Command) { program.command("init") .description("Initialises mod manager") - .action(this.execute); + .action(() => { + Initialiser.initialise(); + }); } - - execute() { - Initialiser.initialise(); - } - } \ No newline at end of file diff --git a/src/util/initialiser.ts b/src/util/initialiser.ts index 523c92f..003e91c 100644 --- a/src/util/initialiser.ts +++ b/src/util/initialiser.ts @@ -1,4 +1,6 @@ -import { existsSync, mkdirSync } from "fs"; +import { existsSync, mkdirSync, writeFileSync } from "fs"; +import path from "path"; +import Mods from "../mods/mods.js"; import PrintUtils from "./print_utils.js"; export default class Initialiser { @@ -27,10 +29,8 @@ export default class Initialiser { } private static isDirFabricServer(): boolean { - const workingDirectory = process.cwd(); - - const serverProperties = `${workingDirectory}/server.properties`; - const fabric = `${workingDirectory}/.fabric`; + const serverProperties = path.join("server.properties"); + const fabric = path.join(".fabric"); return existsSync(serverProperties) && existsSync(fabric); } @@ -38,16 +38,15 @@ export default class Initialiser { private static setupFolderStructure(): boolean { if (!existsSync(this.getModManagerFolderPath())) { mkdirSync(this.getModManagerFolderPath()); + writeFileSync(Mods.getModFilePath(), "[]"); return true; } else { return false; } } - private static getModManagerFolderPath(): string { - const workingDirectory = process.cwd(); - - return `${workingDirectory}/${this.MOD_MANAGER_FOLDER}`; + public static getModManagerFolderPath(): string { + return path.join(this.MOD_MANAGER_FOLDER); } } \ No newline at end of file