2.2.0 • Published 5 days ago

@simple-release/core v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@simple-release/core

ESM-only package NPM version Node version Dependencies status Install size Build status Coverage status

A simple tool to automate version bumps, changelogs, and releases using Conventional Commits.

  • 📄 Uses conventional-changelog to parse commits, determine the next version, and generate a changelog.
  • 🗂️ Supports monorepos and can release multiple packages in a single run.
  • 🧩 Flexible and extensible with custom addons for different project types.
  • 🚀 Has GitHub Action to automate releases in CI/CD pipelines.

Install

# pnpm
pnpm add @simple-release/core
# yarn
yarn add @simple-release/core
# npm
npm i @simple-release/core

Usage

import { Releaser } from '@simple-release/core'
import { PnpmProject } from '@simple-release/pnpm'
import { GithubHosting } from '@simple-release/github'

await new Releaser({
  project: new PnpmProject(),
  hosting: new GithubHosting({
    token: process.env.GITHUB_TOKEN
  })
})
  .bump()
  .commit()
  .tag()
  .push()
  .release()
  .publish()
  .run()

Monorepo example:

import { Releaser } from '@simple-release/core'
import { PnpmWorkspacesProject } from '@simple-release/pnpm'
import { GithubHosting } from '@simple-release/github'

await new Releaser({
  project: new PnpmWorkspacesProject({
    mode: 'independent'
  }),
  hosting: new GithubHosting({
    token: process.env.GITHUB_TOKEN
  })
})
  .bump()
  .commit()
  .tag()
  .push()
  .release()
  .publish()
  .run()

Options

OptionDescription
projectProject instance.
hostingGit repository hosting instance. Optional.
dryRunIf true, do not write files, just change the version in memory.
verboseIf true, log more information to the console.
silentIf true, do not log anything to the console.

Available steps

StepDescription
checkoutCheckout the desired branch.
bumpBump the version of the project and generate changelog.
commitCommit the changes with the new version.
tagTag the commit with the new version.
pushPush the changes to the remote repository.
releaseCreate a release in the remote repository.
publishPublish the project to the package registry.
pullRequestCreate a pull request with the changes.

Addons

  • npm - for projects using npm as a package manager.
  • pnpm - for projects using pnpm as a package manager.
  • github - for projects hosted on GitHub.

Custom addons

Manifest

If you want to create your own project addon, firstly you can need to create a custom manifest adapter. Manifest adapter is a class that reads basic information about the project from the manifest file (like package.json) and can write version to it.

import { ProjectManifest } from '@simple-release/core'

export class CustomManifest extends ProjectManifest {
  static Filename = 'custom.json'

  async readManifest() {
    // Read the manifest file and return its parsed content
  }

  async getName() {
    // Return the name of the project
  }

  async getVersion() {
    // Return the current version of the project
  }

  async isPrivate() {
    // Return true if the project is private
  }

  async writeVersion(version, dryRun) {
    // Write the new version to the manifest file
    // If dryRun is true, do not write the file, just change the version in memory
  }
}

For more detailed example you can look at the PackageJsonManifest implementation.

Project

Project is a class that represents the project and provides methods to work with it:

  • bump version
  • get information from git
  • publish the project
  • etc.

Most of the methods are implemented in base class Project and you can extend it to create your own project class.

In most casses you need just prepare options for the base class and implement publish method (like it is done in PackageJsonProject).

import { Project } from '@simple-release/core'

export class CustomProject extends Project {
  constructor(options) {
    super({
      ...options,
      manifest: new CustomManifest(options.path)
    })
  }

  async publish(options) {
    // Publish the project
  }
}

There also is a base class for monorepo projects - MonorepoProject. It provides methods to work with monorepo projects and you can extend it to create your own monorepo project class (alos see PackageJsonMonorepoProject).

GitRepositoryHosting

GitRepositoryHosting is a class that represents a git repository hosting service (like GitHub, GitLab, etc.) or whatever you want. It is used to create a release in the remote repository and create a pull request with the changes.

import { GitRepositoryHosting } from '@simple-release/core'

export class MyRepositoryHosting extends GitRepositoryHosting {
  async createRelease({ project, dryRun, logger }) {
    // Create the release in the remote repository
    // You can use `project` to get information about the project
    // or more precisely you can use `project.getReleaseData()` to get the data for the release
  }

  async createPullRequest({ from, to, project, dryRun, logger }) {
    // Create a pull request with the changes
    // You can use `project` to get information about the project
  }
}

For more detailed example you can look at the GithubHosting implementation.