From 55bf3e2c44970dedd40faf552049c529f59ee9c1 Mon Sep 17 00:00:00 2001 From: Kallum Jones Date: Mon, 1 Aug 2022 14:36:20 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 133 +++++++++++++++++++++++++++++++++++ package-lock.json | 83 ++++++++++++++++++++++ package.json | 21 ++++++ src/commands/init_command.ts | 16 +++++ src/commands/subcommand.ts | 6 ++ src/mod-manager.ts | 39 ++++++++++ src/util/initialiser.ts | 53 ++++++++++++++ src/util/print_utils.ts | 19 +++++ tsconfig.json | 38 ++++++++++ 9 files changed, 408 insertions(+) create mode 100644 .gitignore create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/commands/init_command.ts create mode 100644 src/commands/subcommand.ts create mode 100644 src/mod-manager.ts create mode 100644 src/util/initialiser.ts create mode 100644 src/util/print_utils.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b03ab2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +server/ \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..caf0e39 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,83 @@ +{ + "name": "mod-manager", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "mod-manager", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "chalk": "^5.0.1", + "commander": "^9.4.0" + }, + "devDependencies": { + "@types/node": "^18.6.3", + "typescript": "^4.7.4" + } + }, + "node_modules/@types/node": { + "version": "18.6.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz", + "integrity": "sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==", + "dev": true + }, + "node_modules/chalk": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", + "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/commander": { + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz", + "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==", + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@types/node": { + "version": "18.6.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz", + "integrity": "sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==", + "dev": true + }, + "chalk": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", + "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==" + }, + "commander": { + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz", + "integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==" + }, + "typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee6f641 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "mod-manager", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "chalk": "^5.0.1", + "commander": "^9.4.0" + }, + "devDependencies": { + "@types/node": "^18.6.3", + "typescript": "^4.7.4" + } +} diff --git a/src/commands/init_command.ts b/src/commands/init_command.ts new file mode 100644 index 0000000..fa0e96d --- /dev/null +++ b/src/commands/init_command.ts @@ -0,0 +1,16 @@ +import { Command } from "commander"; +import Initialiser from "../util/initialiser.js"; +import Subcommand from "./subcommand.js"; + +export default class InitCommand extends Subcommand { + registerCommand(program: Command) { + program.command("init") + .description("Initalises mod manager") + .action(this.execute); + } + + execute() { + Initialiser.initialise(); + } + +} \ No newline at end of file diff --git a/src/commands/subcommand.ts b/src/commands/subcommand.ts new file mode 100644 index 0000000..1f2a9a6 --- /dev/null +++ b/src/commands/subcommand.ts @@ -0,0 +1,6 @@ +import { Command } from "commander"; + +export default abstract class Subcommand { + abstract registerCommand(program: Command): void; + abstract execute(): void; +} \ No newline at end of file diff --git a/src/mod-manager.ts b/src/mod-manager.ts new file mode 100644 index 0000000..b35f247 --- /dev/null +++ b/src/mod-manager.ts @@ -0,0 +1,39 @@ +#!/usr/bin/env node +import { Command } from "commander"; +import InitCommand from "./commands/init_command.js"; +import Subcommand from "./commands/subcommand.js"; +import Initialiser from "./util/initialiser.js"; +import PrintUtils from "./util/print_utils.js"; + +export default class ModManager { + private static program: Command = new Command(); + + private static subcommands: Array = [ + new InitCommand() + ]; + + static init() { + this.program + .name('mod-manager') + .description('A package (mod) manager for Fabric Minecraft Servers'); + + this.subcommands.forEach(command => { + command.registerCommand(ModManager.program); + }); + + this.program.parse(); + } + + static execute(callback: () => any): void { + if (Initialiser.isInitialised()) { + callback(); + } else { + PrintUtils.error("Mod Manager is not initialised"); + } + } +} + + +ModManager.init(); + + diff --git a/src/util/initialiser.ts b/src/util/initialiser.ts new file mode 100644 index 0000000..523c92f --- /dev/null +++ b/src/util/initialiser.ts @@ -0,0 +1,53 @@ +import { existsSync, mkdirSync } from "fs"; +import PrintUtils from "./print_utils.js"; + +export default class Initialiser { + private static readonly MOD_MANAGER_FOLDER = ".mod-manager" + + public static initialise(): void { + if (!this.isInitialised()) { + if (this.isDirFabricServer()) { + const success: boolean = this.setupFolderStructure(); + + if (success) { + PrintUtils.success("Sucessfully initialised Mod Manager!"); + } else { + PrintUtils.error("Unable to set up the Mod Manager folder structure"); + } + } else { + PrintUtils.error("Unable to initialise Mod Manager as this is not a Fabric Minecraft Server"); + } + } else { + PrintUtils.warn("Mod Manager is already initialised!"); + } + } + + public static isInitialised(): boolean { + return existsSync(this.getModManagerFolderPath()); + } + + private static isDirFabricServer(): boolean { + const workingDirectory = process.cwd(); + + const serverProperties = `${workingDirectory}/server.properties`; + const fabric = `${workingDirectory}/.fabric`; + + return existsSync(serverProperties) && existsSync(fabric); + } + + private static setupFolderStructure(): boolean { + if (!existsSync(this.getModManagerFolderPath())) { + mkdirSync(this.getModManagerFolderPath()); + return true; + } else { + return false; + } + } + + private static getModManagerFolderPath(): string { + const workingDirectory = process.cwd(); + + return `${workingDirectory}/${this.MOD_MANAGER_FOLDER}`; + } + +} \ No newline at end of file diff --git a/src/util/print_utils.ts b/src/util/print_utils.ts new file mode 100644 index 0000000..43ed73b --- /dev/null +++ b/src/util/print_utils.ts @@ -0,0 +1,19 @@ +import chalk from "chalk"; + +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)); + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..35e9a1e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + // project options + "lib": [ + "ESNext", + "dom" + ], // specifies which default set of type definitions to use ("DOM", "ES6", etc) + "outDir": "dist", // .js (as well as .d.ts, .js.map, etc.) files will be emitted into this directory., + "removeComments": true, // Strips all comments from TypeScript files when converting into JavaScript- you rarely read compiled code so this saves space + "target": "ES6", // Target environment. Most modern browsers support ES6, but you may want to set it to newer or older. (defaults to ES3) + + // Module resolution + "baseUrl": "./", // Lets you set a base directory to resolve non-absolute module names. + "esModuleInterop": true, // fixes some issues TS originally had with the ES6 spec where TypeScript treats CommonJS/AMD/UMD modules similar to ES6 module + "moduleResolution": "node", // Pretty much always node for modern JS. Other option is "classic" + "paths": {}, // A series of entries which re-map imports to lookup locations relative to the baseUrl + + // Source Map + "sourceMap": true, // enables the use of source maps for debuggers and error reporting etc + "sourceRoot": "/", // Specify the location where a debugger should locate TypeScript files instead of relative source locations. + + // Strict Checks + "alwaysStrict": true, // Ensures that your files are parsed in the ECMAScript strict mode, and emit “use strict” for each source file. + "allowUnreachableCode": false, // pick up dead code paths + "noImplicitAny": true, // In some cases where no type annotations are present, TypeScript will fall back to a type of any for a variable when it cannot infer the type. + "strictNullChecks": true, // When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected. + + // Linter Checks + "noImplicitReturns": true, + "noUncheckedIndexedAccess": true, // accessing index must always check for undefined + "noUnusedLocals": true, // Report errors on unused local variables. + "noUnusedParameters": true // Report errors on unused parameters in functions + }, + "include": ["./**/*.ts"], + "exclude": [ + "node_modules/**/*" + ] +} \ No newline at end of file