Typedoc for the APIs exported by the @octorelease/core package can be found here.
Many Octorelease plugins also export utility methods which can easily be used to create your own scripts. For example, to publish a package to npmjs.org using the @octorelease/npm plugin:
const { utils } = require("@octorelease/npm");
const context = {
dryRun: false, // Specify true to skip actual publish operation
env: process.env, // NPM_TOKEN environment variable must be defined
logger: console
};
const registry = "https://registry.npmjs.org";
(async () => {
await utils.npmConfig(context, registry);
await utils.npmPublish(context, "latest", registry);
})();
To create a plugin for Octorelease, you need to decide which steps are important to your plugin. For example, it is best to always have an init
step because you may be receiving inputs from a user and want to make sure they exist. A plugin can handle any of the following steps (listed in the order that they execute):
init
version
publish
success
fail
Octorelease will require the plugin via Node and look through the required object for methods named like the steps listed above. For example, if your plugin only had an init
and success
step, the main
file for your object would need to export
an object with init
and success
functions.
Each step handler method is passed two objects:
context
- an object containing theconfig
- an object containing the options that a user may pass in via theirrelease.config.js
file (or similar)
For each step that you handle, you will want to ensure it can accept context
and config
as parameters.
To create a plugin project, it is recommended to fork the template repository octorelease/sample-plugin. Alternatively, if you want to start a project from scratch:
- Generate a new project with
npm init
. This will provide you with a basic Node project to get started with. - Create an
index.js
file, and make sure it is specified as themain
in thepackage.json
. You will use this file toexport
an object defining your steps as described above. - Create a
src
orlib
folder in the root of the project. This is where you will store your logic and code for how the step handler methods work. Also create atest
folder so you can write tests related to your logic. - (recommended) Set up a linting system to ensure good JavaScript practices are enforced. ESLint is usually the system of choice, and the configuration can be whatever you prefer.