Skip to content

Commit d0f36c4

Browse files
more docs
1 parent ae264ce commit d0f36c4

14 files changed

+1661
-45
lines changed

website/docs/components/cli.md

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,86 @@ $ oc <command> [options]
4646

4747
Hint: Run -h with any command to show the help
4848

49-
For a list of all the available commands, ype **oc** in your terminal
49+
For a list of all the available commands, type **oc** in your terminal
5050

5151
```sh
5252
$ oc
5353
```
5454

55+
## Common Workflows
56+
57+
Here are the most frequently used command sequences for typical OpenComponents workflows:
58+
59+
### Creating and Testing a New Component
60+
61+
```bash
62+
# Create component
63+
oc init my-component
64+
65+
# Navigate to component
66+
cd my-component
67+
68+
# Start development server
69+
oc dev . 3030
70+
71+
# Preview component (in another terminal)
72+
oc preview http://localhost:3030/my-component
73+
```
74+
75+
### Publishing Workflow
76+
77+
```bash
78+
# Add registry (one-time setup)
79+
oc registry add https://my-registry.com
80+
81+
# Package and publish
82+
oc publish my-component --username=myuser --password=mypass
83+
84+
# Or test before publishing
85+
oc publish my-component --dryRun
86+
```
87+
88+
### Development and Debugging
89+
90+
```bash
91+
# Start dev server with verbose output
92+
oc dev . 3030 --verbose
93+
94+
# Clean node_modules from all components
95+
oc clean . --yes
96+
97+
# Mock plugins for local development
98+
oc mock plugin hash "test-value"
99+
```
100+
101+
## Most Frequently Used Commands
102+
103+
### Essential Commands (Daily Use)
104+
- `oc init <name>` - Create new component
105+
- `oc dev . <port>` - Start development server
106+
- `oc preview <url>` - Preview component
107+
- `oc publish <path>` - Publish component
108+
109+
### Setup Commands (One-time)
110+
- `oc registry add <url>` - Add registry
111+
- `oc registry ls` - List registries
112+
113+
### Maintenance Commands (Occasional)
114+
- `oc clean <path>` - Clean dependencies
115+
- `oc package <path>` - Package component
116+
- `oc mock plugin <name> <value>` - Mock plugins
117+
118+
## Quick Reference
119+
120+
| Command | Purpose | Example |
121+
|---------|---------|---------|
122+
| `init` | Create component | `oc init header` |
123+
| `dev` | Start dev server | `oc dev . 3030` |
124+
| `preview` | Test component | `oc preview http://localhost:3030/header` |
125+
| `publish` | Deploy component | `oc publish header/` |
126+
| `registry add` | Add registry | `oc registry add https://my-registry.com` |
127+
| `clean` | Remove node_modules | `oc clean . --yes` |
128+
55129
---
56130

57131
### clean
@@ -135,18 +209,18 @@ $ oc init <componentPath> [templateType]
135209
| Name | Description | Default |
136210
| --------------- | -------------------------------------------------------- | ---------------------- |
137211
| `componentPath` | The relative path with a name of the component to create |
138-
| `templateType` | The name of the published template module on npm | oc-template-handlebars |
212+
| `templateType` | The name of the published template module on npm | oc-template-es6 |
139213

140214
#### Example:
141215

142216
```sh
143-
$ oc init test-component oc-template-jade
217+
$ oc init test-component oc-template-es6
144218
```
145219

146220
or with using relative path:
147221

148222
```sh
149-
$ oc init components/test-component oc-template-jade
223+
$ oc init components/test-component oc-template-es6
150224
```
151225

152226
which will create `test-component` in `components` directory.

website/docs/components/client-side-operations.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ Configure the client by exposing settings before including the script:
8080

8181
### Default Templates Configuration
8282

83+
Modern OpenComponents uses ES6 templates by default. Legacy template types are still supported for backwards compatibility:
84+
8385
```js
8486
[
87+
// Legacy template types (supported for backwards compatibility)
8588
{
86-
type: "oc-template-jade",
89+
type: "oc-template-jade", // Legacy - use ES6 templates for new components
8790
externals: [
8891
{
8992
global: "jade",
@@ -103,6 +106,8 @@ Configure the client by exposing settings before including the script:
103106
];
104107
```
105108

109+
**Note**: ES6 templates are the recommended default for new components and don't require external dependencies.
110+
106111
## API Methods
107112

108113
### oc.addStylesToHead(styles)
@@ -228,7 +233,7 @@ Render a component using compiled view information and data model.
228233
```js
229234
oc.render(
230235
{
231-
type: "handlebars",
236+
type: "es6", // Modern ES6 template (recommended)
232237
src: "https://registry.com/component/template.js",
233238
key: "template-hash",
234239
},
@@ -791,7 +796,7 @@ Available settings:
791796
| `retryInterval` | `number` (milliseconds) | Retry interval for when component rendering fails | 5000 |
792797
| `retryLimit` | `number` | Max number of retries when component rendering fails | 30 |
793798
| `retrySendNumber` | `boolean` | Appends an `__ocRetry=(number)` to a request to mark the retry number. This is a quite powerful feature that you can handle in the server-side logic in order to make your component even behave differently in case something is going wrong | true |
794-
| `templates` | `array` | The configuration needed for performing client-side rendering of specific template types. | `[{"type": "oc-template-jade","externals": [{"global": "jade","url": "https://unpkg.com/[email protected]/runtime.js"}]},{"type": "oc-template-handlebars","externals": [{"global": "Handlebars","url": "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.runtime.min.js"}]}]` |
799+
| `templates` | `array` | The configuration needed for performing client-side rendering of legacy template types. ES6 templates (default) don't require configuration. | `[{"type": "oc-template-jade","externals": [{"global": "jade","url": "https://unpkg.com/[email protected]/runtime.js"}]},{"type": "oc-template-handlebars","externals": [{"global": "Handlebars","url": "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.runtime.min.js"}]}]` |
795800
| `tag` | `string` | The html tag you want to use for your components in the page | `oc-component` |
796801

797802
## API

website/docs/components/getting-started.md

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ sidebar_position: 1
44

55
# Getting Started
66

7-
## Component creation
7+
## Prerequisites
8+
9+
Before creating your first component, ensure you have:
10+
11+
- **Node.js** (version 20 or higher) - [Download here](https://nodejs.org/)
12+
- **npm** (comes with Node.js) - Basic familiarity with npm commands
13+
- **Basic JavaScript knowledge** - Understanding of functions, objects, and modules
14+
- **Command line familiarity** - Ability to navigate directories and run commands
15+
16+
**New to OpenComponents?** Consider starting with our [Quick Start Tutorial](../quick-start-tutorial) for a complete step-by-step guide.
17+
18+
## Component Creation
819

920
To create a component you need to install oc with a command:
1021

@@ -23,10 +34,10 @@ The above command will create the `hello-world` [directory](#component-structure
2334
It is also possible to set [template](#template) type during the initialisation as an additional init parameter:
2435

2536
```bash
26-
$ oc init hello-world oc-template-jade
37+
$ oc init hello-world oc-template-es6
2738
```
2839

29-
By default this parameter is set to `oc-template-handlebars`.
40+
By default this parameter is set to `oc-template-es6` (modern ES6 templates). Legacy templates like `oc-template-handlebars` are still supported for backwards compatibility.
3041

3142
## Component structure
3243

@@ -85,7 +96,7 @@ The basic package file `package.json` looks as follows:
8596

8697
## Template
8798

88-
The template represents view layer of the component. OC support `Handlebars`(via the `oc-template-handlebars`) and `Jade`(via the `oc-template-jade`) out of the box, but it come with a powerful template system to support components built with any javascript UI framework like `React`, `Angular`, `Vue`...|
99+
The template represents view layer of the component. OC supports modern `ES6` templates by default, along with `React`, `Vue`, `Svelte`, and other javascript UI frameworks. Legacy templates like `Handlebars` and `Jade` are still supported for backwards compatibility.
89100

90101
Initialisation produces a basic hello-world example.
91102

@@ -135,3 +146,99 @@ $ oc preview http://localhost:3030/hello-world
135146
```
136147

137148
That's it. As soon as you make changes on the component, you will be able to refresh this page and see how it looks.
149+
150+
## When to Use Components
151+
152+
OpenComponents are ideal for:
153+
154+
- **Shared UI elements** across multiple applications (headers, footers, navigation)
155+
- **Team independence** where different teams own different parts of the UI
156+
- **Gradual migration** from monolithic to micro frontend architecture
157+
- **A/B testing** individual components without affecting the entire application
158+
- **Third-party integrations** that need to be embedded in multiple sites
159+
160+
## Example Repositories
161+
162+
Explore these example repositories to see OpenComponents in action:
163+
164+
- [OpenComponents Templates](https://github.com/opencomponents/vite-templates) - Modern component templates
165+
- [Storage Adapters](https://github.com/opencomponents/storage-adapters) - Different storage solutions
166+
- [Browser Client](https://github.com/opencomponents/oc-client-browser) - Client-side integration examples
167+
168+
## Troubleshooting Common Issues
169+
170+
### Installation Problems
171+
172+
**Problem**: Permission errors when installing globally
173+
174+
```bash
175+
# Solution: Use sudo (macOS/Linux) or run as administrator (Windows)
176+
sudo npm install oc -g
177+
```
178+
179+
**Problem**: `oc` command not found after installation
180+
181+
```bash
182+
# Check if npm global bin is in your PATH
183+
npm config get prefix
184+
# Add {prefix}/bin to your PATH environment variable
185+
```
186+
187+
### Component Creation Issues
188+
189+
**Problem**: `oc init` fails with template errors
190+
191+
```bash
192+
# Solution: Specify template explicitly (ES6 is default)
193+
oc init hello-world oc-template-es6
194+
```
195+
196+
**Problem**: Component won't start with `oc dev`
197+
198+
```bash
199+
# Solution: Install dependencies first
200+
cd hello-world
201+
npm install
202+
oc dev . 3030
203+
```
204+
205+
### Development Server Issues
206+
207+
**Problem**: Port already in use
208+
209+
```bash
210+
# Solution: Use a different port
211+
oc dev . 3031
212+
```
213+
214+
**Problem**: Component shows "Loading..." forever
215+
216+
- Check browser console for JavaScript errors
217+
- Verify the registry URL is accessible
218+
- Ensure component syntax is valid
219+
220+
### Template Compilation Errors
221+
222+
**Problem**: Template syntax errors
223+
224+
- For ES6 templates: Validate your template literal syntax and ensure the function returns valid HTML
225+
- For legacy Handlebars templates: Validate template syntax and check for missing variables in server.js
226+
- Check for missing variables in server.js
227+
228+
**Problem**: Server.js runtime errors
229+
230+
- Check the server.js syntax
231+
- Verify all required parameters are handled
232+
- Add error handling in your data function
233+
234+
## Next Steps
235+
236+
Once you've created your first component:
237+
238+
1. **[Learn the CLI](cli)** - Master all available commands
239+
2. **[Understand package.json structure](package.json-structure)** - Configure your component properly
240+
3. **[Add server-side logic](the-server.js)** - Make your component dynamic
241+
4. **[Publish to a registry](publishing-to-a-registry)** - Share your component
242+
5. **[Explore client-side operations](client-side-operations)** - Advanced browser integration
243+
244+
For a complete hands-on tutorial, see our [Quick Start Tutorial](../quick-start-tutorial).

website/docs/components/package.json-structure.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ The basic package file `package.json` looks as follows:
1515
"files": {
1616
"data": "server.js",
1717
"template": {
18-
"src": "template.hbs",
19-
"type": "oc-template-handlebars"
18+
"src": "template.js",
19+
"type": "oc-template-es6"
2020
}
2121
}
2222
},
2323
"devDependencies": {
24-
"oc-template-handlebars-compiler": "6.0.8"
24+
"oc-template-es6-compiler": "6.0.8"
2525
}
2626
}
2727
```
@@ -42,7 +42,7 @@ The basic package file `package.json` looks as follows:
4242
| `oc.files.data` | `string` | the model provider's filename, by default `server.js` |
4343
| `oc.files.template` | `object` | represents the data involved with template - view, template engine |
4444
| `oc.files.template.src` | `string` | the view's filename, by default template.html |
45-
| `oc.files.template.type` | `string` | the template engine's type, by default `handlebars` |
45+
| `oc.files.template.type` | `string` | the template engine's type, by default `es6` (modern JavaScript templates). Legacy options like `handlebars` are still supported for backwards compatibility |
4646
| `oc.files.static` | `array of strings` | An array of directories that contain static resources referenced from the component's markup |
4747
| `oc.minify` | `boolean` | Default `true`, will minify static css and js files during publishing |
4848
| `oc.parameters` | `object` | Describes the component's api. Used to auto-generate documentation and get requests validation. Each `key` is the parameter name |

website/docs/components/the-server.js.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ and we don't need to modify any other files.
1616

1717
But when we want to provide some additional logic in our view:
1818

19-
```html
20-
<div>hello {{name}}</div>
19+
```javascript
20+
export default function(model) {
21+
return `<div>hello ${model.name}</div>`;
22+
}
2123
```
2224

2325
we have to modify our `server.js` (model provider).
@@ -160,14 +162,14 @@ First step is to prepare `package.json` file. It is necessary to add `static` pr
160162
"files": {
161163
"data": "server.js",
162164
"template": {
163-
"src": "template.html",
164-
"type": "oc-template-handlebars"
165+
"src": "template.js",
166+
"type": "oc-template-es6"
165167
},
166168
"static": ["public"]
167169
}
168170
},
169171
"devDependencies": {
170-
"oc-template-handlebars-compiler": "6.0.8"
172+
"oc-template-es6-compiler": "6.0.8"
171173
}
172174
}
173175
```
@@ -178,8 +180,10 @@ It is an array of names of directories. In the above example the `public` direct
178180

179181
We can add image to the component view template using `img` tag in which `src` attribute is bound to `img` viewModel property.
180182

181-
```html
182-
<img src="{{path}}public/static_resource.png" />
183+
```javascript
184+
export default function(model) {
185+
return `<img src="${model.path}public/static_resource.png" />`;
186+
}
183187
```
184188

185189
### Update server file

0 commit comments

Comments
 (0)