Developing a new Zowe CLI plug-in
Developing a new Zowe CLI plug-in
Before you begin this tutorial, complete the Extending an existing plug-in tutorial.
Overview​
The advantage of Zowe CLI and of the CLI approach in mainframe development is that it allows for combining different developer tools for new and interesting uses.
This tutorial demonstrates how to create a brand new Zowe CLI plug-in that uses Node.js to create a client-side API.
After following all the steps, you will have created a data set diff utility plug-in called Files Util Plug-in. This plug-in takes in any two data sets, or files, and returns a plain text output in the terminal showing how they differ. This tutorial will also show you how you can integrate your new plug-in with a third-party utility to make your output colorful and easier to read, as shown in the image at the bottom of this page.
If you are ready to create your own unique Zowe CLI plug-in, refer to the notes at the end of each tutorial step for guidance.
If you are interested in creating a credential manager plug-in, see the Zowe CLI secrets for kubernetes plug-in repository.
Setting up the new sample plug-in project​
Download the sample plug-in source and delete the irrelevant content to set up your plug-in project.
Follow these steps:
-
Open a terminal and run the command
mkdir zowe-tutorial
.Note: All the files created through this tutorial are saved in this tutorial directory.
-
Enter
cd zowe-tutorial
to change directory into yourzowe-tutorial
folder. -
Download the source code zip file from the Zowe CLI sample plug-in repository.
-
In your File Explorer, extract the zip file to the
zowe-tutorial
folder. -
Rename the
zowe-cli-sample-plugin-master
directory tofiles-util
.This is the project directory used throughout the rest of this tutorial.
-
Delete all content within the following folders:
src/api
src/cli
docs
folders__tests__/__system__/api
__tests__/__system__/cli
__tests__/api
__tests__/cli
-
Return to your terminal and run
cd files-util
to enter the project directory. -
Enter
git init
to set up a new Git repository. -
Enter
git add --all
to stage (track) all files in the current directory with Git. -
Enter
git commit --message "Initial commit"
to save a snapshot of the staged files in your repository. -
Run
npm install
to install third-party dependencies defined in thepackage.json
file of your Node.js project.When successful, a progress bar displays. Once the plug-in is installed, a message displays the status of the packages in the
node_modules
directory.Note: If vulnerabilities are found in any of the installed dependencies, refer to npm Docs for how to fix them.
To create a unique plug-in: Change the files-util
directory to a name applicable for your project.
Updating package.json
​
Change the name property in the package.json
file to the plug-in name.
Open the package.json
file in a text editor and replace the name field with the following information:
"name": "@zowe/files-util",
This tutorial uses @zowe/files-util
as the tutorial plug-in name.
To create a unique plug-in: Replace @zowe/files-util
with a unique plug-in name. This allows you to publish the plug-in under that name to the npm
registry in the future. For information regarding npm scoping, see the npm documentation.
Adjusting Imperative CLI Framework configuration​
Define json configurations for the plug-in to Imperative.
Change the src/imperative.ts
file to contain the following configurations:
import { IImperativeConfig } from "@zowe/imperative";
const config: IImperativeConfig = {
commandModuleGlobs: ["**/cli/*/*.definition!(.d).*s"],
rootCommandDescription: "Files utility plugin for Zowe CLI",
productDisplayName: "Files Util Plugin",
name: "files-util"
};
export = config;
When successful, the src/imperative.ts
file contains the new configurations.
To create a unique plug-in: Change the plug-in name, display name, and description according to your project.