Skip to content

Commit 57b98db

Browse files
committed
more advanced registry docs
1 parent 8301bf0 commit 57b98db

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

apps/docs/content/docs/create-a-registry.mdx

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Now that we have a working registry we can deploy it to wherever we want. Take a
147147

148148
Each provider has a guide on how to deploy your registry to that particular platform.
149149

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+
150152
## Advanced Usage
151153

152154
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.
@@ -271,4 +273,107 @@ Environment variables will be added to the users `.env.local` or `.env` file.
271273

272274
If you leave an environment variable blank the user will be prompted to add a value for it.
273275

274-
Values you configure here will ***never*** overwrite existing values in the user's env file.
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+
export default defineConfig({
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:
304+
305+
```ts title="jsrepo.config.mts"
306+
import { defineConfig } from "jsrepo";
307+
import { distributed } from "jsrepo/outputs";
308+
309+
export default defineConfig({
310+
registry: [
311+
{
312+
name: '@my-registry/typescript',
313+
outputs: [distributed({ dir: "./public/r/ts" })], // [!code ++]
314+
// ...
315+
},
316+
{
317+
name: '@my-registry/javascript',
318+
outputs: [distributed({ dir: "./public/r/js" })], // [!code ++]
319+
// ...
320+
}
321+
]
322+
});
323+
```
324+
325+
### Dynamically generating registries
326+
327+
You don't always want to have to manually define your entire registry in your config file.
328+
329+
AI has made this less cumbersome but it's still annoying to have a 1k LOC file just to define your registry.
330+
331+
In **jsrepo v2** we automatically generated your registry based on a bunch of complicated options and this wasn't the best experience.
332+
333+
In **jsrepo v3** we are giving the control back to you allowing you to write your own code to generate your registry.
334+
335+
To do this simply pass a function to the `registry` key that returns a registry config:
336+
337+
```ts title="jsrepo.config.mts"
338+
import { defineConfig } from "jsrepo";
339+
// define your own custom function
340+
import { getItems } from "./getItems";
341+
342+
export default defineConfig({
343+
registry: ({ cwd }) => {
344+
return {
345+
name: 'my-registry',
346+
items: getItems(cwd)
347+
}
348+
}
349+
});
350+
```
351+
352+
Oh and of course you can also pass an array of functions:
353+
354+
```ts title="jsrepo.config.mts"
355+
import { defineConfig } from "jsrepo";
356+
// define your own custom function
357+
import { getItems } from "./getItems";
358+
359+
export default defineConfig({
360+
registry: [
361+
({ cwd }) => {
362+
return {
363+
name: '@my-registry/typescript',
364+
items: getItems(path.join(cwd, 'src/registry/ts'))
365+
}
366+
},
367+
({ cwd }) => {
368+
return {
369+
name: '@my-registry/javascript',
370+
items: getItems(path.join(cwd, 'src/registry/js'))
371+
}
372+
}
373+
]
374+
});
375+
```
376+
377+
<Callout type="info">
378+
Dynamically generated registries will still work with the `--watch` flag.
379+
</Callout>

0 commit comments

Comments
 (0)