@microature/gitlab-publisher
v0.2.0
Published
CLI tool for publishing npm packages to GitLab Package Registry
Maintainers
Readme
@microature/gitlab-publisher
A CLI tool for easily publishing npm packages to GitLab Package Registry.
Features
- 🚀 Publish npm packages to GitLab Package Registry with ease
- 🔄 Automatic project detection using
glabCLI or git remote - 📦 Support for both project-level and group-level registries
- 🏷️ Version management (latest, dev, beta tags)
- 🔒 Secure token management via environment variables
- 🎨 Beautiful CLI output with colors and spinners
- 🧪 Dry-run mode for testing
Installation
# Install globally
npm install -g @microature/gitlab-publisher
# Or use as a dev dependency
npm install -D @microature/gitlab-publisherPrerequisites
- GitLab Personal Access Token with
apiandwrite_registryscopes - Your package.json should have a
prepublishOnlyscript for building (if needed) - (Optional)
glabCLI for automatic project detection
Quick Start
1. Create a .env file in your project root:
GITLAB_AUTH_TOKEN=your-personal-access-token
# Optional: Will be auto-detected if not provided
GITLAB_PROJECT_ID=your-project-id2. Add to your package.json (optional):
{
"scripts": {
"prepublishOnly": "npm run build",
"publish:gitlab": "gitlab-publish",
"publish:dev": "gitlab-publish dev",
"publish:beta": "gitlab-publish beta --bump minor"
}
}3. Publish your package:
# Publish latest version
gitlab-publish
# Publish with version bump
gitlab-publish --bump patch
# Publish development version
gitlab-publish dev
# Publish beta version
gitlab-publish beta --bump minor
# Dry run (test without publishing)
gitlab-publish --dry-runUsage
gitlab-publish [type] [options]Arguments
type- Publish type:latest(default),dev,beta
Options
--bump <type>- Version bump type:patch,minor,major--dry-run- Run without actually publishing--registry-type <type>- Registry type:project(default),group--token <token>- GitLab Personal Access Token (overrides .env)--project-id <id>- GitLab Project ID (auto-detected if not provided)--no-build- Skip prepublishOnly script--verbose- Show detailed output-V, --version- Output the version number-h, --help- Display help for command
Examples
Basic Publishing
# Publish current version
gitlab-publish
# Publish with patch version bump (1.0.0 -> 1.0.1)
gitlab-publish --bump patchDevelopment Versions
# Publish dev version with git commit hash
# Example: 1.0.0 -> 1.0.1-dev.abc1234
gitlab-publish devBeta Versions
# Publish beta version
gitlab-publish beta
# Publish beta with minor bump (1.0.0 -> 1.1.0-beta.0)
gitlab-publish beta --bump minorTesting
# Test configuration without publishing
gitlab-publish --dry-run
# Verbose output for debugging
gitlab-publish --verbose --dry-runGroup-Level Registry
# Use group-level registry instead of project-level
gitlab-publish --registry-type groupConfiguration
Environment Variables
GITLAB_AUTH_TOKEN- Your GitLab Personal Access Token (required)GITLAB_PROJECT_ID- Project ID (optional, auto-detected)
Package.json Requirements
Your package must have:
- A scoped name (e.g.,
@yourscope/package-name) - A
prepublishOnlyscript if building is required
Example:
{
"name": "@yourscope/your-package",
"version": "1.0.0",
"scripts": {
"build": "your-build-command",
"prepublishOnly": "npm run build"
}
}How It Works
- Auto-detection: Automatically detects project information from git remote or
glabCLI - Configuration: Creates a temporary
.npmrcwith GitLab registry settings - Publishing: Runs
npm publishwith appropriate settings - Cleanup: Removes temporary
.npmrcfile for security
Troubleshooting
Authentication Error (403 Forbidden)
Ensure your Personal Access Token has the correct scopes:
apiwrite_registryread_registry(optional but recommended)
Project ID Not Found
The tool tries to auto-detect the project ID using:
glabCLI (if installed)- Git remote URL
- GitLab API
If auto-detection fails, set GITLAB_PROJECT_ID in your .env file.
No prepublishOnly Script
Add a prepublishOnly script to your package.json:
{
"scripts": {
"prepublishOnly": "npm run build"
}
}Or use --no-build flag to skip the build step.
License
MIT
Contributing
Issues and pull requests are welcome at GitLab.
Author
microature
