This repository provides a template for creating NPM packages with Rust, allowing you to leverage Rust's performance and safety features while distributing your package through NPM.
- Seamless integration between Rust and Node.js
- Automated setup process
- Version management system
- Pre-configured project structure
- NPM package distribution ready
- Automatic configuration of Cargo.toml and package.json
- Node.js (v20 or higher)
- Rust (latest stable version)
- Cargo (comes with Rust)
- pnpm
- Clone this repository:
git clone [your-repository-url]
cd [repository-name]
- Run the setup script:
npm run setup
During setup, you'll be prompted to provide:
- Package name
- Description
- Author information
- Repository URL
- Keywords (default: cli, rust)
- License (default: MIT)
Note: You don't need to manually edit
Cargo.toml
orpackage.json
files. The setup script automatically configures both files based on your inputs, ensuring perfect synchronization between Rust and Node.js configurations.
.
├── src/ # Rust source code
├── scripts/ # JavaScript setup and utility scripts
├── config.json # Project configuration
├── Cargo.toml # Rust dependencies and configuration (auto-generated)
└── package.json # NPM package configuration (auto-generated)
- Bump the version of your package:
pnpm run bump
This will:
- Increment the version in all necessary files
- Update both Rust and NPM configurations
- Create a git commit with the changes
- Create a local git tag
- Review the changes and when ready:
# Push the commits
git push
# Push the tag to trigger the release
git push origin v[version]
Note: Pushing a tag will automatically trigger the GitHub Actions release workflow.
This template comes with automated workflows for building, testing, and publishing your package:
The build workflow is triggered on:
- Every push to main branch
- Pull requests to main branch
- Manual trigger
The workflow:
- Builds the Rust binary
- Runs tests
- Ensures code quality
- Creates build artifacts
The publish workflow is triggered when:
- A new tag matching the pattern
vx.x.x
is pushed - Example:
v1.0.0
,v2.1.3
The workflow automatically:
- Builds the package for all supported platforms
- Runs the test suite
- Publishes to NPM with your configured credentials
- Creates a GitHub release with built artifacts
-
Add your NPM token to GitHub repository secrets:
- Go to your repository Settings > Secrets
- Add a new secret named
NPM_TOKEN
- Paste your NPM access token
-
Enable GitHub Actions:
- Go to your repository Settings > Actions
- Ensure Actions are enabled for your repository
Note: The build and publish processes are fully automated through GitHub Actions. Publishing is triggered by pushing a tag in the format
vx.x.x
.
This project is licensed under the MIT License - see the LICENSE file for details.