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: apps/docs/content/docs/create-a-registry.mdx
+232-1Lines changed: 232 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ Now we can build our registry with the `jsrepo build` command:
99
99
jsrepo build
100
100
```
101
101
102
-
This will create a `jsrepo.json` file at the root of our project that contains everything we need to start adding items from our registry to other projects.
102
+
This will create a `registry.json` file at the root of our project that contains everything we need to start adding items from our registry to other projects.
103
103
104
104
### Testing the registry
105
105
@@ -146,3 +146,234 @@ jsrepo add logger
146
146
Now that we have a working registry we can deploy it to wherever we want. Take a look at the [providers](/docs/providers) docs for the full list of hosting options.
147
147
148
148
Each provider has a guide on how to deploy your registry to that particular platform.
149
+
150
+
This is the end of the basic guide. You can now start adding items to your registry and deploying it to your favorite hosting platform.
151
+
152
+
## Advanced Usage
153
+
154
+
Now that we have covered the basics of creating a registry we can start to explore some of the features that make **jsrepo** so powerful.
155
+
156
+
### Exclude deps
157
+
158
+
Many times you may not want certain dependencies to be installed with your registry items. For instance if you import `useState` from `react` you probably don't want to force users to install `react` with your registry.
159
+
160
+
For this you can use the `excludeDeps` key of your registry config.
161
+
162
+
```ts title="jsrepo.config.mts"
163
+
import { defineConfig } from"jsrepo";
164
+
165
+
exportdefaultdefineConfig({
166
+
registry: {
167
+
// ...
168
+
excludeDeps: ["react"], // [!code ++]
169
+
},
170
+
});
171
+
```
172
+
173
+
### Configure when an item is added
174
+
175
+
We mentioned this briefly above but you can configure when an item is added in the user's project by setting the `add` key an item.
176
+
177
+
-`"on-init"` - Added on registry init or when it's needed by another item
178
+
-`"when-needed"` - Not listed and only added when another item is added that depends on it
179
+
-`"when-added"` - Added when the user selects it to be added
180
+
181
+
```ts title="jsrepo.config.mts"
182
+
import { defineConfig } from"jsrepo";
183
+
184
+
exportdefaultdefineConfig({
185
+
registry: {
186
+
items: [
187
+
{
188
+
// ...
189
+
add: "when-added", // [!code ++]
190
+
}
191
+
]
192
+
},
193
+
});
194
+
```
195
+
196
+
<Callouttype="info">
197
+
It's good practice to put your framework in the `excludeDeps` list whether that be `react`, `vue`, `svelte`, or `next` etc.
198
+
</Callout>
199
+
200
+
### Configuring the user's project
201
+
202
+
There are a few common things you may want to automatically configure in the user's project when they first initialize your registry.
203
+
204
+
#### Default Paths
205
+
206
+
You can configure the `defaultPaths` key of your registry config to configure the default paths for items or item types to be added to in the user's project.
207
+
208
+
```ts title="jsrepo.config.mts"
209
+
import { defineConfig } from"jsrepo";
210
+
211
+
exportdefaultdefineConfig({
212
+
registry: {
213
+
// ...
214
+
defaultPaths: {
215
+
component: "src/components/ui",
216
+
},
217
+
},
218
+
});
219
+
```
220
+
221
+
#### Plugins
222
+
223
+
You can also configure the `plugins` key to automatically install plugins to the user's project when they initialize your registry.
Sometimes your registry items may require environment variables to work.
242
+
243
+
For this you can define the `envVars` key of that particular item:
244
+
245
+
```ts title="jsrepo.config.mts"
246
+
import { defineConfig } from"jsrepo";
247
+
248
+
exportdefaultdefineConfig({
249
+
registry: {
250
+
// ...
251
+
items: [
252
+
// ...
253
+
{
254
+
// ...
255
+
name: 'db',
256
+
type: 'lib',
257
+
files: [
258
+
{
259
+
path: 'src/db.ts',
260
+
}
261
+
],
262
+
envVars: {
263
+
DATABASE_URL: "https://example.com/database",
264
+
DATABASE_SECRET_TOKEN: "",
265
+
},
266
+
}
267
+
]
268
+
},
269
+
});
270
+
```
271
+
272
+
Environment variables will be added to the users `.env.local` or `.env` file.
273
+
274
+
If you leave an environment variable blank the user will be prompted to add a value for it.
275
+
276
+
Values you configure here will ***never*** overwrite existing values in the user's env file.
277
+
278
+
### Distributing multiple registries
279
+
280
+
It's become common to distribute multiple registries to allow users to optionally use different variants of your registry for example JavaScript or TypeScript.
281
+
282
+
However until now there wasn't an easy way to do this.
283
+
284
+
**jsrepo** solves this by allowing you to define multiple registries in the same config:
285
+
286
+
```ts title="jsrepo.config.mts"
287
+
import { defineConfig } from"jsrepo";
288
+
289
+
exportdefaultdefineConfig({
290
+
registry: [
291
+
{
292
+
name: '@my-registry/typescript',
293
+
// ...
294
+
},
295
+
{
296
+
name: '@my-registry/javascript',
297
+
// ...
298
+
}
299
+
]
300
+
});
301
+
```
302
+
303
+
You can then use the `outputs` api to define where each registry should be output to:
Now running `jsrepo build` will output your registry to the `./public/r` directory.
29
+
30
+
Unlike the `repository` output, the `distributed` output will output each item as a separate json file. For example:
31
+
32
+
<Files>
33
+
<Foldername="public"defaultOpen>
34
+
<Foldername="r"defaultOpen>
35
+
<Filename="registry.json" />
36
+
<Filename="button.json" />
37
+
<Filename="utils.json" />
38
+
</Folder>
39
+
</Folder>
40
+
</Files>
41
+
42
+
Since each item file contains all the code for all the files required for that item this is much more performant, and portable than the `repository` output.
0 commit comments