Introduction
In this tutorial, we will create a basic marketplace plugin using the carphacom-cli tool. The goal is to complete this task within 60 minutes, and we will guide you through the process of scaffolding, writing a hook, adding a settings page, packaging, smoke-testing, and publishing your plugin.
Scaffolding the Plugin
To start, you need to have the carphacom-cli tool installed on your system. Once installed, you can use the carphacom create plugin command to scaffold your plugin. This will create a basic directory structure and files for your plugin.
carphacom create plugin my-marketplace-pluginThis command will create a new directory called my-marketplace-plugin with the basic files and structure for your plugin.
Writing a Hook
A hook is a function that is executed at a specific point in the application's lifecycle. For this example, we will create a hook that will be executed when a product is added to the marketplace. Create a new file called hooks.js in the my-marketplace-plugin directory and add the following code:
export function onProductAdd(product) {
console.log('Product added:', product);
}This hook simply logs a message to the console when a product is added.
Adding a Settings Page
To add a settings page for your plugin, you need to create a new file called settings.js in the my-marketplace-plugin directory. Add the following code to this file:
export function getSettings() {
return [
{
label: 'Marketplace Settings',
description: 'Configure your marketplace settings',
fields: [
{
label: 'Marketplace Name',
name: 'marketplaceName',
type: 'text'
}
]
}
];
}This code defines a settings page with a single field for the marketplace name.
Packaging the Plugin
To package your plugin, you need to run the carphacom package command in the my-marketplace-plugin directory. This will create a zip file containing your plugin.
carphacom packageThis command will create a new file called my-marketplace-plugin.zip in the current directory.
Smoke-Testing the Plugin
To smoke-test your plugin, you need to install it on a test instance of the marketplace and verify that it works as expected. You can do this by running the carphacom install command and then verifying that the hook and settings page are working correctly.
carphacom install my-marketplace-plugin.zipThis command will install your plugin on the test instance of the marketplace.
Publishing the Plugin
Once you have smoke-tested your plugin and verified that it works correctly, you can publish it to the plugin repository. To do this, you need to run the carphacom publish command and follow the prompts to upload your plugin.
carphacom publish my-marketplace-plugin.zipThis command will upload your plugin to the plugin repository, where it can be installed by other users.
Rough Edges
While the carphacom-cli tool provides a lot of functionality out of the box, there are still some rough edges that need to be smoothed out. For example, the tool does not currently support automatic generation of plugin documentation, and the packaging process can be slow for large plugins. However, the carphacom team is actively working on addressing these issues and improving the overall developer experience.
Conclusion
In this tutorial, we have created a basic marketplace plugin using the carphacom-cli tool. We have scaffolded the plugin, written a hook, added a settings page, packaged the plugin, smoke-tested it, and published it to the plugin repository. While there are still some rough edges to be smoothed out, the carphacom-cli tool provides a powerful and flexible way to build and distribute plugins for the marketplace.
Bottom line
The carphacom-cli tool provides a fast and easy way to build and distribute plugins for the marketplace, but it is still a developing technology with some rough edges that need to be addressed.
QubitPage Editorial
Editorial — QubitPage SRL