From 36f6e1e51d0d288a360dd19a1d137e950c56ec4e Mon Sep 17 00:00:00 2001 From: Ando Date: Sun, 20 Oct 2024 21:55:03 +0300 Subject: [PATCH] feat: update rtx to be mise plugin --- plugins/mise.ts | 121 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/mod.ts | 4 +- plugins/rtx.ts | 122 ------------------------------------------------ 3 files changed, 123 insertions(+), 124 deletions(-) create mode 100644 plugins/mise.ts delete mode 100644 plugins/rtx.ts diff --git a/plugins/mise.ts b/plugins/mise.ts new file mode 100644 index 0000000..6052ea1 --- /dev/null +++ b/plugins/mise.ts @@ -0,0 +1,121 @@ +import { evaluateSystemCommand, spawn } from "../src/helpers.ts"; +import Plugin from "../src/plugin.ts"; + +class Mise implements Plugin { + name = "mise"; + commands: Record Promise>; + + constructor() { + const mise = (args: string[]) => [ + "-c", + `eval "$(~/.local/bin/mise activate bash)" && ~/.local/bin/mise ${args.join( + " " + )}`, + ]; + this.commands = { + alias: (args: string[]) => spawn("bash", mise(["alias", ...args])), + "bin-paths": (args: string[]) => + spawn("bash", mise(["bin-paths", ...args])), + cache: (args: string[]) => spawn("bash", mise(["cache", ...args])), + completion: (args: string[]) => + spawn("bash", mise(["completion", ...args])), + current: (args: string[]) => spawn("bash", mise(["current", ...args])), + direnv: (args: string[]) => spawn("bash", mise(["direnv", ...args])), + doctor: (args: string[]) => spawn("bash", mise(["doctor", ...args])), + env: (args: string[]) => spawn("bash", mise(["env", ...args])), + "env-vars": (args: string[]) => + spawn("bash", mise(["env-vars", ...args])), + exec: (args: string[]) => spawn("bash", mise(["exec", ...args])), + implode: (args: string[]) => spawn("bash", mise(["implode", ...args])), + install: (args: string[]) => spawn("bash", mise(["install", ...args])), + latest: (args: string[]) => spawn("bash", mise(["latest", ...args])), + link: (args: string[]) => spawn("bash", mise(["link", ...args])), + ls: (args: string[]) => spawn("bash", mise(["ls", ...args])), + "ls-remote": (args: string[]) => + spawn("bash", mise(["ls-remote", ...args])), + outdated: (args: string[]) => spawn("bash", mise(["outdated", ...args])), + plugins: (args: string[]) => spawn("bash", mise(["plugins", ...args])), + prune: (args: string[]) => spawn("bash", mise(["prune", ...args])), + reshim: (args: string[]) => spawn("bash", mise(["reshim", ...args])), + "self-update": (args: string[]) => + spawn("bash", mise(["self-update", ...args])), + settings: (args: string[]) => spawn("bash", mise(["settings", ...args])), + sync: (args: string[]) => spawn("bash", mise(["sync", ...args])), + trust: (args: string[]) => spawn("bash", mise(["trust", ...args])), + uninstall: (args: string[]) => + spawn("bash", mise(["uninstall", ...args])), + upgrade: (args: string[]) => spawn("bash", mise(["upgrade", ...args])), + u: (args: string[]) => spawn("bash", mise(["use", ...args])), + version: (args: string[]) => spawn("bash", mise(["version", ...args])), + where: (args: string[]) => spawn("bash", mise(["where", ...args])), + which: (args: string[]) => spawn("bash", mise(["which", ...args])), + node: (args: string[]) => spawn("bash", mise(["node", ...args])), + x: (args: string[]) => spawn("bash", mise(["exec", ...args])), + help: () => { + console.log(` + Commands: + alias Manage aliases [aliases: a] + bin-paths List all the active runtime bin paths + cache Manage the mise cache + completion Generate shell completions + current Shows current active and installed runtime versions + direnv Output direnv function to use mise inside direnv + doctor Check mise installation for possible problems. + env Exports env vars to activate mise a single time [aliases: e] + env-vars Manage environment variables + exec Execute a command with tool(s) set [aliases: x] + implode Removes mise CLI and all related data + install Install a tool version [aliases: i] + latest Gets the latest available version for a plugin + link Symlinks a tool version into mise + ls List installed and/or currently selected tool versions [aliases: list] + ls-remote List runtime versions available for install + outdated [experimental] Shows outdated tool versions + plugins Manage plugins [aliases: p] + prune Delete unused versions of tools + reshim rebuilds the shim farm + self-update Updates mise itself + settings Manage settings + sync Add tool versions from external tools to mise + trust Marks a config file as trusted + uninstall Removes runtime versions + upgrade [experimental] Upgrades outdated tool versions + u Change the active version of a tool locally or globally. [aliases: u] + version Show mise version + where Display the installation path for a runtime + which Shows the path that a bin name points to + node Commands for the node plugin + help Print this message or the help of the given subcommand(s)`); + return Promise.resolve(); + }, + }; + } + + async evaluate(command: string): Promise { + const [cmd, ...params] = command.split(" "); + if (this.commands[cmd]) { + await this.commands[cmd](params); + return; + } + if (cmd === "") { + return; + } + await evaluateSystemCommand(command); + } + + async install(): Promise { + const HOME = Deno.env.get("HOME"); + const mise = `${HOME}/.local/bin`; + Deno.env.set("PATH", `${Deno.env.get("PATH")}:${mise}`); + Deno.env.set( + "PATH", + `${Deno.env.get("PATH")}:${HOME}/.local/share/mise/shims` + ); + await spawn("sh", [ + "-c", + "type ~/.local/bin/mise > /dev/null || curl https://mise.run | sh", + ]); + } +} + +export default Mise; diff --git a/plugins/mod.ts b/plugins/mod.ts index fc7d47d..7f3a84b 100644 --- a/plugins/mod.ts +++ b/plugins/mod.ts @@ -33,7 +33,7 @@ import Turso from "./turso.ts"; import Neon from "./neon.ts"; import Pscale from "./pscale.ts"; import Grunt from "./grunt.ts"; -import Rtx from "./rtx.ts"; +import Mise from "./mise.ts"; import Nx from "./nx.ts"; import Fluentci from "./fluentci.ts"; import GitlabCLI from "./gitlab-cli.ts"; @@ -75,7 +75,7 @@ export const plugins = [ new Neon(), new Pscale(), new Grunt(), - new Rtx(), + new Mise(), new Nx(), new Fluentci(), new GitlabCLI(), diff --git a/plugins/rtx.ts b/plugins/rtx.ts deleted file mode 100644 index 3bc6057..0000000 --- a/plugins/rtx.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { evaluateSystemCommand, spawn } from "../src/helpers.ts"; -import Plugin from "../src/plugin.ts"; - -class Rtx implements Plugin { - name = "rtx"; - commands: Record Promise>; - - constructor() { - const rtx = (args: string[]) => [ - "-c", - `eval "$(rtx activate bash)" && rtx ${args.join(" ")}`, - ]; - this.commands = { - alias: (args: string[]) => spawn("bash", rtx(["alias", ...args])), - "bin-paths": (args: string[]) => - spawn("bash", rtx(["bin-paths", ...args])), - cache: (args: string[]) => spawn("bash", rtx(["cache", ...args])), - completion: (args: string[]) => - spawn("bash", rtx(["completion", ...args])), - current: (args: string[]) => spawn("bash", rtx(["current", ...args])), - direnv: (args: string[]) => spawn("bash", rtx(["direnv", ...args])), - doctor: (args: string[]) => spawn("bash", rtx(["doctor", ...args])), - env: (args: string[]) => spawn("bash", rtx(["env", ...args])), - "env-vars": (args: string[]) => spawn("bash", rtx(["env-vars", ...args])), - exec: (args: string[]) => spawn("bash", rtx(["exec", ...args])), - implode: (args: string[]) => spawn("bash", rtx(["implode", ...args])), - install: (args: string[]) => spawn("bash", rtx(["install", ...args])), - latest: (args: string[]) => spawn("bash", rtx(["latest", ...args])), - link: (args: string[]) => spawn("bash", rtx(["link", ...args])), - ls: (args: string[]) => spawn("bash", rtx(["ls", ...args])), - "ls-remote": (args: string[]) => - spawn("bash", rtx(["ls-remote", ...args])), - outdated: (args: string[]) => spawn("bash", rtx(["outdated", ...args])), - plugins: (args: string[]) => spawn("bash", rtx(["plugins", ...args])), - prune: (args: string[]) => spawn("bash", rtx(["prune", ...args])), - reshim: (args: string[]) => spawn("bash", rtx(["reshim", ...args])), - "self-update": (args: string[]) => - spawn("bash", rtx(["self-update", ...args])), - settings: (args: string[]) => spawn("bash", rtx(["settings", ...args])), - sync: (args: string[]) => spawn("bash", rtx(["sync", ...args])), - trust: (args: string[]) => spawn("bash", rtx(["trust", ...args])), - uninstall: (args: string[]) => spawn("bash", rtx(["uninstall", ...args])), - upgrade: (args: string[]) => spawn("bash", rtx(["upgrade", ...args])), - u: (args: string[]) => spawn("bash", rtx(["use", ...args])), - version: (args: string[]) => spawn("bash", rtx(["version", ...args])), - where: (args: string[]) => spawn("bash", rtx(["where", ...args])), - which: (args: string[]) => spawn("bash", rtx(["which", ...args])), - node: (args: string[]) => spawn("bash", rtx(["node", ...args])), - x: (args: string[]) => spawn("bash", rtx(["exec", ...args])), - help: () => { - console.log(` - Commands: - alias Manage aliases [aliases: a] - bin-paths List all the active runtime bin paths - cache Manage the rtx cache - completion Generate shell completions - current Shows current active and installed runtime versions - direnv Output direnv function to use rtx inside direnv - doctor Check rtx installation for possible problems. - env Exports env vars to activate rtx a single time [aliases: e] - env-vars Manage environment variables - exec Execute a command with tool(s) set [aliases: x] - implode Removes rtx CLI and all related data - install Install a tool version [aliases: i] - latest Gets the latest available version for a plugin - link Symlinks a tool version into rtx - ls List installed and/or currently selected tool versions [aliases: list] - ls-remote List runtime versions available for install - outdated [experimental] Shows outdated tool versions - plugins Manage plugins [aliases: p] - prune Delete unused versions of tools - reshim rebuilds the shim farm - self-update Updates rtx itself - settings Manage settings - sync Add tool versions from external tools to rtx - trust Marks a config file as trusted - uninstall Removes runtime versions - upgrade [experimental] Upgrades outdated tool versions - u Change the active version of a tool locally or globally. [aliases: u] - version Show rtx version - where Display the installation path for a runtime - which Shows the path that a bin name points to - node Commands for the node plugin - help Print this message or the help of the given subcommand(s)`); - return Promise.resolve(); - }, - }; - } - - async evaluate(command: string): Promise { - const [cmd, ...params] = command.split(" "); - if (this.commands[cmd]) { - await this.commands[cmd](params); - return; - } - if (cmd === "") { - return; - } - await evaluateSystemCommand(command); - } - - async install(): Promise { - const HOME = Deno.env.get("HOME"); - const RTX = `${HOME}/.local/share/rtx/bin`; - Deno.env.set("PATH", `${Deno.env.get("PATH")}:${RTX}`); - Deno.env.set( - "PATH", - `${Deno.env.get("PATH")}:${HOME}/.local/share/rtx/shims` - ); - await spawn("sh", [ - "-c", - "type rtx > /dev/null || (type apt && sudo apt install libssl-dev -y)", - ]); - await spawn("sh", [ - "-c", - "type rtx > /dev/null || curl https://rtx.pub/install.sh | sh", - ]); - await spawn("sh", ["-c", "mkdir -p ~/.local/share/rtx/shims"]); - } -} - -export default Rtx;