Skip to content

Commit e86f92b

Browse files
Merge pull request #2656 from contentstack/fix/add-warning-for-launch
feat: warn and suggest install for opt-in launch commands
2 parents 3c9fbc0 + 51d0866 commit e86f92b

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

packages/contentstack/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@
156156
],
157157
"init": [
158158
"./lib/hooks/init/context-init",
159-
"./lib/hooks/init/utils-init"
159+
"./lib/hooks/init/utils-init",
160+
"./lib/hooks/init/opt-in-plugin-guide"
160161
]
161162
}
162163
},
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Hook } from '@oclif/core';
2+
import { cliux } from '@contentstack/cli-utilities';
3+
4+
/**
5+
* Commands whose plugins used to ship bundled with the CLI but are now opt-in.
6+
* Keyed by oclif topic (the segment before the first `:` in a command id).
7+
*/
8+
const DEMOTED_PLUGINS: Record<string, string> = {
9+
launch: '@contentstack/cli-launch',
10+
};
11+
12+
/**
13+
* When a user runs a command belonging to a demoted (now opt-in) plugin that
14+
* is not installed, warn them and point to the install command instead of
15+
* letting the generic "command not found" handler report it as a typo. Runs on
16+
* `init`, before command resolution, so it pre-empts `@oclif/plugin-not-found`.
17+
*/
18+
const hook: Hook<'init'> = async function (opts): Promise<void> {
19+
if (!opts.id) return;
20+
21+
const topic = opts.id.split(':')[0];
22+
const pluginName = DEMOTED_PLUGINS[topic];
23+
if (!pluginName) return;
24+
25+
// If the plugin is already installed, let normal command resolution proceed.
26+
if (this.config.plugins.has(pluginName)) return;
27+
28+
cliux.print(
29+
`\nWarning: "${topic}" is now an opt-in plugin and is not installed, so "${topic}:*" commands are unavailable.`,
30+
{ color: 'yellow' },
31+
);
32+
cliux.print('\nInstall it to enable these commands:', { color: 'yellow' });
33+
cliux.print(` csdx plugins:install ${pluginName}\n`, { color: 'green' });
34+
35+
this.exit(127);
36+
};
37+
38+
export default hook;

0 commit comments

Comments
 (0)