Skip to content

Commit 490cb96

Browse files
improve publishing
1 parent 332ef01 commit 490cb96

File tree

1 file changed

+265
-6
lines changed

1 file changed

+265
-6
lines changed

website/docs/components/publishing-to-a-registry.md

Lines changed: 265 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,273 @@ sidebar_position: 5
44

55
# Publishing to a registry
66

7-
You will need an online registry connected to a library to do that. The only requisite is that a component with the same name and version cannot be already existing on that registry.
7+
Publishing components to an OpenComponents registry makes them available for consumption across your applications. This guide covers the complete publishing workflow, from basic commands to advanced scenarios and troubleshooting.
8+
9+
## Overview
10+
11+
Publishing is the process of uploading your packaged component to a registry where it becomes available for consumption. When you publish a component:
12+
13+
1. **Packaging**: Your component is compiled and packaged with all dependencies
14+
2. **Validation**: The registry validates the component structure, CLI version, and custom rules
15+
3. **Storage**: The component is stored in the registry's storage backend
16+
4. **Availability**: The component becomes accessible via HTTP endpoints
17+
18+
## Prerequisites
19+
20+
Before publishing components, ensure you have:
21+
22+
- An OpenComponents registry set up and accessible
23+
- A properly structured component with valid `package.json`
24+
- Registry credentials (if authentication is required)
25+
- Compatible CLI and Node.js versions
26+
27+
## Basic Publishing Workflow
28+
29+
### 1. Add Registry
30+
31+
First, configure your registry (only needed once):
32+
33+
```sh
34+
oc registry add https://your-registry-domain.com
35+
```
36+
37+
### 2. Publish Component
38+
39+
Navigate to your component directory and publish:
40+
41+
```sh
42+
oc publish my-component/
43+
```
44+
45+
This command will:
46+
47+
- Package your component automatically
48+
- Compress it for upload
49+
- Upload to all configured registries
50+
- Make it available at `https://your-registry-domain.com/my-component`
51+
52+
## Authentication
53+
54+
### Interactive Authentication
55+
56+
If the registry requires authentication, you'll be prompted for credentials:
57+
58+
```sh
59+
oc publish my-component/
60+
# Registry requires authentication
61+
# Username: your-username
62+
# Password: [hidden input]
63+
```
64+
65+
### Command-line Authentication
66+
67+
Provide credentials directly via command-line options:
68+
69+
```sh
70+
oc publish my-component/ --username=your-username --password=your-password
71+
```
72+
73+
### Custom Authentication
74+
75+
Registries can implement custom authentication strategies. Check with your registry administrator for specific requirements.
76+
77+
## CLI Options
78+
79+
The `oc publish` command supports several options:
80+
81+
| Option | Type | Description | Example |
82+
| --------------- | ------- | ---------------------------------------------------- | ---------------------------------------------- |
83+
| `--username` | string | Username for registry authentication | `--username=john` |
84+
| `--password` | string | Password for registry authentication | `--password=secret` |
85+
| `--registries` | array | Specific registries to publish to (overrides config) | `--registries=http://reg1.com,http://reg2.com` |
86+
| `--skipPackage` | boolean | Skip packaging step (use existing `_package` folder) | `--skipPackage` |
87+
| `--dryRun` | boolean | Test publish without actually uploading | `--dryRun` |
88+
89+
### Examples
90+
91+
**Basic publish:**
92+
93+
```sh
94+
oc publish my-component/
95+
```
96+
97+
**Publish with credentials:**
98+
99+
```sh
100+
oc publish my-component/ --username=developer --password=mypassword
101+
```
102+
103+
**Dry run (test without publishing):**
104+
105+
```sh
106+
oc publish my-component/ --dryRun
107+
```
108+
109+
**Publish to specific registries:**
110+
111+
```sh
112+
oc publish my-component/ --registries=https://staging-registry.com,https://prod-registry.com
113+
```
114+
115+
**Skip packaging (use pre-built component):**
116+
117+
```sh
118+
oc publish my-component/ --skipPackage
119+
```
120+
121+
## Advanced Usage
122+
123+
### Multiple Registries
124+
125+
You can publish to multiple registries simultaneously:
126+
127+
```sh
128+
# Configure multiple registries
129+
oc registry add https://staging-registry.com
130+
oc registry add https://production-registry.com
131+
132+
# Publish to all configured registries
133+
oc publish my-component/
134+
135+
# Or specify registries for this publish only
136+
oc publish my-component/ --registries=https://staging-registry.com
137+
```
138+
139+
### Pre-built Components
140+
141+
If you have a pre-packaged component in the `_package` folder:
142+
143+
```sh
144+
oc publish my-component/ --skipPackage
145+
```
146+
147+
This skips the packaging step and directly publishes the existing package.
148+
149+
### Testing with Dry Run
150+
151+
Always test your publish with `--dryRun` first:
152+
153+
```sh
154+
oc publish my-component/ --dryRun
155+
```
156+
157+
This validates your component and simulates the publish process without actually uploading.
158+
159+
## Version Management
160+
161+
- Component versions are determined by the `version` field in `package.json`
162+
- You cannot publish the same name and version twice to the same registry
163+
- Update your component version before publishing updates:
164+
165+
```json
166+
{
167+
"name": "my-component",
168+
"version": "1.0.1",
169+
"oc": {
170+
// component configuration
171+
}
172+
}
173+
```
174+
175+
## Troubleshooting
176+
177+
### Common Errors
178+
179+
**Unauthorized (401)**
180+
181+
```
182+
Error: Unauthorized
183+
```
184+
185+
**Solution**: Provide valid credentials using `--username` and `--password` options, or ensure your authentication is properly configured.
186+
187+
**Component Already Exists**
188+
189+
```
190+
Error: Component already exists: [email protected]
191+
```
192+
193+
**Solution**: Update the version in your `package.json` file before publishing.
194+
195+
**CLI Version Mismatch**
196+
197+
```
198+
Error: OC CLI version needs upgrade
199+
```
200+
201+
**Solution**: Update your CLI to the required version:
8202

9203
```sh
10-
# you have to do the registry config first, just once
11-
oc registry add http://my-components-registry.mydomain.com
204+
npm install -g oc@latest
205+
```
206+
207+
**Node Version Incompatibility**
208+
209+
```
210+
Error: Node CLI version needs upgrade
211+
```
212+
213+
**Solution**: Update Node.js to a compatible version as specified in the error message.
214+
215+
**Invalid Component Name**
216+
217+
```
218+
Error: Component name not valid
219+
```
220+
221+
**Solution**: Ensure your component name follows naming conventions (lowercase, no spaces, valid npm package name format).
222+
223+
**Invalid Component Version**
224+
225+
```
226+
Error: Component version not valid
227+
```
228+
229+
**Solution**: Use semantic versioning (e.g., "1.0.0", "2.1.3") in your `package.json`.
230+
231+
**Package Validation Failed**
232+
233+
```
234+
Error: Package is not valid
235+
```
236+
237+
**Solution**: Check that your component has:
238+
239+
- Valid `package.json` with required `oc` configuration
240+
- All required files (template, server.js if needed)
241+
- Proper component structure
242+
243+
**Template Version Incompatibility**
12244

13-
# then, ship it
14-
oc publish hello-world/
15245
```
246+
Error: Your template requires a version of OC higher than X.X.X
247+
```
248+
249+
**Solution**: Either upgrade your registry or downgrade your template requirements.
250+
251+
### Debugging Tips
252+
253+
1. **Use dry run first**: Always test with `--dryRun` before actual publishing
254+
2. **Check component structure**: Ensure all required files are present
255+
3. **Validate package.json**: Verify the `oc` configuration is correct
256+
4. **Test locally**: Use `oc dev` to test your component locally before publishing
257+
5. **Check registry logs**: Contact your registry administrator for server-side error details
258+
259+
### Getting Help
260+
261+
If you encounter issues not covered here:
262+
263+
1. Check the component structure with `oc dev`
264+
2. Validate your `package.json` configuration
265+
3. Test with `--dryRun` to identify issues before publishing
266+
4. Contact your registry administrator for authentication or server issues
267+
5. Check the [OpenComponents GitHub repository](https://github.com/opencomponents/oc) for known issues
268+
269+
## Best Practices
16270

17-
Now, it should be there at `http://my-components-registry.mydomain.com/hello-world`.
271+
- **Always use dry run first**: Test your publish with `--dryRun`
272+
- **Version management**: Follow semantic versioning for your components
273+
- **Test locally**: Use `oc dev` to test components before publishing
274+
- **Secure credentials**: Never commit passwords to version control
275+
- **Registry selection**: Use staging registries for testing, production for releases
276+
- **Component validation**: Ensure your component works in isolation before publishing

0 commit comments

Comments
 (0)