Reading time: 2 minutes and 45 seconds.
Developing action mods
Prerequisites
- You have read the getting started guide.
- You have created a new action mod template project.
- You have started a local development server and connected Spotfire to it.
Develop and test the mod
When the action mod project template has been created, there is a single script called my-script
whose source code is defined in src/scripts/my-script.ts
.
This script takes a single string argument and prints it to the console with an exclamation point appended.
For more information about the folder structure and the project, see the README.md file.
1. Test run your mod
-
In the Mods development tool, open the Test tab and click Test run. Select the script in the flyout that opens, click Next, provide a message in the text field, and click Run.
-
In the lower part of the Mods development tool, click Show script output. You should now see your message (followed by an exclamation point) printed.
2. Debug your mod
Action mods support interactive debugging in VS Code. This option is available in the installed client only.
-
To enable debugging, click Start debugging in the Mods development tool.
-
In VS Code, add a breakpoint at the start of the script and press F5 (or run “Debug: Start Debugging” command). This opens a prompt for the debug port (default to 9222), make sure that this is the same port shown the Mods development tool in Spotfire.
-
Run the script again. VS Code should now break at the breakpoint. You can inspect local variables and run JavaScript code using the debug tools provided by the editor.
3. Continue development
-
Change the code in
src/scripts/my-script.ts
to print something else, save the file, and then re-run the script. Any changes made to scripts are automatically picked up by Spotfire if you have your local servers running. -
Try adding a new script by running
npx @spotfire/mods-sdk add-script a-new-script
in a terminal. This will create a new file undersrc/scripts/a-new-script.ts
and update your mod manifest. Since adding a script changes the manifest you must reload it in the the Mods development tool by clicking the Reload manifest button. It is also possible to add script entries in the manifest together with the script file manually, without using theadd-script
command.
All metadata that concerns the mod is defined in the mod-manifest.json file. A list of the entries that are common to all mods can be found in the getting started guide. The entries that are specific to action mods are listed below:
Entry | Description |
---|---|
capabilities | Any extended capabilites required by the scripts. Currently supports LibraryRead and LibraryWrite . |
scripts | An array of the scripts in the action mod. |
For details, see the manifest schema.
What’s next?
-
Follow the tutorial to create a mod that loads data from the library, adds a visualization, and more.
-
Browse the snippets for inspiration on what you can do with the Spotfire API.
-
Explore the entire API in the API documentation.
-
Read the FAQ.