Ran a reformat

This commit is contained in:
Kallum Jones 2022-08-09 14:56:46 +01:00
parent 7d6d49ec19
commit d47e752f1a
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9
9 changed files with 95 additions and 73 deletions

View File

@ -1,8 +1,11 @@
# Mod Manager
A package manager-like CLI utility for installing, upgrading and migrating mods on Fabric Minecraft Servers
## Envrionment Variables
The list of required variables are as follows:
```
CURSEFORGE_API_KEY="**api key goes here**"
```

View File

@ -20,9 +20,15 @@ import {CurseforgeSource} from "./mods/sources/curseforge_source.js";
export default class ModManager {
public static logger: Logger | null = null;
static FilePaths = class {
public static readonly MOD_MANAGER_FOLDER_PATH = path.join(".mod-manager");
public static readonly LOGS_FOLDER = path.join(this.MOD_MANAGER_FOLDER_PATH, "logs");
public static readonly LOG_FILE: string = path.join(this.LOGS_FOLDER, `${new Date().valueOf()}.log.json`);
public static readonly MOD_FILE_PATH = path.join(this.MOD_MANAGER_FOLDER_PATH, "mods.json");
public static readonly VERSION_FILE_PATH = path.join(this.MOD_MANAGER_FOLDER_PATH, "version")
public static readonly MODS_FOLDER_PATH = path.join("mods")
}
private static program: Command = new Command();
private static subcommands: Array<Subcommand> = [
new InitCommand(),
new InstallCommand(),
@ -34,15 +40,6 @@ export default class ModManager {
new MigrateCommand()
];
static FilePaths = class {
public static readonly MOD_MANAGER_FOLDER_PATH = path.join(".mod-manager");
public static readonly LOGS_FOLDER = path.join(this.MOD_MANAGER_FOLDER_PATH, "logs");
public static readonly LOG_FILE: string = path.join(this.LOGS_FOLDER, `${new Date().valueOf()}.log.json`);
public static readonly MOD_FILE_PATH = path.join(this.MOD_MANAGER_FOLDER_PATH, "mods.json");
public static readonly VERSION_FILE_PATH = path.join(this.MOD_MANAGER_FOLDER_PATH, "version")
public static readonly MODS_FOLDER_PATH = path.join("mods")
}
static init() {
if (Initialiser.isInitialised()) {
this.logger = ModManager.createLogger();
@ -76,7 +73,8 @@ export default class ModManager {
let logger = pino({
base: {
pid: undefined,
hostname: undefined}
hostname: undefined
}
},
pino.destination({
dest: ModManager.FilePaths.LOG_FILE,

View File

@ -161,30 +161,6 @@ export default class Mods {
}
}
/**
* Finds the mod based on the provided id or name
* @param mod the id or mod name
* @return the found Mod, or undefined if no mod was found
*/
private static findMod(mod: string): TrackedMod | undefined {
// Replace underscores and dashes with spaces
mod = mod.replaceAll("_", " ");
mod = mod.replaceAll("-", " ")
let mods: Array<TrackedMod> = this.getTrackedMods();
for (let modEle of mods) {
const id = modEle.id.toLowerCase();
const name = modEle.name.toLowerCase();
const query = mod.toLowerCase();
if (id == query || Util.areStringsSimilar(mod, name)) {
return modEle;
}
}
return undefined;
}
static async update() {
const trackedMods = this.getTrackedMods();
@ -286,10 +262,6 @@ export default class Mods {
return possible;
}
private static getEssentialMods() {
return this.getTrackedMods().filter(mod => mod.essential);
}
/**
* Migrates to the provided version of minecraft
* @param version the Minecraft version to migrate to
@ -343,6 +315,34 @@ export default class Mods {
PrintUtils.success(`Successfully migrated to ${version}`)
}
/**
* Finds the mod based on the provided id or name
* @param mod the id or mod name
* @return the found Mod, or undefined if no mod was found
*/
private static findMod(mod: string): TrackedMod | undefined {
// Replace underscores and dashes with spaces
mod = mod.replaceAll("_", " ");
mod = mod.replaceAll("-", " ")
let mods: Array<TrackedMod> = this.getTrackedMods();
for (let modEle of mods) {
const id = modEle.id.toLowerCase();
const name = modEle.name.toLowerCase();
const query = mod.toLowerCase();
if (id == query || Util.areStringsSimilar(mod, name)) {
return modEle;
}
}
return undefined;
}
private static getEssentialMods() {
return this.getTrackedMods().filter(mod => mod.essential);
}
private static isDependedOn(dependency: string) {
const trackedMods = this.getTrackedMods();

View File

@ -11,7 +11,9 @@ export default class Util {
return str // insert a space before all caps
.replace(/([A-Z])/g, ' $1')
// uppercase the first character
.replace(/^./, function(str){ return str.toUpperCase(); })
.replace(/^./, function (str) {
return str.toUpperCase();
})
}
static areStringsSimilar(master: string, compare: string): boolean {

View File

@ -4,34 +4,53 @@
"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)
],
// 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
"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.
"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 youll get a type error if you try to use them where a concrete value is expected.
"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 youll 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
"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"],
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules/**/*"
]