diff --git a/manifest.yml b/manifest.yml index b947704..3ac1967 100644 --- a/manifest.yml +++ b/manifest.yml @@ -2,15 +2,17 @@ _version: '20220212062110' plugins: echo: - remote: '/home/daniel/code/pluggable-cli/plugins/echo' + remote: 'https://git.lyte.dev/lytedev/echo.git' run: '{plugin_dir}/echo.sh' - # preInstallCommand: - # installCommand: git clone $remote + # this is the default installCommand, so we don't really need to specify it + installCommand: ['git', 'clone', '{remote}', '{plugin_dir}'] + # none of these work, but wouldn't be tough to implement if needed + # preInstallCommand: # may also want to checkout a provided version tag and copy contents # and only clone to a "plugin-repos" dir # might want to omit git history, too? # postInstallCommand: shutup: - remote: '/home/daniel/code/pluggable-cli/plugins/shutup' + remote: 'https://git.lyte.dev/lytedev/shutup-cli-plugin.git' run: '{plugin_dir}/shutup.sh' diff --git a/src/core.ts b/src/core.ts index 6970097..e90ffa6 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,7 +1,7 @@ -import {yaml, fs, path} from "./deps.ts" +import {yaml, fs, path, xdg} from "./deps.ts" -const MANIFEST_URL = "file:///home/daniel/code/pluggable-cli/manifest.yml" -const PLUGINS_DIR = "/home/daniel/.home/.cache/installed-plugins" +const MANIFEST_URL = "https://git.lyte.dev/lytedev/pluggable-cli-deno/raw/branch/master/manifest.yml" +const PLUGINS_DIR = path.join(xdg.cache(), "/cli-poc-installed-plugins") fs.ensureDir(PLUGINS_DIR) @@ -25,6 +25,7 @@ async function usage() { console.info(" install-plugin ") console.info(" update-plugin ") console.info(" remove-plugin ") + console.info(" ensure-plugin ") console.info(" list-plugins") } @@ -46,16 +47,20 @@ async function installPlugin(pluginName: string) { console.error(`plugin ${pluginName} has no entry`) Deno.exit(1) } - const cmd = ["git", "clone", pluginManifestData.remote, pluginName] + const cmd = pluginManifestData.installCommand || ["git", "clone", pluginManifestData.remote, pluginName].map(segment => + segment + .replace('{remote}', pluginManifestData.remote) + .replace('{plugin_dir}', path.join(PLUGINS_DIR, pluginName)) + ) + const installCommand = Deno.run({ - cwd: PLUGINS_DIR, stdout: "piped", stderr: "piped", cmd }) const status = await installCommand.status() if (status.code != 0) { - console.error(`Installing plugin using command ${cmd} failed:\n${await installCommand.output()}\n${await installCommand.stderrOutput()}`) + console.error(`Installing plugin using command ${cmd} failed:\n${new TextDecoder().decode(await installCommand.output())}\n${new TextDecoder().decode(await installCommand.stderrOutput())}`) Deno.exit(status.code) } return installCommand @@ -71,11 +76,20 @@ async function updatePlugin(pluginName: string) { await installPlugin(pluginName) } +async function ensurePlugin(pluginName: string) { + if (manifest.plugins[subcommand].installed !== true) { + // console.warn(`Installing missing ${subcommand} plugin...`) + await installPlugin(subcommand) + } +} + const subcommand = Deno.args[0] if (Deno.args.includes("-h") || subcommand == "help" || subcommand == "" || Deno.args.includes("--help")) { usage() } else if (subcommand == "update-plugin") { await updatePlugin(Deno.args[1]) +} else if (subcommand == "ensure-plugin") { + ensurePlugin(subcommand) } else if (subcommand == "remove-plugin") { await deletePlugin(Deno.args[1]) } else if (subcommand == "install-plugin") { @@ -83,10 +97,7 @@ if (Deno.args.includes("-h") || subcommand == "help" || subcommand == "" || Deno } else if (subcommand == "list-plugins") { listPlugins() } else { - if (manifest.plugins[subcommand].installed !== true) { - // console.warn(`Installing missing ${subcommand} plugin...`) - await installPlugin(subcommand) - } + await ensurePlugin(subcommand) const subcommandCommand = Deno.run({ cmd: [manifest.plugins[subcommand].run.replace("{plugin_dir}", path.join(PLUGINS_DIR, subcommand))].concat(Deno.args.slice(1)) }) diff --git a/src/deps.ts b/src/deps.ts index b6e0be4..a2e33b6 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,4 +1,4 @@ -export * as xdg from 'https://deno.land/x/xdg@v9.4.0/src/mod.deno.ts'; +export {default as xdg} from 'https://deno.land/x/xdg@v9.4.0/src/mod.deno.ts'; export * as media_types from "https://deno.land/x/media_types@v2.12.1/mod.ts"; export * as compare_versions from "https://deno.land/x/compare_versions@0.4.0/mod.ts"; export * as yaml from "https://deno.land/std@0.125.0/encoding/yaml.ts"