mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2024-12-22 04:18:21 -05:00
Add list command
This commit is contained in:
parent
b9c2f22de3
commit
66f4c2b289
27
package-lock.json
generated
27
package-lock.json
generated
@ -9,6 +9,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"as-table": "^1.0.55",
|
||||
"axios": "^0.27.2",
|
||||
"chalk": "^5.0.1",
|
||||
"commander": "^9.4.0",
|
||||
@ -51,6 +52,14 @@
|
||||
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/as-table": {
|
||||
"version": "1.0.55",
|
||||
"resolved": "https://registry.npmjs.org/as-table/-/as-table-1.0.55.tgz",
|
||||
"integrity": "sha512-xvsWESUJn0JN421Xb9MQw6AsMHRCUknCe0Wjlxvjud80mU4E6hQf1A6NzQKcYNmYw62MfzEtXc+badstZP3JpQ==",
|
||||
"dependencies": {
|
||||
"printable-characters": "^1.0.42"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
@ -573,6 +582,11 @@
|
||||
"renderkid": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/printable-characters": {
|
||||
"version": "1.0.42",
|
||||
"resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz",
|
||||
"integrity": "sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ=="
|
||||
},
|
||||
"node_modules/process-warning": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-2.0.0.tgz",
|
||||
@ -793,6 +807,14 @@
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz",
|
||||
"integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA=="
|
||||
},
|
||||
"as-table": {
|
||||
"version": "1.0.55",
|
||||
"resolved": "https://registry.npmjs.org/as-table/-/as-table-1.0.55.tgz",
|
||||
"integrity": "sha512-xvsWESUJn0JN421Xb9MQw6AsMHRCUknCe0Wjlxvjud80mU4E6hQf1A6NzQKcYNmYw62MfzEtXc+badstZP3JpQ==",
|
||||
"requires": {
|
||||
"printable-characters": "^1.0.42"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
@ -1134,6 +1156,11 @@
|
||||
"renderkid": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"printable-characters": {
|
||||
"version": "1.0.42",
|
||||
"resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz",
|
||||
"integrity": "sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ=="
|
||||
},
|
||||
"process-warning": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-2.0.0.tgz",
|
||||
|
@ -11,6 +11,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"as-table": "^1.0.55",
|
||||
"axios": "^0.27.2",
|
||||
"chalk": "^5.0.1",
|
||||
"commander": "^9.4.0",
|
||||
|
26
src/commands/list_command.ts
Normal file
26
src/commands/list_command.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import Subcommand from "./subcommand.js";
|
||||
import {Command} from "commander";
|
||||
import ModManager from "../mod-manager.js";
|
||||
import asTable from "as-table";
|
||||
import Mods from "../mods/mods.js";
|
||||
import PrintUtils from "../util/print_utils.js";
|
||||
import chalk from "chalk";
|
||||
import Util from "../util/util.js";
|
||||
|
||||
export class ListCommand implements Subcommand {
|
||||
registerCommand(program: Command): void {
|
||||
program.command("list")
|
||||
.description("Lists installed mods")
|
||||
.action(() => {
|
||||
ModManager.execute(() => {
|
||||
let tableFunc = asTable.configure ({
|
||||
title: x => chalk.cyanBright(Util.stringPrettyify(x)),
|
||||
delimiter: chalk.blueBright(' | '),
|
||||
dash: chalk.blueBright('-')
|
||||
})
|
||||
PrintUtils.info(tableFunc(Mods.getTrackedMods()))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import Initialiser from "./util/initialiser.js";
|
||||
import PrintUtils from "./util/print_utils.js";
|
||||
import path from "path";
|
||||
import {Logger, pino} from "pino"
|
||||
import {ListCommand} from "./commands/list_command.js";
|
||||
|
||||
|
||||
export default class ModManager {
|
||||
@ -17,7 +18,8 @@ export default class ModManager {
|
||||
|
||||
private static subcommands: Array<Subcommand> = [
|
||||
new InitCommand(),
|
||||
new InstallCommand()
|
||||
new InstallCommand(),
|
||||
new ListCommand()
|
||||
];
|
||||
|
||||
static init() {
|
||||
|
@ -171,6 +171,70 @@ export default class ModrinthSource implements ModSource {
|
||||
return "Modrinth";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the project with the provided id
|
||||
* Example Shape of data from the query:
|
||||
* {
|
||||
* "id": "gvQqBUqZ",
|
||||
* "slug": "lithium",
|
||||
* "project_type": "mod",
|
||||
* "team": "peSx5UYg",
|
||||
* "title": "Lithium",
|
||||
* "description": "No-compromises game logic/server optimization mod",
|
||||
* "body": "...",
|
||||
* "body_url": "https://cdn.modrinth.com/data/gvQqBUqZ/description.md",
|
||||
* "published": "2021-01-03T00:56:52.292581Z",
|
||||
* "updated": "2022-07-29T22:18:05.703354Z",
|
||||
* "approved": "2021-01-03T00:56:52.292581Z",
|
||||
* "status": "approved",
|
||||
* "moderator_message": null,
|
||||
* "license": {
|
||||
* "id": "lgpl-3",
|
||||
* "name": "GNU Lesser General Public License v3",
|
||||
* "url": "https://cdn.modrinth.com/licenses/lgpl-3.txt"
|
||||
* },
|
||||
* "client_side": "optional",
|
||||
* "server_side": "optional",
|
||||
* "downloads": 225038,
|
||||
* "followers": 1872,
|
||||
* "categories": [
|
||||
* "optimization"
|
||||
* ],
|
||||
* "additional_categories": [],
|
||||
* "versions": [
|
||||
* "2w527DB2",
|
||||
* "ZRR9yqHD",
|
||||
* "aZ0JFf08",
|
||||
* "cTZv31gu",
|
||||
* "igqdFUYG",
|
||||
* "nVR7Q63z",
|
||||
* "ouTdXXWj",
|
||||
* "pGhOMdTm",
|
||||
* "pHl1Vi6k",
|
||||
* "pXdccFQf",
|
||||
* "rvsW1zhb",
|
||||
* "sIKhU9s4",
|
||||
* "5fmGl08Y",
|
||||
* "7jxErppe",
|
||||
* "EhG1mQzx",
|
||||
* "Ehsd7YUl",
|
||||
* "FHFKMKeu",
|
||||
* "Le0tKjFX",
|
||||
* "2CbyxeU0",
|
||||
* "MoF1cn6g",
|
||||
* "2aoHIXuK"
|
||||
* ],
|
||||
* "icon_url": "https://cdn.modrinth.com/data/gvQqBUqZ/icon.png",
|
||||
* "issues_url": "https://github.com/jellysquid3/lithium-fabric/issues",
|
||||
* "source_url": "https://github.com/jellysquid3/lithium-fabric",
|
||||
* "wiki_url": null,
|
||||
* "discord_url": "https://jellysquid.me/discord",
|
||||
* "donation_urls": [],
|
||||
* "gallery": []
|
||||
* }
|
||||
* @param id the id to get the name of
|
||||
* @return The found project name
|
||||
*/
|
||||
async getProjectName(id: string): Promise<string> {
|
||||
const response = await axios.get(format(ModrinthSource.PROJECT_URL, id));
|
||||
return await response.data.title;
|
||||
|
@ -2,4 +2,11 @@ export default class Util {
|
||||
static isArrayEmpty(array: Array<any> | undefined): boolean {
|
||||
return array === undefined || array.length == 0;
|
||||
}
|
||||
|
||||
static stringPrettyify(str: string): string {
|
||||
return str // insert a space before all caps
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
// uppercase the first character
|
||||
.replace(/^./, function(str){ return str.toUpperCase(); })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user