File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 },
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments