This guide provides a comprehensive overview of how to develop plugins for the enum-plus library. It covers the necessary steps, best practices, and examples to help you create plugins that enhance the functionality of enum-plus.
To get started with plugin development, you need to have a basic understanding of the enum-plus library and its core concepts. Familiarize yourself with the Documentation and explore the existing plugins to see how they are structured.
You need to assess the generality of the plugin to decide whether to maintain it in the official enum-plus repository or as an independent third-party plugin. If the functionality of the plugin meets the following criteria:
- Openness: Based on or targeting a public framework or technology, i.e., not a private technology of a specific company or organization
- Generality: Used by the majority of users who use this technology
- Relevance: Closely related to the concept of enumeration
Then it may be suitable for maintenance in the official repository, please continue reading the rest of this guide. Otherwise, it may be more suitable for independent maintenance as a third-party plugin.
For third-party plugins, you can refer to this guide or choose not to follow it, but please ensure the quality and clarity of the plugin documentation. Please publish the plugin to npm and share your plugin link here Awesome Plugins, so that more people can know about your plugin.
Official or third-party plugins are equally important to us, and we welcome any valuable plugins.
A typical enum-plus plugin consists of the following components.
You can refer to the plugin-sample for a complete example.
- Plugin Metadata: Information about the plugin, such as its name, version, and description. They are defined in the
package.jsonfile. - Core Functionality: The main logic of the plugin, which extends or modifies the behavior of enum-plus. They are implemented in the
srcdirectory. Please follow these guidelines:- Please develop the plugin using TypeScript.
- Write type declarations to extend the
EnumExtensiontype. Make sure the method declarations are consistent with the implementation. Remember that type declarations are just as important as the implementation. - The functionality should be clearly defined and focused on the intended purpose of the plugin. It should not include unrelated features. They should be implemented in a new plugin.
- Use meaningful names for functions and variables to enhance code readability.
- Ensure compatibility with the target version of enum-plus which is specified in the
peerDependenciesfield ofpackage.json. - If possible, the output code should be compatible with
ES2015and above. In any case, it should be at least down toES2020.
- Plugin Options: Optionally, you can provide configuration options for users to customize the plugin's behavior. Please follow the bellow patterns for better flexibility:
- Avoid hardcoding values. Instead, use options to allow users to customize the plugin's behavior.
- Provide sensible defaults for options to ensure the plugin works out of the box.
- Validate options to ensure they are of the correct type and within acceptable ranges.
- Documentation: Please provide clear and concise documentation for your plugin, including installation instructions, usage examples, and API references. This can be done in a
README.mdfile. If possible, please write the documentation in both English and Chinese. If not applicable, please choose English as it is the default language. - Tests: Implement tests to ensure the plugin works as expected and to prevent regressions. You need to write tests for
Jest. Please follow these guidelines:- Write unit tests for each function and component.
- The test coverage should be
100%to ensure all critical paths are tested. - Use meaningful test names to describe the purpose of each test.
When your plugin is ready, you can publish it to the npm registry. Please follow these steps:
- Ensure that your
package.jsonfile is correctly configured with the necessary metadata and dependencies. - Build the plugin using the
npm run buildcommand. - Test the built plugin using the
npm run testcommand, to ensure it works as expected. - Add a tag before publishing. The tag should be in the format of
plugin-{plugin-name}@{version}, e.g.plugin-sample@1.0.0. Do not usevx.x.xformat, as it is reserved for enum-plus releases. - Create a new release in the Releases section of the enum-plus repository. The release name should be the same as the tag you created in the previous step.
- Do not publish the plugin directly to npm without creating a release in the enum-plus repository.
- Do not publish the plugin using the
npm publishcommand.
- Pay attention to the Issues channel for any feedback or bug reports from users, periodically. Please respond to issues related to your plugin.