npm package: @orderly.network/npm-release
Description: CLI for releasing npm packages using [release-it](https://github.com/release-it/release-it), with support for environment-based registry/token config, Git auth, pre-release tags, and Slack notifications.
Latest version: 0.0.6

# @orderly.network/npm-release

CLI for releasing npm packages using [release-it](https://github.com/release-it/release-it), with support for environment-based registry/token config, Git auth, pre-release tags, and Slack notifications.

## Features

- **release-it driven** — Bump version, commit, tag, and publish via release-it.
- **Environment-based config** — Registry URL and npm token via `NPM_REGISTRY` / `NPM_TOKEN`; no local `.release-it.json` required.
- **Git authentication** — GitLab (and similar) push via `GIT_TOKEN` + `GIT_USERNAME`; commit identity via `GIT_NAME` / `GIT_EMAIL`.
- **Pre-release tags** — Optional `PRERELEASE_TAG` (e.g. `alpha`, `beta`) for prerelease versions and `npm dist-tag`.
- **Slack notifications** — Optional webhook for success/failure after publish.
- **Internal registry friendly** — When using a custom registry (non-npmjs.org), git tag creation is skipped so internal flows stay simple.

## Installation and usage

From your project root:

```bash
npx @orderly.network/npm-release
```

Or add as a devDependency and run via scripts:

```bash
pnpm add -D @orderly.network/npm-release
```

```json
{
  "scripts": {
    "release": "orderly-npm-release"
  }
}
```

## Environment variables

| Variable               | Description                                                                           |
| ---------------------- | ------------------------------------------------------------------------------------- |
| `CI_COMMIT_BRANCH`     | Current branch in CI environment                                                      |
| `NPM_REGISTRY`         | npm registry URL (default: `https://registry.npmjs.org`)                              |
| `NPM_TOKEN`            | Auth token for publishing; written to `.npmrc` when set                               |
| `GIT_TOKEN`            | Git personal access token for push (e.g. GitLab)                                      |
| `GIT_USERNAME`         | Git username (used with token for authenticated remote URL)                           |
| `GIT_NAME`             | Git `user.name` for commits                                                           |
| `GIT_EMAIL`            | Git `user.email` for commits                                                          |
| `RELEASE_VERSION_TYPE` | Bump type: `patch`, `minor`, or `major`                                               |
| `PRERELEASE_TAG`       | Pre-release identifier (e.g. `alpha`, `beta`); enables `--preRelease` and `--npm.tag` |
| `SLACK_WEBHOOK_URL`    | Webhook URL for success/failure Slack notifications                                   |

All variables are optional. Unset values use defaults or disable the corresponding feature (e.g. no Slack notification if `SLACK_WEBHOOK_URL` is not set).

## Behavior

### Internal registry

When `NPM_REGISTRY` is set and is **not** `https://registry.npmjs.org`, the CLI treats it as an internal registry and **does not create a git tag**. Commits and push still occur; only tagging is skipped.

### Pre-release

- If `PRERELEASE_TAG` is set and the current `package.json` version is already a prerelease with the same preId (e.g. `1.0.0-alpha.0` with tag `alpha`), the version is incremented as **prerelease** (e.g. `1.0.0-alpha.1`).
- Otherwise, the bump follows `RELEASE_VERSION_TYPE` (`patch`, `minor`, or `major`). When `PRERELEASE_TAG` is set, the new version is a prerelease and published under that npm dist-tag.

### Working directory

The CLI does **not** require a clean working directory. It is intended to run in CI after `pnpm install` or build steps that may change the lockfile or generated files.

## CI integration

In GitLab CI (or similar), set the needed environment variables (`GIT_NAME`, `GIT_EMAIL`, `GIT_USERNAME`, `GIT_TOKEN`, `NPM_REGISTRY`, `NPM_TOKEN`, `RELEASE_VERSION_TYPE`, `PRERELEASE_TAG`, `SLACK_WEBHOOK_URL`) and run:

```bash
pnpm release
```

or:

```bash
npx @orderly.network/npm-release
```

## License

MIT