diff --git a/bin/commonPlugins.ts b/bin/commonPlugins.ts new file mode 100644 index 000000000..7fc5fc1ad --- /dev/null +++ b/bin/commonPlugins.ts @@ -0,0 +1,17 @@ +import {PackageData} from "ep_etherpad-lite/node/types/PackageInfo"; +import {writeFileSync} from "fs"; +import {installedPluginsPath} from "ep_etherpad-lite/static/js/pluginfw/installer"; +const pluginsModule = require('ep_etherpad-lite/static/js/pluginfw/plugins'); + +export const persistInstalledPlugins = async () => { + const plugins:PackageData[] = [] + const installedPlugins = {plugins: plugins}; + for (const pkg of Object.values(await pluginsModule.getPackages()) as PackageData[]) { + installedPlugins.plugins.push({ + name: pkg.name, + version: pkg.version, + }); + } + installedPlugins.plugins = [...new Set(installedPlugins.plugins)]; + writeFileSync(installedPluginsPath, JSON.stringify(installedPlugins)); +}; diff --git a/bin/installPlugins.ts b/bin/installPlugins.ts deleted file mode 100644 index 85ae0b6b4..000000000 --- a/bin/installPlugins.ts +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -import {writeFileSync} from 'fs' -import {linkInstaller, installedPluginsPath} from "ep_etherpad-lite/static/js/pluginfw/installer"; -import {PackageData} from "ep_etherpad-lite/node/types/PackageInfo"; - -const pluginsModule = require('ep_etherpad-lite/static/js/pluginfw/plugins'); -if (process.argv.length === 2) { - console.error('Expected at least one argument!'); - process.exit(1); -} - -let args = process.argv.slice(2) - -let registryPlugins: string[] = []; -let localPlugins: string[] = []; - -if (args.indexOf('--path') !== -1) { - const indexToSplit = args.indexOf('--path'); - registryPlugins = args.slice(0, indexToSplit); - localPlugins = args.slice(indexToSplit + 1); -} else { - registryPlugins = args; -} - -const persistInstalledPlugins = async () => { - const plugins:PackageData[] = [] - const installedPlugins = {plugins: plugins}; - for (const pkg of Object.values(await pluginsModule.getPackages()) as PackageData[]) { - installedPlugins.plugins.push({ - name: pkg.name, - version: pkg.version, - }); - } - installedPlugins.plugins = [...new Set(installedPlugins.plugins)]; - writeFileSync(installedPluginsPath, JSON.stringify(installedPlugins)); -}; - -async function run() { - for (const plugin of registryPlugins) { - console.log(`Installing plugin from registry: ${plugin}`) - if (plugin.includes('@')) { - const [name, version] = plugin.split('@'); - await linkInstaller.installPlugin(name, version); - continue; - } - await linkInstaller.installPlugin(plugin); - } - - for (const plugin of localPlugins) { - console.log(`Installing plugin from path: ${plugin}`); - await linkInstaller.installFromPath(plugin); - } -} - -(async () => { - await run(); - await persistInstalledPlugins(); -})(); diff --git a/bin/package.json b/bin/package.json index 36ad07b47..d30664f4c 100644 --- a/bin/package.json +++ b/bin/package.json @@ -32,7 +32,7 @@ "rebuildPad": "node --import tsx rebuildPad.ts", "stalePlugins": "node --import tsx ./plugins/stalePlugins.ts", "checkPlugin": "node --import tsx ./plugins/checkPlugin.ts", - "install-plugins": "node --import tsx ./installPlugins.ts" + "plugins": "node --import tsx ./plugins.ts" }, "author": "", "license": "ISC" diff --git a/bin/plugins.ts b/bin/plugins.ts new file mode 100644 index 000000000..1b9d2d446 --- /dev/null +++ b/bin/plugins.ts @@ -0,0 +1,106 @@ +'use strict'; + +import {linkInstaller} from "ep_etherpad-lite/static/js/pluginfw/installer"; +import {persistInstalledPlugins} from "./commonPlugins"; +import fs from "node:fs"; +const settings = require('ep_etherpad-lite/node/utils/Settings'); + +if (process.argv.length === 2) { + console.error('Expected at least one argument!'); + process.exit(1); +} + +let args = process.argv.slice(2) + +// 3d arg is ls, install or rm +let action = args[0]; + + + + +const install = ()=> { + + let registryPlugins: string[] = []; + let localPlugins: string[] = []; + + if (args.indexOf('--path') !== -1) { + const indexToSplit = args.indexOf('--path'); + registryPlugins = args.slice(1, indexToSplit); + localPlugins = args.slice(indexToSplit + 1); + } else { + registryPlugins = args; + } + + async function run() { + for (const plugin of registryPlugins) { + console.log(`Installing plugin from registry: ${plugin}`) + if (plugin.includes('@')) { + const [name, version] = plugin.split('@'); + await linkInstaller.installPlugin(name, version); + continue; + } + await linkInstaller.installPlugin(plugin); + } + + for (const plugin of localPlugins) { + console.log(`Installing plugin from path: ${plugin}`); + await linkInstaller.installFromPath(plugin); + } + } + + (async () => { + await run(); + await persistInstalledPlugins(); + })(); +} + +const list = ()=>{ + const walk = async () => { + const plugins = fs.readFileSync(settings.root+"/var/installed_plugins.json", "utf-8") + const pluginNames = JSON.parse(plugins).plugins.map((plugin: any) => plugin.name).join(", ") + + console.log("Installed plugins are:", pluginNames) + } + + (async () => { + await walk(); + })(); +} + +const remove = (plugins: string[])=>{ + const walk = async () => { + for (const plugin of plugins) { + console.log(`Uninstalling plugin: ${plugin}`) + await linkInstaller.uninstallPlugin(plugin); + } + await persistInstalledPlugins(); + } + + (async () => { + await walk(); + })(); +} + + +switch (action) { + case "install": + install(); + break; + case "i": + install(); + break; + case "ls": + list(); + break; + case "list": + list(); + break; + case "rm": + remove(args.slice(1)); + break; + default: + console.error('Expected at least one argument!'); + process.exit(1); +} + + diff --git a/package.json b/package.json index 5c7354b2e..7588eed27 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "test-ui:ui": "pnpm --filter ep_etherpad-lite run test-ui:ui", "test-admin": "pnpm --filter ep_etherpad-lite run test-admin", "test-admin:ui": "pnpm --filter ep_etherpad-lite run test-admin:ui", - "install-plugins": "pnpm --filter bin run install-plugins" + "install-plugins": "pnpm --filter bin run install-plugins", + "remove-plugins": "pnpm --filter bin run remove-plugins", + "list-plugins": "pnpm --filter bin run list-plugins" }, "dependencies": { "ep_etherpad-lite": "workspace:./src"