1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/docs/extensions/guides/generator.md
chh b94e523ad5
Add documentation on how to use Lens Extension Generator (#1411)
* Add generator docs

Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>

* 'Welcome' > 'You are welcome to ...'

Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>

* Add missing backslash

Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>

* Move Generator section to Extension Guides

Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>
2020-11-24 16:38:43 +02:00

2.1 KiB

New Extension Project with Generator

The Lens Extension Generator scaffolds a project ready for development. Install Yeoman and Lens Extension Generator with:

npm install -g yo generator-lens-ext

Run the generator and fill out a few fields for a TypeScript project:

yo lens-ext
# ? What type of extension do you want to create? New Extension (TypeScript)
# ? What's the name of your extension? my-first-lens-ext
# ? What's the description of your extension? My hello world extension
# ? What's your extension's publisher name? @my-org/my-first-lens-ext
# ? Initialize a git repository? Yes
# ? Install dependencies after initialization? Yes
# ? Which package manager to use? yarn
# ? symlink created extension folder to ~/.k8slens/extensions (mac/linux) or :User
s\<user>\.k8slens\extensions (windows)? Yes

Start webpack, which watches the my-first-lens-ext folder.

cd my-first-lens-ext
npm start # start the webpack server in watch mode

Then, open Lens, you should see a Hello World item in the menu:

Hello World

Developing the Extension

Try to change my-first-lens-ext/renderer.tsx to "Hello Lens!":

clusterPageMenus = [
    {
        target: { pageId: "hello" },
        title: "Hello Lens",
        components: {
            Icon: ExampleIcon,
        }
    }
]

Then, Reload Lens by CMD+R (Mac) / Ctrl+R (Linux/Windows), you should see the menu item text changes:

Hello World

Debugging the Extension

Testing

Next steps

You can take a closer look at Common Capabilities of extension, how to style the extension. Or the Extension Anatomy.

You are welcome to raise an issue for Lens Extension Generator, if you find problems, or have feature requests.

The source code of the generator is hosted at Github