diff --git a/packages/contentstack/src/hooks/init/opt-in-plugin-guide.ts b/packages/contentstack/src/hooks/init/opt-in-plugin-guide.ts index 8653eaf390..5626f98e87 100644 --- a/packages/contentstack/src/hooks/init/opt-in-plugin-guide.ts +++ b/packages/contentstack/src/hooks/init/opt-in-plugin-guide.ts @@ -3,11 +3,21 @@ import { cliux } from '@contentstack/cli-utilities'; /** * Commands whose plugins used to ship bundled with the CLI but are now opt-in. - * Keyed by oclif topic (the segment before the first `:` in a command id). + * + * `match` tests the full command id rather than just the oclif topic (the segment + * before the first `:`) because not every demoted plugin owns its topic: launch's + * commands all share the `launch` topic, but migrate-rte's only command is + * `cm:entries:migrate-html-rte` — topic `cm`, which is also used by dozens of + * unrelated commands (`cm:stacks:export`, etc.), so it can't be keyed by topic. */ -const DEMOTED_PLUGINS: Record = { - launch: '@contentstack/cli-launch', -}; +const DEMOTED_PLUGINS: Array<{ match: (id: string) => boolean; label: string; pluginName: string }> = [ + { match: (id) => id.split(':')[0] === 'launch', label: 'launch', pluginName: '@contentstack/cli-launch' }, + { + match: (id) => id === 'cm:entries:migrate-html-rte', + label: 'cm:entries:migrate-html-rte', + pluginName: '@contentstack/cli-cm-migrate-rte', + }, +]; /** * When a user runs a command belonging to a demoted (now opt-in) plugin that @@ -18,18 +28,19 @@ const DEMOTED_PLUGINS: Record = { const hook: Hook<'init'> = async function (opts): Promise { if (!opts.id) return; - const topic = opts.id.split(':')[0]; - const pluginName = DEMOTED_PLUGINS[topic]; - if (!pluginName) return; + const demoted = DEMOTED_PLUGINS.find(({ match }) => match(opts.id as string)); + if (!demoted) return; + + const { label, pluginName } = demoted; // If the plugin is already installed, let normal command resolution proceed. if (this.config.plugins.has(pluginName)) return; cliux.print( - `\nWarning: "${topic}" is now an opt-in plugin and is not installed, so "${topic}:*" commands are unavailable.`, + `\nWarning: "${label}" is now an opt-in plugin and is not installed, so this command is unavailable.`, { color: 'yellow' }, ); - cliux.print('\nInstall it to enable these commands:', { color: 'yellow' }); + cliux.print('\nInstall it to enable this command:', { color: 'yellow' }); cliux.print(` csdx plugins:install ${pluginName}\n`, { color: 'green' }); this.exit(127);