|
| 1 | +# Publishing Guide |
| 2 | + |
| 3 | +This guide explains how to publish new versions of JsonFileCRUD to npm. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **npm account**: Make sure you have an npm account and are logged in |
| 8 | + ```bash |
| 9 | + npm login |
| 10 | + ``` |
| 11 | + |
| 12 | +2. **npm token**: For GitHub Actions, add your npm token to repository secrets as `NPM_TOKEN` |
| 13 | + |
| 14 | +3. **Repository access**: Make sure you have push access to the GitHub repository |
| 15 | + |
| 16 | +## Publishing Process |
| 17 | + |
| 18 | +### Option 1: Manual Publishing (Recommended for first time) |
| 19 | + |
| 20 | +1. **Update version and changelog:** |
| 21 | + ```bash |
| 22 | + npm version patch # for bug fixes |
| 23 | + npm version minor # for new features |
| 24 | + npm version major # for breaking changes |
| 25 | + ``` |
| 26 | + |
| 27 | +2. **Verify everything works:** |
| 28 | + ```bash |
| 29 | + npm test |
| 30 | + npm run examples |
| 31 | + ``` |
| 32 | + |
| 33 | +3. **Check what will be published:** |
| 34 | + ```bash |
| 35 | + npm pack --dry-run |
| 36 | + ``` |
| 37 | + |
| 38 | +4. **Publish to npm:** |
| 39 | + ```bash |
| 40 | + npm publish |
| 41 | + ``` |
| 42 | + |
| 43 | +### Option 2: Automated Publishing via GitHub Releases |
| 44 | + |
| 45 | +1. **Create a new release on GitHub:** |
| 46 | + - Go to the repository on GitHub |
| 47 | + - Click "Releases" → "Create a new release" |
| 48 | + - Tag version: `v1.0.0` (match package.json version) |
| 49 | + - Release title: `Version 1.0.0` |
| 50 | + - Description: Copy from CHANGELOG.md |
| 51 | + |
| 52 | +2. **GitHub Actions will automatically:** |
| 53 | + - Run all tests |
| 54 | + - Run examples |
| 55 | + - Publish to npm (if tests pass) |
| 56 | + |
| 57 | +### Option 3: Using npm version command |
| 58 | + |
| 59 | +```bash |
| 60 | +# This will: |
| 61 | +# 1. Run tests |
| 62 | +# 2. Run examples |
| 63 | +# 3. Update version in package.json |
| 64 | +# 4. Create git tag |
| 65 | +# 5. Push to GitHub |
| 66 | +npm version patch |
| 67 | +``` |
| 68 | + |
| 69 | +Then create a GitHub release for the new tag to trigger npm publishing. |
| 70 | + |
| 71 | +## Version Guidelines |
| 72 | + |
| 73 | +- **Patch (1.0.X)**: Bug fixes, documentation updates |
| 74 | +- **Minor (1.X.0)**: New features, non-breaking changes |
| 75 | +- **Major (X.0.0)**: Breaking changes |
| 76 | + |
| 77 | +## Checklist Before Publishing |
| 78 | + |
| 79 | +- [ ] All tests pass (`npm test`) |
| 80 | +- [ ] Examples work (`npm run examples`) |
| 81 | +- [ ] CHANGELOG.md updated |
| 82 | +- [ ] README.md updated if needed |
| 83 | +- [ ] Version number updated in package.json |
| 84 | +- [ ] Git changes committed and pushed |
| 85 | + |
| 86 | +## Post-Publishing |
| 87 | + |
| 88 | +1. **Verify the package:** |
| 89 | + ```bash |
| 90 | + npm view json-file-crud |
| 91 | + ``` |
| 92 | + |
| 93 | +2. **Test installation:** |
| 94 | + ```bash |
| 95 | + mkdir test-install |
| 96 | + cd test-install |
| 97 | + npm init -y |
| 98 | + npm install json-file-crud |
| 99 | + ``` |
| 100 | + |
| 101 | +3. **Update documentation** if needed |
| 102 | + |
| 103 | +## Troubleshooting |
| 104 | + |
| 105 | +- **403 Forbidden**: Make sure you're logged in and have permission to publish |
| 106 | +- **Version already exists**: Update the version number |
| 107 | +- **Tests fail**: Fix issues before publishing |
| 108 | +- **Missing files**: Check .npmignore and package.json files array |
0 commit comments