This guide explains how to publish the AI Rules CLI to npm for public use.
- Node.js 18+ installed
- npm account - Create one at npmjs.com
- Git repository - Ensure your code is in a Git repository
Check that your package.json has the correct configuration:
{
"name": "ai-rules-cli",
"version": "1.0.0",
"description": "CLI for managing Cursor AI rules with dependency resolution and conflict detection",
"main": "dist/index.js",
"bin": {
"ai-rules": "./dist/index.js"
},
"files": ["dist/**/*", "README.md", "LICENSE"],
"repository": {
"type": "git",
"url": "https://github.com/rerades/ai-rules-cli.git"
},
"homepage": "https://github.com/rerades/ai-rules-cli#readme",
"bugs": {
"url": "https://github.com/rerades/ai-rules-cli/issues"
}
}# Build the project
npm run build
# Run tests
npm test
# Test the CLI locally
node dist/index.js --help# See what will be included in the package
npm pack --dry-run# Run the automated publish script
npm run publish:scriptThis script will:
- Build the project
- Run tests
- Check if the package name is available
- Show a dry run preview
- Ask for confirmation before publishing
# 1. Login to npm (if not already logged in)
npm login
# 2. Build the project
npm run build
# 3. Test the build
node dist/index.js --help
# 4. Check what will be published
npm pack --dry-run
# 5. Publish to npm
npm publishTest that users can install and use your package:
# Test global installation
npm install -g ai-rules-cli
ai-rules --help
# Test npx usage
npx ai-rules-cli --help- Update the README with the correct installation instructions
- Add any new features or changes to the changelog
- Update the repository with the latest changes
Create a Git tag for the version:
git tag v1.0.0
git push origin v1.0.0Follow Semantic Versioning:
- MAJOR (1.0.0): Breaking changes
- MINOR (1.1.0): New features, backward compatible
- PATCH (1.0.1): Bug fixes, backward compatible
# Update version in package.json
npm version patch # 1.0.0 -> 1.0.1
npm version minor # 1.0.0 -> 1.1.0
npm version major # 1.0.0 -> 2.0.0
# This automatically:
# - Updates package.json version
# - Creates a Git tag
# - Commits the changes-
Package name already exists
- Choose a different name
- Use a scoped package:
@your-username/ai-rules-cli
-
Build fails
- Check TypeScript errors:
npm run build - Fix linting issues:
npm run lint:fix
- Check TypeScript errors:
-
Permission denied
- Ensure you're logged in:
npm whoami - Check npm permissions for the package
- Ensure you're logged in:
-
Package too large
- Review
.npmignorefile - Remove unnecessary files from
filesarray
- Review
- Check npm documentation: docs.npmjs.com
- npm CLI help:
npm help publish - Package troubleshooting:
npm help package
- Never commit
.npmrcwith sensitive tokens - Use
npm loginfor authentication - Consider using 2FA for your npm account
- Review package contents before publishing
- Test thoroughly before publishing
- Use semantic versioning consistently
- Write clear documentation and changelog
- Keep dependencies up to date
- Monitor package downloads and issues
- Respond to user feedback promptly
Once published, users can install and use your CLI:
# Global installation
npm install -g ai-rules-cli
ai-rules init
# Using npx (no installation required)
npx ai-rules-cli init
# Check version
ai-rules --version- Monitor for security vulnerabilities:
npm audit - Update dependencies regularly:
npm update - Respond to issues and feature requests
- Plan for future versions and breaking changes