|
| 1 | +# npm Publishing Guide |
| 2 | + |
| 3 | +This document describes how to publish the DoPlan CLI to npm. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The DoPlan CLI is published to npm as `doplan-cli`. The npm package includes a wrapper script that automatically downloads the platform-specific binary from GitHub releases. |
| 8 | + |
| 9 | +## Package Structure |
| 10 | + |
| 11 | +- `package.json` - npm package configuration |
| 12 | +- `bin/doplan.js` - Wrapper script that downloads and executes the binary |
| 13 | +- `scripts/postinstall.js` - Post-install script that downloads the binary |
| 14 | +- `scripts/prepublish.js` - Pre-publish validation script |
| 15 | +- `.npmrc` - npm configuration |
| 16 | + |
| 17 | +## Publishing Process |
| 18 | + |
| 19 | +### Automated Publishing (Recommended) |
| 20 | + |
| 21 | +Publishing to npm is automated via GitHub Actions. When you push a tag matching `v*`: |
| 22 | + |
| 23 | +1. The release workflow builds binaries for all platforms |
| 24 | +2. Creates a GitHub release |
| 25 | +3. Automatically publishes to npm with the same version |
| 26 | + |
| 27 | +**Requirements:** |
| 28 | +- `NPM_TOKEN` secret must be configured in GitHub repository settings |
| 29 | +- Token must have publish permissions for the `doplan-cli` package |
| 30 | + |
| 31 | +### Manual Publishing |
| 32 | + |
| 33 | +If you need to publish manually: |
| 34 | + |
| 35 | +```bash |
| 36 | +# 1. Ensure you're logged in to npm |
| 37 | +npm login |
| 38 | + |
| 39 | +# 2. Update version in package.json (if needed) |
| 40 | +npm version patch|minor|major |
| 41 | + |
| 42 | +# 3. Run pre-publish validation |
| 43 | +npm run prepublishOnly |
| 44 | + |
| 45 | +# 4. Publish to npm |
| 46 | +npm publish |
| 47 | + |
| 48 | +# 5. Verify publication |
| 49 | +npm view doplan-cli |
| 50 | +``` |
| 51 | + |
| 52 | +## Setting up NPM_TOKEN |
| 53 | + |
| 54 | +1. **Create an npm access token:** |
| 55 | + - Go to https://www.npmjs.com/settings/YOUR_USERNAME/tokens |
| 56 | + - Click "Generate New Token" |
| 57 | + - Select "Automation" token type |
| 58 | + - Copy the token |
| 59 | + |
| 60 | +2. **Add to GitHub Secrets:** |
| 61 | + - Go to your repository settings |
| 62 | + - Navigate to Secrets and variables > Actions |
| 63 | + - Click "New repository secret" |
| 64 | + - Name: `NPM_TOKEN` |
| 65 | + - Value: Your npm token |
| 66 | + - Click "Add secret" |
| 67 | + |
| 68 | +## Package Details |
| 69 | + |
| 70 | +- **Package Name:** `doplan-cli` |
| 71 | +- **Registry:** https://registry.npmjs.org/ |
| 72 | +- **Access:** Public |
| 73 | +- **Scoped:** No (public package) |
| 74 | + |
| 75 | +## How It Works |
| 76 | + |
| 77 | +1. **Installation:** When users run `npm install -g doplan-cli`: |
| 78 | + - npm installs the package files |
| 79 | + - `postinstall.js` runs automatically |
| 80 | + - Downloads the platform-specific binary from GitHub releases |
| 81 | + - Stores binary in `bin/<platform>-<arch>/doplan` |
| 82 | + |
| 83 | +2. **Execution:** When users run `doplan`: |
| 84 | + - `bin/doplan.js` wrapper script is executed |
| 85 | + - Script detects platform and architecture |
| 86 | + - If binary doesn't exist, downloads it from GitHub releases |
| 87 | + - Executes the binary with all arguments |
| 88 | + |
| 89 | +## Version Management |
| 90 | + |
| 91 | +- Version in `package.json` should match the Go release version |
| 92 | +- GitHub Actions automatically syncs version from git tag |
| 93 | +- Use semantic versioning (e.g., `1.0.0`, `1.0.1`, `1.1.0`) |
| 94 | + |
| 95 | +## Troubleshooting |
| 96 | + |
| 97 | +### Binary Download Fails |
| 98 | + |
| 99 | +If the binary download fails during installation: |
| 100 | +- Check GitHub releases exist for the version |
| 101 | +- Verify network connectivity |
| 102 | +- Users can manually download from GitHub releases |
| 103 | + |
| 104 | +### Publishing Fails |
| 105 | + |
| 106 | +If automated publishing fails: |
| 107 | +- Check `NPM_TOKEN` secret is set correctly |
| 108 | +- Verify token has publish permissions |
| 109 | +- Check package name isn't already taken |
| 110 | +- Ensure version doesn't already exist on npm |
| 111 | + |
| 112 | +### Version Mismatch |
| 113 | + |
| 114 | +If package.json version doesn't match release: |
| 115 | +- GitHub Actions automatically updates it from git tag |
| 116 | +- For manual publishing, ensure versions match |
| 117 | + |
| 118 | +## Testing Before Publishing |
| 119 | + |
| 120 | +```bash |
| 121 | +# Test package locally |
| 122 | +npm pack |
| 123 | +tar -xzf doplan-cli-*.tgz |
| 124 | +cd package |
| 125 | +npm install |
| 126 | + |
| 127 | +# Test the wrapper script |
| 128 | +./bin/doplan.js --version |
| 129 | + |
| 130 | +# Test installation simulation |
| 131 | +npm run prepublishOnly |
| 132 | +``` |
| 133 | + |
| 134 | +## Updating Package |
| 135 | + |
| 136 | +To update the npm package: |
| 137 | + |
| 138 | +1. Make changes to package files |
| 139 | +2. Update version (automated in CI/CD) |
| 140 | +3. Push git tag (triggers automated publish) |
| 141 | +4. Or publish manually with `npm publish` |
| 142 | + |
| 143 | +## Package Files Included |
| 144 | + |
| 145 | +The following files are included in the npm package (defined in `package.json` `files` field): |
| 146 | + |
| 147 | +- `bin/` - Wrapper scripts |
| 148 | +- `scripts/` - Install and publish scripts |
| 149 | +- `README.md` - Package documentation |
| 150 | +- `LICENSE` - License file |
| 151 | + |
| 152 | +Excluded files: |
| 153 | +- Source code (Go files) |
| 154 | +- Build artifacts |
| 155 | +- Test files |
| 156 | +- Development documentation |
| 157 | + |
| 158 | +## Support |
| 159 | + |
| 160 | +For issues with npm publishing: |
| 161 | +- Check GitHub Actions workflow logs |
| 162 | +- Verify npm token permissions |
| 163 | +- Review npm package page: https://www.npmjs.com/package/doplan-cli |
| 164 | + |
0 commit comments