typescriptcommand-line-interfaceoclif

Install Local Plugin


I generated a multi-command CLI using npx oclif multi mynewcli. I'm trying to install the default plugin created using npx oclif plugin mynewplugin as referenced here. I don't know see any documentation on how to actually do that though. Is there documentation I'm missing? How does the CLI know where to look for included plugins?


Solution

  • After you have executed the two commands npx oclif multi mynewcli and npx oclif plugin mynewplugin is some directory for example in this case the projects directory, your directories will be structured like this

    projects
    |--- mynewcli
    |--- mynewplugin
    

    cd into the mynewcli project and

    1. install the plugins installer with npm i @oclif/plugin-plugins --save

    2. add this plugin into package.json in oclif.plugins array

      {
        "name": "mynewcli",
        "version": "0.0.0",
        // ...
        "oclif": {
           "plugins": [
               "@oclif/plugin-help", 
               "@oclif/plugin-plugins" // <== in here
           ]
        }
      }
      
    3. run ./bin/run plugins:link ../mynewplugin to link the plugin into your main project

    4. run ./bin/run plugins you will see your mynewplugin was added into your project