diff --git a/README.md b/README.md index 9188221..142275f 100644 --- a/README.md +++ b/README.md @@ -1 +1,172 @@ -Test CLI Rust to publish to npm +# Rust-NPM Package Template + +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. + +## šŸš€ Features + +- 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 + +## šŸ“¦ Prerequisites + +- Node.js (v20 or higher) +- Rust (latest stable version) +- Cargo (comes with Rust) +- pnpm + +## šŸ›  Getting Started + +1. Clone this repository: + +```bash +git clone [your-repository-url] +cd [repository-name] +``` + +2. Run the setup script: + +```bash +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` or `package.json` files. The setup script automatically configures both files based on your inputs, ensuring perfect synchronization between Rust and Node.js configurations. + +## šŸ“ Project Structure + +``` +. +ā”œā”€ā”€ 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) +``` + +## šŸ”„ Version Management & Release Process + +1. Bump the version of your package: + +```bash +pnpm run bump +``` + +This will: + +- Increment the version in all necessary files +- Update both Rust and NPM configurations +- Stage the changes for commit + +2. Commit and push the changes: + +```bash +git add . +git commit -m "chore: bump version to x.x.x" +git push +``` + +3. Create and push a tag to trigger the release: + +```bash +git tag vx.x.x +git push origin vx.x.x +``` + +> **Note**: Replace `x.x.x` with your actual version number (e.g., v1.0.0) + +## šŸš€ CI/CD with GitHub Actions + +This template comes with automated workflows for building, testing, and publishing your package: + +### Automated Builds + +The build workflow is triggered on: + +- Every push to main branch +- Pull requests to main branch +- Manual trigger + +The workflow: + +1. Builds the Rust binary +2. Runs tests +3. Ensures code quality +4. Creates build artifacts + +### Publishing Process + +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: + +1. Builds the package for all supported platforms +2. Runs the test suite +3. Publishes to NPM with your configured credentials +4. Creates a GitHub release with built artifacts + +### Setting Up CI/CD + +1. 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 + +2. 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` - there's no need to manually publish to NPM. + +## šŸš€ Building + +To build the Rust binary: + +```bash +cargo build +``` + +For production release: + +```bash +cargo build --release +``` + +## šŸ“¦ Publishing + +1. Build your package: + +```bash +pnpm run build +``` + +2. Test your package: + +```bash +pnpm test +``` + +3. Publish to NPM: + +```bash +pnpm publish +``` + +## šŸ“„ License + +This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/scripts/bump.js b/scripts/bump.js new file mode 100644 index 0000000..66bb5de --- /dev/null +++ b/scripts/bump.js @@ -0,0 +1,50 @@ +import { execSync } from 'child_process'; +import { readFileSync, writeFileSync } from 'fs'; +import { resolve } from 'path'; + +function getCurrentVersion() { + const configPath = resolve(__dirname, '../config.json'); + const config = JSON.parse(readFileSync(configPath, 'utf8')); + return config.version; +} + +function bumpVersion() { + try { + // Run npm version patch to increment version + execSync('pnpm version patch --no-git-tag-version'); + + // Get the new version from package.json + const packageJson = JSON.parse(readFileSync('package.json', 'utf8')); + const newVersion = packageJson.version; + + // Update config.json + const configPath = resolve(__dirname, '../config.json'); + const config = JSON.parse(readFileSync(configPath, 'utf8')); + config.version = newVersion; + writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n'); + + // Update all configuration files + require('./update-config'); + + // Git operations (local only) + execSync('git add .'); + execSync(`git commit -m "chore: bump version to ${newVersion}"`); + execSync(`git tag v${newVersion}`); + + console.log(`āœØ Successfully bumped version to ${newVersion}`); + console.log('\nNext steps:'); + console.log('1. Review the changes'); + console.log('2. Push the changes:'); + console.log(' git push'); + console.log('3. Push the tag to trigger the release:'); + console.log(` git push origin v${newVersion}`); + console.log( + '\nšŸš€ Once pushed, GitHub Actions will handle the release process', + ); + } catch (error) { + console.error('āŒ Error during version bump:', error.message); + process.exit(1); + } +} + +bumpVersion(); diff --git a/scripts/setup.js b/scripts/setup.js index 98707fc..0a9833e 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -51,8 +51,11 @@ async function setup() { console.log('\nāœØ Setup complete! Your project is ready.'); console.log(`\nNext steps:`); console.log(`1. Check the generated configuration files`); - console.log(`2. Run \`cargo build\` to compile the Rust project`); - console.log(`3. Use \`pnpm run bump\` to increment version when needed`); + console.log(`2. Commit your changes when ready`); + console.log(`3. Run \`cargo build\` to compile the Rust project`); + console.log( + `4. Use \`pnpm run bump\` when you need to release a new version`, + ); rl.close(); }