Get Started with the Web Extensibility API
Introduction
Studio Pro extensions can be developed using TypeScript and use standard web development technologies to extend the Studio Pro development environment. This document describes how to set up a basic development environment for building an extension using the web extensibility API.
For more detailed information, see the Mendix Studio Pro Web Extensibility API reference documentation.
Prerequisites
You will need the following prerequisites:
- Mendix Studio Pro version 11.2.0 or higher.
- A development IDE to develop your extensions. Mendix recommends using Visual Studio Code.
- The latest version 22.x.x of Node: https://nodejs.org/en/download.
--enable-extension-development feature flag.
Creating Your First Extension
This section will show you how to build and test an extension.
Create a Test App
Create a new app using the Blank Web App template.
You can also open the application directory containing the application .mpr file by clicking the App menu > Show App Directory in Explorer (or Show App Directory in Finder) in Studio Pro.
Creating the Extension
To accelerate your extension development, Mendix provides an extension generator that creates a customizable sample extension.
To use the generator, navigate to your desired source code directory and run the command npm create @mendix/extension. You may be prompted by npm to grant permission to install the generator. After installation, you will be guided through a series of questions to help configure your extension.
You will be asked the following:
- Select the programming language (TypeScript is used in the tutorials)
- Specify the extension name
- Choose if you will use React for the extension’s UI
The next two questions, while optional, are highly recommended, as they enable direct debugging and deployment from Visual Studio Code:
- Specify the path to the Studio Pro executable (this allows Visual Studio Code to automatically attach to Studio Pro for debugging)
- Specify the location of the application
.mprpackage (this allows for automatic deployment of your extension build to your app)
The last question allows you to select the Studio Pro version you are targeting; Mendix recommends choosing version 11.
On a Windows machine, the Studio Pro executable is typically located at C:\Program Files\Mendix\<version>\modeler\studiopro.exe. To find the exact path, follow these steps:
- Launch Studio Pro.
- Right-click its taskbar icon, then right-click
Mendix Studio Pro 11.2.0(your version may differ). - Select Properties. The Target field displays the executable path.
Once you have completed the setup, a new directory named after your extension will be created, containing the source code of the extension.
Exploring the Created Extension
In the following example, the name of your extension is myextension and you are exploring it using Visual Studio Code.
Before you begin, your extension will have to get an instance of the Studio Pro API. to do this, from the Explorer window, navigate to src/main/index.ts and select it to open the file.
In the source code, you should see the following:
-
Line 6 gets an instance of the Studio Pro API by calling
getStudioProApi.export const component: IComponent = { async loaded(componentContext) { const studioPro = getStudioProApi(componentContext); -
Line 7 adds a menu:
await studioPro.ui.extensionsMenu.add({ menuId: "myextension.MainMenu", caption: "MyExtension Menu", subMenus: [ { menuId: "myextension.ShowMenu", caption: "Show tab" }, ], }); -
Line 16 opens a tab.
// Open a tab when the menu item is clicked studioPro.ui.extensionsMenu.addEventListener( "menuItemActivated", (args) => { if (args.menuId === "myextension.ShowMenu") { studioPro.ui.tabs.open( { title: "MyExtension Tab" }, { componentName: "extension/myextension", uiEntrypoint: "tab", } ); } } ); -
If you navigate to
build-extension.mjs, you can choose the directory to which the extension will be installed to after being built by changing line 6:const appDir = "C:\\TestApps\\AppTestExtensions" -
The file
.vscode\launch.jsonspecifies the launch configuration and enables debugging. The following lines specify how Studio Pro will be run:… "runtimeExecutable": "C:\\Program Files\\Mendix\\11.2.0\\modeler\\studiopro.exe", "runtimeArgs": ["C:\\TestApps\\AppTestExtensions\\AppTestExtensions.mpr", "--enable-extension-development", "--enable-web-extensions"], …
When you install the extension, you will see a new menu item within Studio Pro.
Building, Installing, and Debugging the Extension
The following steps occur within Visual Studio Code:
- Select File > Open Folder.
- Navigate to the folder where you created your extension.
- Click Select Folder.
- Select Yes if you are asked whether you trust this folder.
- Open a Terminal from the top menu by clicking Terminal > New Terminal.
- From the Terminal, type
npm install. This installs all dependencies for the extension. - Build your extension using the command
npm run buildin the terminal. If you provided the path to.mprfile in the previous step, this will install the extension into the application directory.
If the last two questions of the extension generator were answered and you have built and installed the extension, you can debug it by following the steps below:
- Open the extension source code in Visual Studio Code and set breakpoints.
- Select Run and Debug from the side panel.
- Click the play button on the top of the panel (or press F5).
This will run Studio Pro in extension development mode and open the configured application. You will see a new Extensions item in the top menu.
Extensibility Feedback
If you would like to provide additional feedback, you can complete a small survey.
Any feedback is appreciated.