Create Backstage Plugin¶
Let's create a Backstage plugin!
Well, to be honest, this is quite trivial and there are greate guides out there.
So why am I writing this, yet again?
Because through writing it down I remember and understand it better.
Either way, my work is based upon, and inspired by:
Goal¶
The goal is to add the ability to say something about a Software Catalog entry.
We do this by having a Frontend component in the Catalog Item page (as a Tab) and a Backend component it can query.
And, ideally, this plugin is then also usable by Tanzu Developer Portal via its Wrapper APIs.
Steps¶
So, let's go over what we'll do:
- Ensure we have all the pre-requisites in place (e.g., Backstage codebase, NodeJS, and so on)
- Create a Backend plugin
- add it to Backstage
- build & publish it to NPMJS.org
- Create a Frontend plugin
- add it to Backstage
- build & publish it to NPMJS.org
Pre-requisites¶
Before we start, make sure you have the following ready/installed:
- An account on NPMJS.org, we'll publish the plugins here
- Get a copy of Backstage, so we can test our plugin(s)
- Do a Git checkout/clone of github.com/backstage/backstage or create a Fork
- Install Node Version Managager (NVM), not required though strongly recommended
- Install NodeJS, either download it from the source, or use NVM to install it for you (_recommended)
- Backstage generally supports NodeJS 16 and 18, while latest is 20?
- To install via NVM, run
nvm use 18
- Install NPM, even though Backstage uses Yarn, we still rely on NPM for some tasks (such as Publishing)
- Install Yarn, more on this below
- Install TypeScript, more on this below
Yarn Installation¶
Oke, this has become super confusing. So it helps to clarify a few things.
Yarn is an alternative NodeJS package manager/builder, as compared to NPM.
The "classical" Yarn, version 1 and 2, are installed standalone.
Beyond those versions, Yarn is installed via NodeJS. But, not via NodeJS directly, but via Corepack.
I do believe you can keep using the classic Yar (e.g., 1.x) if you don't really care.
If you do care about having the latest versions, the process is as follows:
- Ensure you have the latest version of NodeJS (that is compatible with Backstage)
- Enable Corepack (might have to install it first, see below)
- Switch Yarn to the
stable
version
This should get you the latest stable version of Yarn.
TypeScript Installation¶
The Backstage plugins are built via TypeScript.
While you can do every step along the way without TypeScript being involved, at the end of the line, your plugin won't work without it.
So, ensure you have TypeScript available, so commands like yarn tsc
work: