|
| 1 | +# Publishing Guide for MeridianAlgo.js |
| 2 | + |
| 3 | +This guide covers how to publish the MeridianAlgo packages to both npm and GitHub Packages. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **npm Account**: Create an account at [npmjs.com](https://www.npmjs.com/) |
| 8 | +2. **GitHub Account**: You need a GitHub account with this repository |
| 9 | +3. **Authentication Tokens**: |
| 10 | + - npm token for npm publishing |
| 11 | + - GitHub Personal Access Token (PAT) for GitHub Packages |
| 12 | + |
| 13 | +## Publishing to npm |
| 14 | + |
| 15 | +### Step 1: Login to npm |
| 16 | + |
| 17 | +```bash |
| 18 | +npm login |
| 19 | +``` |
| 20 | + |
| 21 | +Enter your npm credentials when prompted. |
| 22 | + |
| 23 | +### Step 2: Build All Packages |
| 24 | + |
| 25 | +```bash |
| 26 | +pnpm build |
| 27 | +``` |
| 28 | + |
| 29 | +This will compile all TypeScript packages to JavaScript in the `dist` folders. |
| 30 | + |
| 31 | +### Step 3: Publish All Packages |
| 32 | + |
| 33 | +```bash |
| 34 | +pnpm publish:all |
| 35 | +``` |
| 36 | + |
| 37 | +This will publish all packages under the `@meridianalgo` scope to npm. |
| 38 | + |
| 39 | +### Step 4: Verify Publication |
| 40 | + |
| 41 | +Visit your packages on npm: |
| 42 | +- https://www.npmjs.com/package/@meridianalgo/core |
| 43 | +- https://www.npmjs.com/package/@meridianalgo/indicators |
| 44 | +- https://www.npmjs.com/package/@meridianalgo/data |
| 45 | +- (and so on for all packages) |
| 46 | + |
| 47 | +## Publishing to GitHub Packages |
| 48 | + |
| 49 | +### Step 1: Create GitHub Personal Access Token |
| 50 | + |
| 51 | +1. Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic) |
| 52 | +2. Click "Generate new token (classic)" |
| 53 | +3. Select scopes: |
| 54 | + - `write:packages` - Upload packages to GitHub Package Registry |
| 55 | + - `read:packages` - Download packages from GitHub Package Registry |
| 56 | + - `delete:packages` - Delete packages from GitHub Package Registry |
| 57 | +4. Generate and copy the token |
| 58 | + |
| 59 | +### Step 2: Configure npm for GitHub Packages |
| 60 | + |
| 61 | +Create or update `.npmrc` in your home directory (`~/.npmrc` or `C:\Users\YourName\.npmrc`): |
| 62 | + |
| 63 | +``` |
| 64 | +//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN |
| 65 | +@meridianalgo:registry=https://npm.pkg.github.com |
| 66 | +``` |
| 67 | + |
| 68 | +Replace `YOUR_GITHUB_TOKEN` with your actual token. |
| 69 | + |
| 70 | +### Step 3: Update Package Names for GitHub |
| 71 | + |
| 72 | +GitHub Packages requires the scope to match your GitHub username or organization. Update the root `.npmrc`: |
| 73 | + |
| 74 | +``` |
| 75 | +@MeridianAlgo:registry=https://npm.pkg.github.com |
| 76 | +``` |
| 77 | + |
| 78 | +### Step 4: Publish to GitHub Packages |
| 79 | + |
| 80 | +```bash |
| 81 | +# Build all packages |
| 82 | +pnpm build |
| 83 | + |
| 84 | +# Publish each package |
| 85 | +pnpm -r publish --registry=https://npm.pkg.github.com --access=public |
| 86 | +``` |
| 87 | + |
| 88 | +## Publishing to Both Registries |
| 89 | + |
| 90 | +You can publish to both npm and GitHub Packages by running the commands sequentially: |
| 91 | + |
| 92 | +```bash |
| 93 | +# Build once |
| 94 | +pnpm build |
| 95 | + |
| 96 | +# Publish to npm |
| 97 | +pnpm -r publish --registry=https://registry.npmjs.org/ --access=public |
| 98 | + |
| 99 | +# Publish to GitHub Packages |
| 100 | +pnpm -r publish --registry=https://npm.pkg.github.com --access=public |
| 101 | +``` |
| 102 | + |
| 103 | +## Version Management |
| 104 | + |
| 105 | +### Patch Version (Bug Fixes) |
| 106 | + |
| 107 | +```bash |
| 108 | +pnpm version:patch |
| 109 | +``` |
| 110 | + |
| 111 | +This increments the patch version (2.0.0 → 2.0.1) for all packages. |
| 112 | + |
| 113 | +### Minor Version (New Features) |
| 114 | + |
| 115 | +```bash |
| 116 | +pnpm version:minor |
| 117 | +``` |
| 118 | + |
| 119 | +This increments the minor version (2.0.0 → 2.1.0) for all packages. |
| 120 | + |
| 121 | +### Major Version (Breaking Changes) |
| 122 | + |
| 123 | +```bash |
| 124 | +pnpm version:major |
| 125 | +``` |
| 126 | + |
| 127 | +This increments the major version (2.0.0 → 3.0.0) for all packages. |
| 128 | + |
| 129 | +After updating versions, commit the changes and publish: |
| 130 | + |
| 131 | +```bash |
| 132 | +git add . |
| 133 | +git commit -m "chore: bump version to X.Y.Z" |
| 134 | +git push |
| 135 | +pnpm build |
| 136 | +pnpm publish:all |
| 137 | +``` |
| 138 | + |
| 139 | +## Troubleshooting |
| 140 | + |
| 141 | +### Error: "You must be logged in to publish packages" |
| 142 | + |
| 143 | +Run `npm login` and enter your credentials. |
| 144 | + |
| 145 | +### Error: "You do not have permission to publish" |
| 146 | + |
| 147 | +Make sure you're logged in with the correct account and have access to the `@meridianalgo` scope. |
| 148 | + |
| 149 | +### Error: "Package already exists" |
| 150 | + |
| 151 | +You're trying to publish a version that already exists. Increment the version number first. |
| 152 | + |
| 153 | +### Error: "ENEEDAUTH" |
| 154 | + |
| 155 | +Your authentication token is missing or expired. Run `npm login` again or update your `.npmrc` file. |
| 156 | + |
| 157 | +## Best Practices |
| 158 | + |
| 159 | +1. **Always build before publishing**: Run `pnpm build` to ensure all packages are compiled |
| 160 | +2. **Test before publishing**: Run `pnpm test` to ensure all tests pass |
| 161 | +3. **Update CHANGELOG.md**: Document changes in each release |
| 162 | +4. **Use semantic versioning**: Follow semver (major.minor.patch) conventions |
| 163 | +5. **Tag releases on GitHub**: Create git tags for each release |
| 164 | +6. **Write release notes**: Document what's new in each version |
| 165 | + |
| 166 | +## GitHub Release Workflow |
| 167 | + |
| 168 | +After publishing to npm: |
| 169 | + |
| 170 | +1. Create a git tag: |
| 171 | +```bash |
| 172 | +git tag -a v2.0.0 -m "Release version 2.0.0" |
| 173 | +git push origin v2.0.0 |
| 174 | +``` |
| 175 | + |
| 176 | +2. Create a GitHub Release: |
| 177 | + - Go to your repository on GitHub |
| 178 | + - Click "Releases" → "Create a new release" |
| 179 | + - Select the tag you just created |
| 180 | + - Write release notes |
| 181 | + - Publish the release |
| 182 | + |
| 183 | +## Automated Publishing with GitHub Actions |
| 184 | + |
| 185 | +You can automate publishing using GitHub Actions. Create `.github/workflows/publish.yml`: |
| 186 | + |
| 187 | +```yaml |
| 188 | +name: Publish Packages |
| 189 | + |
| 190 | +on: |
| 191 | + release: |
| 192 | + types: [created] |
| 193 | + |
| 194 | +jobs: |
| 195 | + publish: |
| 196 | + runs-on: ubuntu-latest |
| 197 | + steps: |
| 198 | + - uses: actions/checkout@v3 |
| 199 | + |
| 200 | + - uses: pnpm/action-setup@v2 |
| 201 | + with: |
| 202 | + version: 8 |
| 203 | + |
| 204 | + - uses: actions/setup-node@v3 |
| 205 | + with: |
| 206 | + node-version: '18' |
| 207 | + registry-url: 'https://registry.npmjs.org' |
| 208 | + |
| 209 | + - run: pnpm install |
| 210 | + - run: pnpm build |
| 211 | + - run: pnpm test |
| 212 | + |
| 213 | + - run: pnpm -r publish --access public |
| 214 | + env: |
| 215 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 216 | +``` |
| 217 | +
|
| 218 | +Add your npm token as a GitHub secret named `NPM_TOKEN`. |
| 219 | + |
| 220 | +## Support |
| 221 | + |
| 222 | +For issues with publishing: |
| 223 | +- npm: https://docs.npmjs.com/ |
| 224 | +- GitHub Packages: https://docs.github.com/en/packages |
| 225 | +- pnpm: https://pnpm.io/ |
| 226 | + |
| 227 | +--- |
| 228 | + |
| 229 | +**Last Updated**: November 30, 2025 |
| 230 | +**Version**: 2.0.0 |
0 commit comments