You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/quick-start-tutorial.md
+82-9Lines changed: 82 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,12 @@ By the end of this tutorial, you'll know how to:
22
22
23
23
## Step 1: Create Your First Component
24
24
25
+
Let's start by creating a working directory:
26
+
27
+
```bash
28
+
mkdir oc-tutorial &&cd oc-tutorial
29
+
```
30
+
25
31
Let's create a simple "hello-world" component:
26
32
27
33
```bash
@@ -33,19 +39,24 @@ This creates a new directory with the following structure:
33
39
```
34
40
hello-world/
35
41
├── package.json # Component configuration
36
-
├── src/view.ts # ES6 template (the view)
37
-
├── src/server.js # Server-side logic (optional)
42
+
├── src/
43
+
│ ├── view.ts # TypeScript template (the view)
44
+
│ └── server.ts # Server-side logic
38
45
└── public/
39
46
└── logo.png # Static assets
47
+
├── tsconfig.json # TypeScript configuration
48
+
└── node_modules/ # Dependencies
40
49
```
41
50
42
51
### Understanding the Files
43
52
44
53
**package.json**: Contains component metadata, dependencies, and OpenComponents-specific configuration.
45
54
46
-
**template.ts**: The ES6 template that defines how your component looks using modern JavaScript.
55
+
**src/view.ts**: The TypeScript template that defines how your component looks using modern JavaScript with CSS imports and client-side event handling.
47
56
48
-
**server.ts**: Optional file for server-side logic, data fetching, or API calls.
57
+
**src/server.ts**: Contains server-side logic, data fetching, parameter definitions, and API actions.
58
+
59
+
**Important Note**: The generated component is more sophisticated than basic examples you might see in documentation. It includes TypeScript, CSS modules, client-side interactivity, and server actions.
The generated component includes parameters that you need to know about. Let's check what parameters are required:
83
+
84
+
```bash
85
+
cd hello-world
86
+
cat package.json
87
+
```
88
+
89
+
Look for the `oc.parameters` section in the package.json. You'll notice that some parameters may be marked as `"mandatory": true`. This is crucial for testing your component.
90
+
91
+
### Examine the Generated Files
92
+
69
93
Navigate to your component directory:
70
94
71
95
```bash
@@ -75,7 +99,7 @@ cd hello-world
75
99
Look at the generated template:
76
100
77
101
```bash
78
-
cat template.js
102
+
cat src/view.ts
79
103
```
80
104
81
105
You'll see something like:
@@ -93,6 +117,12 @@ export default function (model) {
93
117
94
118
## Step 3: Start Local Development
95
119
120
+
**Important**: Run the development server from the parent directory (not inside the component directory):
**Important**: The generated component requires parameters. If you get an error about "missing mandatory parameters", check the component info page to see what parameters are required.
153
+
154
+
### Check Component Information
155
+
156
+
Visit http://localhost:3030/hello-world/~info to see detailed information about your component, including all available parameters and which ones are mandatory.
122
157
123
158
Or use the CLI preview:
124
159
125
160
```bash
126
161
oc preview http://localhost:3030/hello-world
127
162
```
128
163
164
+
**Note**: If the preview command doesn't work, don't worry - you can test your component directly in the browser using the URLs above.
0 commit comments