hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/cli/app.js
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-12-09 23:02:55 +0100
committerhachem <im@hachem.wtf>2025-12-09 23:02:55 +0100
commit5cc4c5a689e124e3951c80f0cfda0de4a797fec7 (patch)
tree7cb412c67f54636a4926161f4c948b68d87e74e8 /cli/app.js
parent50e62e246fef7975866c244e08ead7c681d50349 (diff)
[add]: merging and refactor
Diffstat (limited to 'cli/app.js')
-rw-r--r--cli/app.js138
1 files changed, 138 insertions, 0 deletions
diff --git a/cli/app.js b/cli/app.js
new file mode 100644
index 0000000..1252358
--- /dev/null
+++ b/cli/app.js
@@ -0,0 +1,138 @@
+#!/usr/bin/env node
+
+const readline = require("readline")
+
+const { LoadConfig } = require("../lib/config")
+
+const { Check } = require("./commands/check")
+const { Generate } = require("./commands/generate")
+const { Merge } = require("./commands/merge")
+const { CleanGenerated, CleanLatest, CleanAll } = require("./commands/clean")
+const { ListMods } = require("./commands/list")
+
+const pkg = require("../package.json")
+const config = LoadConfig()
+const { minecraft_version } = config
+
+const ShowHelp = () =>
+{
+ console.log(`
+ Commands:
+
+ list-mods List configured mods
+ check Check if all mods are compatible before generating
+ generate Download mods + server, run to generate files
+ merge Backup server, move generated files to server location
+ clean generated Remove server directory
+ clean latest Remove latest backup zip
+ clean all Remove both generated and latest backup
+ help Show this help
+ exit Exit
+`)
+}
+
+const ProcessCommand = async (input, rl) =>
+{
+ const parts = input.trim().toLowerCase().split(/\s+/)
+ const cmd = parts[0]
+ const arg = parts[1]
+
+ switch (cmd)
+ {
+ case "list-mods":
+ ListMods()
+ break
+
+ case "check":
+ await Check()
+ break
+
+ case "generate":
+ await Generate(rl)
+ break
+
+ case "merge":
+ await Merge()
+ break
+
+ case "clean":
+ if (arg === "generated")
+ await CleanGenerated()
+ else if (arg === "latest")
+ await CleanLatest()
+ else if (arg === "all")
+ await CleanAll()
+ else
+ console.log(" Usage: clean generated | clean latest | clean all")
+ break
+
+ case "help":
+ case "?":
+ ShowHelp()
+ break
+
+ case "exit":
+ case "quit":
+ case "q":
+ console.log(" Goodbye!\n")
+ process.exit(0)
+
+ case "":
+ break
+
+ default:
+ console.log(` Unknown command: ${cmd}. Type 'help' for commands.`)
+ }
+}
+
+const DrawBox = (lines) =>
+{
+ const maxLen = Math.max(...lines.map(l => l.length))
+ const pad = (str) => str + " ".repeat(maxLen - str.length)
+
+ const top = "╔" + "═".repeat(maxLen + 2) + "╗"
+ const bot = "╚" + "═".repeat(maxLen + 2) + "╝"
+ const mid = lines.map(l => "║ " + pad(l) + " ║").join("\n ")
+
+ return ` ${top}\n ${mid}\n ${bot}`
+}
+
+const Main = () =>
+{
+ const title = `BENSON CLI v${pkg.version}`
+ const subtitle = `Fabric Server for MC ${minecraft_version}`
+
+ const box = DrawBox([title, subtitle])
+
+ console.log(`
+${box}
+
+ Type 'help' for commands.
+`)
+
+ const rl = readline.createInterface
+ ({
+ input: process.stdin,
+ output: process.stdout
+ })
+
+ const Prompt = () =>
+ {
+ rl.question("benson> ", async (input) =>
+ {
+ await ProcessCommand(input, rl)
+ Prompt()
+ })
+ }
+
+ rl.on("close", () =>
+ {
+ console.log("\n Goodbye!\n")
+ process.exit(0)
+ })
+
+ Prompt()
+}
+
+Main()
+