|
1 |
| -Test CLI Rust to publish to npm |
| 1 | +# Rust-NPM Package Template |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## 🚀 Features |
| 6 | + |
| 7 | +- Seamless integration between Rust and Node.js |
| 8 | +- Automated setup process |
| 9 | +- Version management system |
| 10 | +- Pre-configured project structure |
| 11 | +- NPM package distribution ready |
| 12 | +- Automatic configuration of Cargo.toml and package.json |
| 13 | + |
| 14 | +## 📦 Prerequisites |
| 15 | + |
| 16 | +- Node.js (v20 or higher) |
| 17 | +- Rust (latest stable version) |
| 18 | +- Cargo (comes with Rust) |
| 19 | +- pnpm |
| 20 | + |
| 21 | +## 🛠 Getting Started |
| 22 | + |
| 23 | +1. Clone this repository: |
| 24 | + |
| 25 | +```bash |
| 26 | +git clone [your-repository-url] |
| 27 | +cd [repository-name] |
| 28 | +``` |
| 29 | + |
| 30 | +2. Run the setup script: |
| 31 | + |
| 32 | +```bash |
| 33 | +npm run setup |
| 34 | +``` |
| 35 | + |
| 36 | +During setup, you'll be prompted to provide: |
| 37 | + |
| 38 | +- Package name |
| 39 | +- Description |
| 40 | +- Author information |
| 41 | +- Repository URL |
| 42 | +- Keywords (default: cli, rust) |
| 43 | +- License (default: MIT) |
| 44 | + |
| 45 | +> **Note**: You don't need to manually edit `Cargo.toml` or `package.json` files. The setup script automatically configures both files based on your inputs, ensuring perfect synchronization between Rust and Node.js configurations. |
| 46 | +
|
| 47 | +## 📝 Project Structure |
| 48 | + |
| 49 | +``` |
| 50 | +. |
| 51 | +├── src/ # Rust source code |
| 52 | +├── scripts/ # JavaScript setup and utility scripts |
| 53 | +├── config.json # Project configuration |
| 54 | +├── Cargo.toml # Rust dependencies and configuration (auto-generated) |
| 55 | +└── package.json # NPM package configuration (auto-generated) |
| 56 | +``` |
| 57 | + |
| 58 | +## 🔄 Version Management & Release Process |
| 59 | + |
| 60 | +1. Bump the version of your package: |
| 61 | + |
| 62 | +```bash |
| 63 | +pnpm run bump |
| 64 | +``` |
| 65 | + |
| 66 | +This will: |
| 67 | + |
| 68 | +- Increment the version in all necessary files |
| 69 | +- Update both Rust and NPM configurations |
| 70 | +- Stage the changes for commit |
| 71 | + |
| 72 | +2. Commit and push the changes: |
| 73 | + |
| 74 | +```bash |
| 75 | +git add . |
| 76 | +git commit -m "chore: bump version to x.x.x" |
| 77 | +git push |
| 78 | +``` |
| 79 | + |
| 80 | +3. Create and push a tag to trigger the release: |
| 81 | + |
| 82 | +```bash |
| 83 | +git tag vx.x.x |
| 84 | +git push origin vx.x.x |
| 85 | +``` |
| 86 | + |
| 87 | +> **Note**: Replace `x.x.x` with your actual version number (e.g., v1.0.0) |
| 88 | +
|
| 89 | +## 🚀 CI/CD with GitHub Actions |
| 90 | + |
| 91 | +This template comes with automated workflows for building, testing, and publishing your package: |
| 92 | + |
| 93 | +### Automated Builds |
| 94 | + |
| 95 | +The build workflow is triggered on: |
| 96 | + |
| 97 | +- Every push to main branch |
| 98 | +- Pull requests to main branch |
| 99 | +- Manual trigger |
| 100 | + |
| 101 | +The workflow: |
| 102 | + |
| 103 | +1. Builds the Rust binary |
| 104 | +2. Runs tests |
| 105 | +3. Ensures code quality |
| 106 | +4. Creates build artifacts |
| 107 | + |
| 108 | +### Publishing Process |
| 109 | + |
| 110 | +The publish workflow is triggered when: |
| 111 | + |
| 112 | +- A new tag matching the pattern `vx.x.x` is pushed |
| 113 | +- Example: `v1.0.0`, `v2.1.3` |
| 114 | + |
| 115 | +The workflow automatically: |
| 116 | + |
| 117 | +1. Builds the package for all supported platforms |
| 118 | +2. Runs the test suite |
| 119 | +3. Publishes to NPM with your configured credentials |
| 120 | +4. Creates a GitHub release with built artifacts |
| 121 | + |
| 122 | +### Setting Up CI/CD |
| 123 | + |
| 124 | +1. Add your NPM token to GitHub repository secrets: |
| 125 | + |
| 126 | + - Go to your repository Settings > Secrets |
| 127 | + - Add a new secret named `NPM_TOKEN` |
| 128 | + - Paste your NPM access token |
| 129 | + |
| 130 | +2. Enable GitHub Actions: |
| 131 | + - Go to your repository Settings > Actions |
| 132 | + - Ensure Actions are enabled for your repository |
| 133 | + |
| 134 | +> **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` - there's no need to manually publish to NPM. |
| 135 | +
|
| 136 | +## 🚀 Building |
| 137 | + |
| 138 | +To build the Rust binary: |
| 139 | + |
| 140 | +```bash |
| 141 | +cargo build |
| 142 | +``` |
| 143 | + |
| 144 | +For production release: |
| 145 | + |
| 146 | +```bash |
| 147 | +cargo build --release |
| 148 | +``` |
| 149 | + |
| 150 | +## 📦 Publishing |
| 151 | + |
| 152 | +1. Build your package: |
| 153 | + |
| 154 | +```bash |
| 155 | +pnpm run build |
| 156 | +``` |
| 157 | + |
| 158 | +2. Test your package: |
| 159 | + |
| 160 | +```bash |
| 161 | +pnpm test |
| 162 | +``` |
| 163 | + |
| 164 | +3. Publish to NPM: |
| 165 | + |
| 166 | +```bash |
| 167 | +pnpm publish |
| 168 | +``` |
| 169 | + |
| 170 | +## 📄 License |
| 171 | + |
| 172 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments