blinkk / rootjs

Root.js – A full-featured web development tool with a built-in CMS.
https://rootjs.dev
MIT License
7 stars 0 forks source link

Get a list of collections #386

Open willthomson opened 3 months ago

willthomson commented 3 months ago

In Registry, we're using collections, one per microsite. On each microsite, we show a 'more domains' dropdown. In order to maintain this list across all microsites automatically, it would be great to get a list of all collections.

This is related to https://github.com/blinkk/rootjs/issues/385, allowing access to the metadata to populate this dropdown.

stevenle commented 3 months ago

Root uses vite under the hood, so you can actually use import.meta.glob to get all of the collections in your project. Something like:

const collectionModules = import.meta.glob('/collections/*.schema.ts', {eager: true});
const collectionSchemas = collectionModules.map((module) => module.default);
console.log(collectionSchemas);