Skip to content

Latest commit

History

History
198 lines (138 loc) 路 4.93 KB

github-npm-package-strategy.md

File metadata and controls

198 lines (138 loc) 路 4.93 KB

GithubNpmPackageStrategy

A Strategy to publish NPM packages source controlled in Github.

This strategy will:

demo

Options

Type: object literal

Optional properties are denoted by *

logger*

Type: Logger
Default: processStdoutLogger

release

Type: Release

remote*

Type: string
Default: origin

gitClient*

Type: GitClient
Default: GitExecaClient

gitActor*

Type: string
Default: undefined

A short-hand to perform git commits using a specific author & committer email and name.

Example:

/*
 * The value must be in author format: "NAME <EMAIL>"
 */
{ gitActor: "bot <bot@email.com>" }
It is also possible to explicitly use the equivalent environment variables:

GIT_COMMITTER_NAME: bot
GIT_COMMITTER_EMAIL: bot@email.com
GIT_AUTHOR_NAME: bot
GIT_AUTHOR_EMAIL: bot@email.com

workingDirectory*

Type: string
Default: process.cwd()

packageRoot*

Type: string
Default: options.workingDirectory

The working directory to use for npm commands.

changelogFilePath*

Type: string
Default: ${workingDirectory}/CHANGELOG.md

regenerateChangelog*

Type: boolean
Default: true

Regenerate the changelog (next and previous versions).

github

Type: object literal

An object literal with 3 properties:

{
  owner: "abstracter-io",
  repo: "atomic-release",
  personalAccessToken: "Github personal access token with repository access"
}

branchConfig

Type: object literal

{
  // config for "main" branch
  main: {
    isStableGithubRelease: true // Will not mark the created Github release as "pre release"
    npmRegistryDistTag: "latest" // <-- will enable doing: npm install @abstracter/atomic-release ("latest" is the default when installing)
  }

  // config for "beta" branch
  beta: {
    isStableGithubRelease: false, // Will mark the created Github release as "pre release" (falsy by default)
    npmRegistryDistTag: "unstable" // <-- will enable doing: npm install @abstracter/atomic-release@unstable
  }
}

鈩癸笍 聽 GitStrategy options are also applicable.

Example

const { GithubNpmPackageStrategy } = require("@abstracter/atomic-release/strategies");
const { gitSemanticRelease } = require("@abstracter/atomic-release/adapters/git-semantic-release");

const github = {
  owner: "abstracter-io",
  repo: "atomic-release",
  host: "https://github.com",
};

const stableBranchName = "main";

const createRelease = () => {
  return gitSemanticRelease({
    stableBranchName,

    workingDirectory: process.cwd(),

    preReleaseBranches: {
      beta: "beta",
    },

    conventionalChangelogWriterContext: {
      host: github.host,
      owner: github.owner,
      repository: github.repo,
      repoUrl: `${github.host}//${github.owner}/${github.repo}`,
    },
  });
};

const createStrategy = (release) => {
  return new GithubNpmPackageStrategy({
    release,

    remote: "origin",

    changelogFilePath: `${process.cwd()}/CHANGELOG.md`,

    workingDirectory: process.cwd(),

    regenerateChangeLog: true,

    github: {
      repo: github.repo,
      owner: github.owner,
      personalAccessToken: process.env.GITHUB_PAT_TOKEN,
    },

    branchConfig: {
      [stableBranchName]: {
        isStable: true,
        npmRegistryDistTag: "latest",
      },

      beta: {
        npmRegistryDistTag: "beta",
      },
    },
  });
};

createRelease().then(createStrategy).then((strategy => strategy.run()));